test-regex: Add a test to check for a bug in the regex routines
authorRamsay Jones <ramsay@ramsay1.demon.co.uk>
Sat, 1 Sep 2012 17:46:54 +0000 (18:46 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 3 Sep 2012 01:57:21 +0000 (18:57 -0700)
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
.gitignore
Makefile
t/t0070-fundamental.sh
test-regex.c [new file with mode: 0644]

index 3b7680ea1e5baa58430798a9836481975dbb6234..d284b058a33dfa8235d8608a89a500bfef1c1028 100644 (file)
 /test-obj-pool
 /test-parse-options
 /test-path-utils
+/test-regex
 /test-run-command
 /test-sha1
 /test-sigchain
index e4f8e0ef08b9f3f4eb5035f20421ee035127fdf2..d2b145b533485d9064c5e2db76949dd5b3a41863 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -476,6 +476,7 @@ TEST_PROGRAMS_NEED_X += test-mktemp
 TEST_PROGRAMS_NEED_X += test-obj-pool
 TEST_PROGRAMS_NEED_X += test-parse-options
 TEST_PROGRAMS_NEED_X += test-path-utils
+TEST_PROGRAMS_NEED_X += test-regex
 TEST_PROGRAMS_NEED_X += test-run-command
 TEST_PROGRAMS_NEED_X += test-sha1
 TEST_PROGRAMS_NEED_X += test-sigchain
index 9bee8bfd2e063c40bae2d76930370bd9e8ba8fa5..da2c504e53e37840f71790d6b262106b7b57d697 100755 (executable)
@@ -25,4 +25,9 @@ test_expect_success POSIXPERM 'mktemp to unwritable directory prints filename' '
        grep "cannotwrite/test" err
 '
 
+test_expect_success 'check for a bug in the regex routines' '
+       # if this test fails, re-build git with NO_REGEX=1
+       test-regex
+'
+
 test_done
diff --git a/test-regex.c b/test-regex.c
new file mode 100644 (file)
index 0000000..b5bfd54
--- /dev/null
@@ -0,0 +1,20 @@
+#include <git-compat-util.h>
+
+int main(int argc, char **argv)
+{
+       char *pat = "[^={} \t]+";
+       char *str = "={}\nfred";
+       regex_t r;
+       regmatch_t m[1];
+
+       if (regcomp(&r, pat, REG_EXTENDED | REG_NEWLINE))
+               die("failed regcomp() for pattern '%s'", pat);
+       if (regexec(&r, str, 1, m, 0))
+               die("no match of pattern '%s' to string '%s'", pat, str);
+
+       /* http://sourceware.org/bugzilla/show_bug.cgi?id=3957  */
+       if (m[0].rm_so == 3) /* matches '\n' when it should not */
+               die("regex bug confirmed: re-build git with NO_REGEX=1");
+
+       exit(0);
+}