[5.1] 7179b96 Tempt fate and try to make getopt() error strings part of our tests, in order to have less ambiguous error messages.

Poul-Henning Kamp phk at FreeBSD.org
Mon Apr 10 13:59:08 CEST 2017


commit 7179b965ff398f6726ff3bb97e878dd388356905
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sun Apr 2 19:57:02 2017 +0000

    Tempt fate and try to make getopt() error strings part of our tests,
    in order to have less ambiguous error messages.

diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 1c45b32..2d3a9dc 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -530,12 +530,9 @@ main(int argc, char * const *argv)
 	do {
 		switch (o) {
 		case '?':
-			if (optopt == '?') {
+			if (optopt == '?')
 				usage();
-				exit(1);
-			}
-			ARGV_ERR("Option '%c' unknown.\n",
-			    optopt);
+			exit(2);
 		case 'V':
 		case 'x':
 			ARGV_ERR("-%c must be the first argument\n", o);
diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc
index abe4c85..e4d0aa6 100644
--- a/bin/varnishtest/tests/a00009.vtc
+++ b/bin/varnishtest/tests/a00009.vtc
@@ -11,7 +11,10 @@ shell -err -expect {-V must be the first argument} "varnishd -d -V foo "
 
 shell -err -expect {Too many arguments for -x} "varnishd -x foo bar"
 shell -err -expect {Invalid -x argument} "varnishd -x foo "
-shell -err -expect {Option 'A' unknown.} "varnishd -A "
+
+# This one is tricky, the getopt message on stderr is not standardized.
+shell -err -expect {option --} "varnishd -A "
+
 shell -err -expect {Usage: varnishd [options]} "varnishd -? "
 shell -err -expect {Too many arguments} "varnishd foo "
 



More information about the varnish-commit mailing list