test-regex: Add a test to check for a bug in the regex routines
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ramsay Jones committed
Sep 1, 2012 at 18:46 UTC
c91841594c2f08bec0c8b2d46da27add18fb4854
4 files changed
+27
.gitignore
+1
@@ -184,6 +184,7 @@
184
/test-obj-pool
185
/test-parse-options
186
/test-path-utils
187
+/test-regex
188
/test-run-command
189
/test-sha1
190
/test-sigchain
Makefile
+1
@@ -476,6 +476,7 @@ TEST_PROGRAMS_NEED_X += test-mktemp
476
TEST_PROGRAMS_NEED_X += test-obj-pool
477
TEST_PROGRAMS_NEED_X += test-parse-options
478
TEST_PROGRAMS_NEED_X += test-path-utils
479
+TEST_PROGRAMS_NEED_X += test-regex
480
TEST_PROGRAMS_NEED_X += test-run-command
481
TEST_PROGRAMS_NEED_X += test-sha1
482
TEST_PROGRAMS_NEED_X += test-sigchain
t/t0070-fundamental.sh
+5
@@ -25,4 +25,9 @@ test_expect_success POSIXPERM 'mktemp to unwritable directory prints filename' '
25
grep "cannotwrite/test" err
26
'
27
28
+test_expect_success 'check for a bug in the regex routines' '
29
+ # if this test fails, re-build git with NO_REGEX=1
30
+ test-regex
31
+'
32
+
33
test_done
test-regex.c
new
+20
@@ -0,0 +1,20 @@
1
+#include <git-compat-util.h>
2
+
3
+int main(int argc, char **argv)
4
+{
5
+ char *pat = "[^={} \t]+";
6
+ char *str = "={}\nfred";
7
+ regex_t r;
8
+ regmatch_t m[1];
9
+
10
+ if (regcomp(&r, pat, REG_EXTENDED | REG_NEWLINE))
11
+ die("failed regcomp() for pattern '%s'", pat);
12
+ if (regexec(&r, str, 1, m, 0))
13
+ die("no match of pattern '%s' to string '%s'", pat, str);
14
+
15
+ /* http://sourceware.org/bugzilla/show_bug.cgi?id=3957 */
16
+ if (m[0].rm_so == 3) /* matches '\n' when it should not */
17
+ die("regex bug confirmed: re-build git with NO_REGEX=1");
18
+
19
+ exit(0);
20
+}