1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-21 11:36:08 +02:00

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>
This commit is contained in:
Ramsay Jones 2012-09-01 18:46:54 +01:00 committed by Junio C Hamano
parent d0f1ea6003
commit c91841594c
4 changed files with 27 additions and 0 deletions

1
.gitignore vendored
View File

@ -184,6 +184,7 @@
/test-obj-pool
/test-parse-options
/test-path-utils
/test-regex
/test-run-command
/test-sha1
/test-sigchain

View File

@ -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

View File

@ -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

20
test-regex.c Normal file
View File

@ -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);
}