Skip to content

Commit

Permalink
Merge branch 'rj/test-regex' into maint-1.7.11
Browse files Browse the repository at this point in the history
* rj/test-regex:
  test-regex: Add a test to check for a bug in the regex routines
  • Loading branch information
Junio C Hamano committed Sep 15, 2012
2 parents f463cc5 + c918415 commit dabdc01
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
/test-mktemp
/test-parse-options
/test-path-utils
/test-regex
/test-revision-walking
/test-run-command
/test-sha1
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ TEST_PROGRAMS_NEED_X += test-mergesort
TEST_PROGRAMS_NEED_X += test-mktemp
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-revision-walking
TEST_PROGRAMS_NEED_X += test-run-command
TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
Expand Down
5 changes: 5 additions & 0 deletions t/t0070-fundamental.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 20 additions & 0 deletions test-regex.c
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit dabdc01

Please sign in to comment.