Thread (1 message) 1 message, 1 author, 2020-05-18

Re: [PATCH v3 1/2] t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ)

From: Junio C Hamano <hidden>
Date: 2020-05-18 20:15:53

Carlo Marcelo Arenas Belón  [off-list ref] writes:
Based-on-patch-by: Junio C Hamano [off-list ref]
This is sufficiently different from what I suggested that I do not
deserve the above line, I would think.
+	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);
Nice.
+	}
+	if (!str)
+		return 0;
+
+	ret = regexec(&r, str, 1, m, 0);
+	if (ret) {
+		if (silent || ret == REG_NOMATCH)
+			return ret;
+
+		regerror(ret, &r, errbuf, sizeof(errbuf));
+		die("failed regexec() for subject '%s' (%s)", str, errbuf);
+	}
 
 	return 0;
+usage:
+	usage("\ttest-tool regex --bug\n"
+	      "\ttest-tool regex [--silent] <pattern>\n"
+	      "\ttest-tool regex [--silent] <pattern> <string> [<options>]");
+	return -1;
 }
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help