git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] t4018: add a few more test cases for cpp hunk header matching

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Dec 19, 2011, 21:53 UTC
Message-ID
<6fUozvAFiZtWtB8fYx2kUeUq8VtDgI4bzcA55hMiHJgT_Ag96PM120NEGB5HdtvbJQHJWjAksX6bgea_pMM2jpV6mCwiLKQ9EacSnIUmJ8llgHHqU2I0v9oMj8mYKTJxdIZXJFnBtYA@cipher.nrlssc.navy.mil>
In-Reply-To
<31E9klcRboMV0wSJY5WO-N7nIBOUOa_wr6MVfWY9AInImxJIqC0flahvpDrVGMIuZ9e7Ouha1HDuesbwTGaNQA4dgN-FShNJKkfMG_cHLUJAT2rE539shnQxzM0dQyZIb5661As6Tvs@cipher.nrlssc.navy.mil>
From: Brandon Casey <drafnel@gmail.com>
Add one case for matching a function returning a pointer.
Plus add examples of things we explicitly do not match:
   labels
   function declarations
   global variable declarations
Signed-off-by: Brandon Casey <drafnel@gmail.com>
---

This can be squashed into the original patch with the other test cases. This just introduces a few more cases pointed out by Thomas Rast in the email Johannes referenced.

   http://thread.gmane.org/gmane.comp.version-control.git/186355/focus=186439

Also, note that all of the tests pass except for ignore_global.cpp with Johannes's pattern:

   "!^[ \\t]*[a-zA-Z_][a-zA-Z_0-9]*[^()]*:[[:space:]]*$\n^[a-zA-Z_][a-zA-Z_0-9]*.*"
-Brandon
 t/t4018/ignore_declaration.cpp |   35 +++++++++++++++++++++++++++++++++++
 t/t4018/ignore_global.cpp      |   36 ++++++++++++++++++++++++++++++++++++
 t/t4018/ignore_label.cpp       |   35 +++++++++++++++++++++++++++++++++++
 t/t4018/pointer_return.cpp     |   34 ++++++++++++++++++++++++++++++++++
 4 files changed, 140 insertions(+), 0 deletions(-)
 create mode 100644 t/t4018/ignore_declaration.cpp
 create mode 100644 t/t4018/ignore_global.cpp
 create mode 100644 t/t4018/ignore_label.cpp
 create mode 100644 t/t4018/pointer_return.cpp
diff --git a/t/t4018/ignore_declaration.cpp b/t/t4018/ignore_declaration.cpp
new file mode 100644
index 0000000..615aea0
--- /dev/null
+++ b/t/t4018/ignore_declaration.cpp
@@ -0,0 +1,35 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+	return 0;
+}
+
+int RIGHT_function_hunk_header (void)
+{
+	void WRONG_function_declaration_within_body (void);
+	/*
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 */
+
+	int answer = 0;
+
+	/*
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 */
+
+	return answer;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+	return 0;
+}
diff --git a/t/t4018/ignore_global.cpp b/t/t4018/ignore_global.cpp
new file mode 100644
index 0000000..df6b8aa
--- /dev/null
+++ b/t/t4018/ignore_global.cpp
@@ -0,0 +1,36 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+	return 0;
+}
+
+int RIGHT_function_hunk_header (void)
+{
+	/*
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 */
+
+	return answer;
+}
+
+int WRONG_global_variable;
+
+/*
+ * Filler
+ * Filler
+ * Filler
+ * Filler
+ * Filler
+ * Filler
+ */
+
+int answer = 0;
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+	return 0;
+}
diff --git a/t/t4018/ignore_label.cpp b/t/t4018/ignore_label.cpp
new file mode 100644
index 0000000..2e3ce10
--- /dev/null
+++ b/t/t4018/ignore_label.cpp
@@ -0,0 +1,35 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+	return 0;
+}
+
+int RIGHT_function_hunk_header (void)
+{
+WRONG_should_not_match_label:
+	/*
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 */
+
+	int answer = 0;
+
+	/*
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 */
+
+	return answer;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+	return 0;
+}
diff --git a/t/t4018/pointer_return.cpp b/t/t4018/pointer_return.cpp
new file mode 100644
index 0000000..fd85545
--- /dev/null
+++ b/t/t4018/pointer_return.cpp
@@ -0,0 +1,34 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+	return 0;
+}
+
+static int *RIGHT_function_hunk_header (void)
+{
+	/*
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 */
+
+	int answer = 0;
+
+	/*
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 * Filler
+	 */
+
+	return answer;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+	return 0;
+}
-- 
1.7.7.4
Previous: Brandon CaseyNext: Junio C Hamano
Message 19 of 35 in “attr: map builtin userdiff drivers to well-known extensions”
  1. attr: map builtin userdiff drivers to well-known extensionsJeff King, Dec 16, 2011
  2. Johannes SixtDec 16, 2011
  3. Junio C HamanoDec 16, 2011
  4. Jeff KingDec 16, 2011
  5. Jeff KingDec 16, 2011
  6. Junio C HamanoDec 16, 2011
  7. Jeff KingDec 17, 2011
  8. Johannes SixtDec 16, 2011
  9. Jeff KingDec 17, 2011
  10. Jonathan NiederDec 17, 2011
  11. 1/2 attr: map builtin userdiff drivers to well-known extensionsJeff King, Dec 19, 2011
  12. Jonathan NiederDec 19, 2011
  13. Jeff KingDec 19, 2011
  14. Ævar Arnfjörð BjarmasonDec 22, 2011
  15. 2/2 attr: drop C/C++ default extension mappingJeff King, Dec 19, 2011
  16. Jonathan NiederDec 19, 2011
  17. Thomas RastDec 19, 2011
  18. t4018: introduce test cases for the internal hunk header patternsBrandon Casey, Dec 19, 2011
  19. t4018: add a few more test cases for cpp hunk header matchingBrandon Casey, Dec 19, 2011
  20. Junio C HamanoDec 19, 2011
  21. Brandon CaseyDec 19, 2011
  22. Junio C HamanoDec 19, 2011
  23. t4018: introduce test cases for the internal hunk header patternsBrandon Casey, Dec 20, 2011
  24. Jakub NarebskiDec 20, 2011
  25. Brandon CaseyDec 20, 2011
  26. Thomas RastDec 20, 2011
  27. Johannes SixtDec 20, 2011
  28. Junio C HamanoDec 20, 2011
  29. Mark LevedahlDec 16, 2011
  30. Jeff KingDec 16, 2011
  31. Philip OakleyDec 16, 2011
  32. Jeff KingDec 16, 2011
  33. Philip OakleyDec 21, 2011
  34. Jeff KingDec 23, 2011
  35. Junio C HamanoDec 16, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.