Re: Test failures in t4034
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:54:37
Ramsay Jones [off-list ref] writes:
Yes, there was a net increase in the line count when I introduced die(), but the main program flow was less cluttered by error handling. The net result looked much better, so I thought it was worth it. What may not be too obvious, however, is that test-regex.c was written to be independent of git.
That part I was very aware of actually; it it is a bit tricky to tell what the right thing to do, though. Your test itself needs to be pretty much portable without the portability help you would get git-compat-util.h, but the point of this kind of test is to tell if you want to define preprocessor macros that may affect the behaviour of such compatibility layer ;-)
Given that I'm now building it as part of git, I should have simply #included <git-compat-util.h> and used the die() routine from libgit.a (since I'm now *relying* on test-regex being linked with libgit.a).
OK.
quoted
quoted
+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 */ + exit(1);This could be the third call site of die() that tells the user to build with NO_REGEX=1. Then "cd t && sh t0070-fundamental.sh -i -v" would give that message directly to the user.Hmm, even without "-i -v", it's *very* clear what is going on, but sure it wouldn't hurt either. (Also, I wanted to be able to distinguish an exit via die() from a "test failed" error return).
OK. Thanks.