2018-03-24 07:44:53 +00:00
|
|
|
#include "test-tool.h"
|
2016-06-25 05:22:29 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
struct reg_flag {
|
|
|
|
const char *name;
|
|
|
|
int flag;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct reg_flag reg_flags[] = {
|
t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ)
7187c7bbb8 (t4210: skip i18n tests that don't work on FreeBSD, 2019-11-27)
adds a REG_ILLSEQ prerequisite to avoid failures from the tests added in
4e2443b181 (log tests: test regex backends in "--encode=<enc>" tests,
2019-06-28), but hardcodes it to be only enabled in FreeBSD.
Instead of hardcoding the affected platform, teach the test-regex helper,
how to validate a pattern and report back, so it can be used to detect the
same issue in other affected systems (like DragonFlyBSD or macOS).
While at it, refactor the tool so it can report back the source of the
errors it founds, and can be invoked also in a --silent mode, when needed,
for backward compatibility. A missing flag has been added and the code
reformatted, as well as updates to the way the parameters are handled, for
consistency.
To minimize changes, it is assumed the regcomp error is of the right type
since we control the only caller, and is also assumed to affect both basic
and extended syntax (only basic is tested, but both behave the same in all
three affected platforms since they use the same function).
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-18 18:44:15 +00:00
|
|
|
{ "EXTENDED", REG_EXTENDED },
|
|
|
|
{ "NEWLINE", REG_NEWLINE },
|
|
|
|
{ "ICASE", REG_ICASE },
|
|
|
|
{ "NOTBOL", REG_NOTBOL },
|
|
|
|
{ "NOTEOL", REG_NOTEOL },
|
2016-06-25 05:22:29 +00:00
|
|
|
#ifdef REG_STARTEND
|
t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ)
7187c7bbb8 (t4210: skip i18n tests that don't work on FreeBSD, 2019-11-27)
adds a REG_ILLSEQ prerequisite to avoid failures from the tests added in
4e2443b181 (log tests: test regex backends in "--encode=<enc>" tests,
2019-06-28), but hardcodes it to be only enabled in FreeBSD.
Instead of hardcoding the affected platform, teach the test-regex helper,
how to validate a pattern and report back, so it can be used to detect the
same issue in other affected systems (like DragonFlyBSD or macOS).
While at it, refactor the tool so it can report back the source of the
errors it founds, and can be invoked also in a --silent mode, when needed,
for backward compatibility. A missing flag has been added and the code
reformatted, as well as updates to the way the parameters are handled, for
consistency.
To minimize changes, it is assumed the regcomp error is of the right type
since we control the only caller, and is also assumed to affect both basic
and extended syntax (only basic is tested, but both behave the same in all
three affected platforms since they use the same function).
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-18 18:44:15 +00:00
|
|
|
{ "STARTEND", REG_STARTEND },
|
2016-06-25 05:22:29 +00:00
|
|
|
#endif
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
2012-09-01 17:46:54 +00:00
|
|
|
|
2016-06-25 05:22:28 +00:00
|
|
|
static int test_regex_bug(void)
|
2012-09-01 17:46:54 +00:00
|
|
|
{
|
|
|
|
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");
|
|
|
|
|
2022-07-01 10:37:36 +00:00
|
|
|
regfree(&r);
|
2016-06-25 05:22:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-24 07:44:53 +00:00
|
|
|
int cmd__regex(int argc, const char **argv)
|
2016-06-25 05:22:28 +00:00
|
|
|
{
|
2016-06-25 05:22:29 +00:00
|
|
|
const char *pat;
|
|
|
|
const char *str;
|
t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ)
7187c7bbb8 (t4210: skip i18n tests that don't work on FreeBSD, 2019-11-27)
adds a REG_ILLSEQ prerequisite to avoid failures from the tests added in
4e2443b181 (log tests: test regex backends in "--encode=<enc>" tests,
2019-06-28), but hardcodes it to be only enabled in FreeBSD.
Instead of hardcoding the affected platform, teach the test-regex helper,
how to validate a pattern and report back, so it can be used to detect the
same issue in other affected systems (like DragonFlyBSD or macOS).
While at it, refactor the tool so it can report back the source of the
errors it founds, and can be invoked also in a --silent mode, when needed,
for backward compatibility. A missing flag has been added and the code
reformatted, as well as updates to the way the parameters are handled, for
consistency.
To minimize changes, it is assumed the regcomp error is of the right type
since we control the only caller, and is also assumed to affect both basic
and extended syntax (only basic is tested, but both behave the same in all
three affected platforms since they use the same function).
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-18 18:44:15 +00:00
|
|
|
int ret, silent = 0, flags = 0;
|
2016-06-25 05:22:29 +00:00
|
|
|
regex_t r;
|
|
|
|
regmatch_t m[1];
|
t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ)
7187c7bbb8 (t4210: skip i18n tests that don't work on FreeBSD, 2019-11-27)
adds a REG_ILLSEQ prerequisite to avoid failures from the tests added in
4e2443b181 (log tests: test regex backends in "--encode=<enc>" tests,
2019-06-28), but hardcodes it to be only enabled in FreeBSD.
Instead of hardcoding the affected platform, teach the test-regex helper,
how to validate a pattern and report back, so it can be used to detect the
same issue in other affected systems (like DragonFlyBSD or macOS).
While at it, refactor the tool so it can report back the source of the
errors it founds, and can be invoked also in a --silent mode, when needed,
for backward compatibility. A missing flag has been added and the code
reformatted, as well as updates to the way the parameters are handled, for
consistency.
To minimize changes, it is assumed the regcomp error is of the right type
since we control the only caller, and is also assumed to affect both basic
and extended syntax (only basic is tested, but both behave the same in all
three affected platforms since they use the same function).
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-18 18:44:15 +00:00
|
|
|
char errbuf[64];
|
2016-06-25 05:22:29 +00:00
|
|
|
|
|
|
|
argv++;
|
t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ)
7187c7bbb8 (t4210: skip i18n tests that don't work on FreeBSD, 2019-11-27)
adds a REG_ILLSEQ prerequisite to avoid failures from the tests added in
4e2443b181 (log tests: test regex backends in "--encode=<enc>" tests,
2019-06-28), but hardcodes it to be only enabled in FreeBSD.
Instead of hardcoding the affected platform, teach the test-regex helper,
how to validate a pattern and report back, so it can be used to detect the
same issue in other affected systems (like DragonFlyBSD or macOS).
While at it, refactor the tool so it can report back the source of the
errors it founds, and can be invoked also in a --silent mode, when needed,
for backward compatibility. A missing flag has been added and the code
reformatted, as well as updates to the way the parameters are handled, for
consistency.
To minimize changes, it is assumed the regcomp error is of the right type
since we control the only caller, and is also assumed to affect both basic
and extended syntax (only basic is tested, but both behave the same in all
three affected platforms since they use the same function).
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-18 18:44:15 +00:00
|
|
|
argc--;
|
|
|
|
|
|
|
|
if (!argc)
|
|
|
|
goto usage;
|
|
|
|
|
|
|
|
if (!strcmp(*argv, "--bug")) {
|
|
|
|
if (argc == 1)
|
|
|
|
return test_regex_bug();
|
|
|
|
else
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
if (!strcmp(*argv, "--silent")) {
|
|
|
|
silent = 1;
|
2016-06-25 05:22:29 +00:00
|
|
|
argv++;
|
t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ)
7187c7bbb8 (t4210: skip i18n tests that don't work on FreeBSD, 2019-11-27)
adds a REG_ILLSEQ prerequisite to avoid failures from the tests added in
4e2443b181 (log tests: test regex backends in "--encode=<enc>" tests,
2019-06-28), but hardcodes it to be only enabled in FreeBSD.
Instead of hardcoding the affected platform, teach the test-regex helper,
how to validate a pattern and report back, so it can be used to detect the
same issue in other affected systems (like DragonFlyBSD or macOS).
While at it, refactor the tool so it can report back the source of the
errors it founds, and can be invoked also in a --silent mode, when needed,
for backward compatibility. A missing flag has been added and the code
reformatted, as well as updates to the way the parameters are handled, for
consistency.
To minimize changes, it is assumed the regcomp error is of the right type
since we control the only caller, and is also assumed to affect both basic
and extended syntax (only basic is tested, but both behave the same in all
three affected platforms since they use the same function).
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-18 18:44:15 +00:00
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
if (!argc)
|
|
|
|
goto usage;
|
|
|
|
|
|
|
|
pat = *argv++;
|
|
|
|
if (argc == 1)
|
|
|
|
str = NULL;
|
|
|
|
else {
|
|
|
|
str = *argv++;
|
|
|
|
while (*argv) {
|
|
|
|
struct reg_flag *rf;
|
|
|
|
for (rf = reg_flags; rf->name; rf++)
|
|
|
|
if (!strcmp(*argv, rf->name)) {
|
|
|
|
flags |= rf->flag;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!rf->name)
|
|
|
|
die("do not recognize flag %s", *argv);
|
|
|
|
argv++;
|
|
|
|
}
|
2016-06-25 05:22:29 +00:00
|
|
|
}
|
|
|
|
git_setup_gettext();
|
|
|
|
|
t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ)
7187c7bbb8 (t4210: skip i18n tests that don't work on FreeBSD, 2019-11-27)
adds a REG_ILLSEQ prerequisite to avoid failures from the tests added in
4e2443b181 (log tests: test regex backends in "--encode=<enc>" tests,
2019-06-28), but hardcodes it to be only enabled in FreeBSD.
Instead of hardcoding the affected platform, teach the test-regex helper,
how to validate a pattern and report back, so it can be used to detect the
same issue in other affected systems (like DragonFlyBSD or macOS).
While at it, refactor the tool so it can report back the source of the
errors it founds, and can be invoked also in a --silent mode, when needed,
for backward compatibility. A missing flag has been added and the code
reformatted, as well as updates to the way the parameters are handled, for
consistency.
To minimize changes, it is assumed the regcomp error is of the right type
since we control the only caller, and is also assumed to affect both basic
and extended syntax (only basic is tested, but both behave the same in all
three affected platforms since they use the same function).
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-18 18:44:15 +00:00
|
|
|
ret = regcomp(&r, pat, flags);
|
|
|
|
if (ret) {
|
|
|
|
if (silent)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
regerror(ret, &r, errbuf, sizeof(errbuf));
|
|
|
|
die("failed regcomp() for pattern '%s' (%s)", pat, errbuf);
|
|
|
|
}
|
|
|
|
if (!str)
|
2022-07-01 10:37:36 +00:00
|
|
|
goto cleanup;
|
t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ)
7187c7bbb8 (t4210: skip i18n tests that don't work on FreeBSD, 2019-11-27)
adds a REG_ILLSEQ prerequisite to avoid failures from the tests added in
4e2443b181 (log tests: test regex backends in "--encode=<enc>" tests,
2019-06-28), but hardcodes it to be only enabled in FreeBSD.
Instead of hardcoding the affected platform, teach the test-regex helper,
how to validate a pattern and report back, so it can be used to detect the
same issue in other affected systems (like DragonFlyBSD or macOS).
While at it, refactor the tool so it can report back the source of the
errors it founds, and can be invoked also in a --silent mode, when needed,
for backward compatibility. A missing flag has been added and the code
reformatted, as well as updates to the way the parameters are handled, for
consistency.
To minimize changes, it is assumed the regcomp error is of the right type
since we control the only caller, and is also assumed to affect both basic
and extended syntax (only basic is tested, but both behave the same in all
three affected platforms since they use the same function).
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-18 18:44:15 +00:00
|
|
|
|
|
|
|
ret = regexec(&r, str, 1, m, 0);
|
|
|
|
if (ret) {
|
|
|
|
if (silent || ret == REG_NOMATCH)
|
2022-07-01 10:37:36 +00:00
|
|
|
goto cleanup;
|
t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ)
7187c7bbb8 (t4210: skip i18n tests that don't work on FreeBSD, 2019-11-27)
adds a REG_ILLSEQ prerequisite to avoid failures from the tests added in
4e2443b181 (log tests: test regex backends in "--encode=<enc>" tests,
2019-06-28), but hardcodes it to be only enabled in FreeBSD.
Instead of hardcoding the affected platform, teach the test-regex helper,
how to validate a pattern and report back, so it can be used to detect the
same issue in other affected systems (like DragonFlyBSD or macOS).
While at it, refactor the tool so it can report back the source of the
errors it founds, and can be invoked also in a --silent mode, when needed,
for backward compatibility. A missing flag has been added and the code
reformatted, as well as updates to the way the parameters are handled, for
consistency.
To minimize changes, it is assumed the regcomp error is of the right type
since we control the only caller, and is also assumed to affect both basic
and extended syntax (only basic is tested, but both behave the same in all
three affected platforms since they use the same function).
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-18 18:44:15 +00:00
|
|
|
|
|
|
|
regerror(ret, &r, errbuf, sizeof(errbuf));
|
|
|
|
die("failed regexec() for subject '%s' (%s)", str, errbuf);
|
|
|
|
}
|
2016-06-25 05:22:29 +00:00
|
|
|
|
2022-07-01 10:37:36 +00:00
|
|
|
cleanup:
|
|
|
|
regfree(&r);
|
|
|
|
return ret;
|
t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ)
7187c7bbb8 (t4210: skip i18n tests that don't work on FreeBSD, 2019-11-27)
adds a REG_ILLSEQ prerequisite to avoid failures from the tests added in
4e2443b181 (log tests: test regex backends in "--encode=<enc>" tests,
2019-06-28), but hardcodes it to be only enabled in FreeBSD.
Instead of hardcoding the affected platform, teach the test-regex helper,
how to validate a pattern and report back, so it can be used to detect the
same issue in other affected systems (like DragonFlyBSD or macOS).
While at it, refactor the tool so it can report back the source of the
errors it founds, and can be invoked also in a --silent mode, when needed,
for backward compatibility. A missing flag has been added and the code
reformatted, as well as updates to the way the parameters are handled, for
consistency.
To minimize changes, it is assumed the regcomp error is of the right type
since we control the only caller, and is also assumed to affect both basic
and extended syntax (only basic is tested, but both behave the same in all
three affected platforms since they use the same function).
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-18 18:44:15 +00:00
|
|
|
usage:
|
|
|
|
usage("\ttest-tool regex --bug\n"
|
|
|
|
"\ttest-tool regex [--silent] <pattern>\n"
|
|
|
|
"\ttest-tool regex [--silent] <pattern> <string> [<options>]");
|
|
|
|
return -1;
|
2012-09-01 17:46:54 +00:00
|
|
|
}
|