From c91841594c2f08bec0c8b2d46da27add18fb4854 Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Sat, 1 Sep 2012 18:46:54 +0100 Subject: [PATCH] test-regex: Add a test to check for a bug in the regex routines Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- .gitignore | 1 + Makefile | 1 + t/t0070-fundamental.sh | 5 +++++ test-regex.c | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+) create mode 100644 test-regex.c diff --git a/.gitignore b/.gitignore index 3b7680ea1e..d284b058a3 100644 --- a/.gitignore +++ b/.gitignore @@ -184,6 +184,7 @@ /test-obj-pool /test-parse-options /test-path-utils +/test-regex /test-run-command /test-sha1 /test-sigchain diff --git a/Makefile b/Makefile index e4f8e0ef08..d2b145b533 100644 --- 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 diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh index 9bee8bfd2e..da2c504e53 100755 --- a/t/t0070-fundamental.sh +++ b/t/t0070-fundamental.sh @@ -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 index 0000000000..b5bfd54139 --- /dev/null +++ b/test-regex.c @@ -0,0 +1,20 @@ +#include + +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); +} -- 2.11.4.GIT