Module Name: src
Committed By: rillig
Date: Thu Oct 7 18:07:25 UTC 2021
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/indent: Makefile
src/usr.bin/indent: args.c
Added Files:
src/tests/usr.bin/indent: opt.0 opt.0.pro opt.0.stdout
Log Message:
tests/indent: test parsing of command line options in profile file
To generate a diff of this commit:
cvs rdiff -u -r1.1132 -r1.1133 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/indent/opt.0 \
src/tests/usr.bin/indent/opt.0.pro src/tests/usr.bin/indent/opt.0.stdout
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/args.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1132 src/distrib/sets/lists/tests/mi:1.1133
--- src/distrib/sets/lists/tests/mi:1.1132 Tue Oct 5 17:09:45 2021
+++ src/distrib/sets/lists/tests/mi Thu Oct 7 18:07:25 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1132 2021/10/05 17:09:45 rillig Exp $
+# $NetBSD: mi,v 1.1133 2021/10/07 18:07:25 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4985,6 +4985,9 @@
./usr/tests/usr.bin/indent/opt-v.0 tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/opt-v.0.pro tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/opt-v.0.stdout tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/indent/opt.0 tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/indent/opt.0.pro tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/indent/opt.0.stdout tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/parens.0 tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/parens.0.pro tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/parens.0.stdout tests-usr.bin-tests compattestfile,atf
Index: src/tests/usr.bin/indent/Makefile
diff -u src/tests/usr.bin/indent/Makefile:1.12 src/tests/usr.bin/indent/Makefile:1.13
--- src/tests/usr.bin/indent/Makefile:1.12 Tue Oct 5 17:09:45 2021
+++ src/tests/usr.bin/indent/Makefile Thu Oct 7 18:07:25 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.12 2021/10/05 17:09:45 rillig Exp $
+# $NetBSD: Makefile,v 1.13 2021/10/07 18:07:25 rillig Exp $
.include <bsd.own.mk>
@@ -261,6 +261,9 @@ FILES+= opt-ut.0.stdout
FILES+= opt-v.0
FILES+= opt-v.0.pro
FILES+= opt-v.0.stdout
+FILES+= opt.0
+FILES+= opt.0.pro
+FILES+= opt.0.stdout
FILES+= parens.0
FILES+= parens.0.stdout
FILES+= parens.0.pro
Index: src/usr.bin/indent/args.c
diff -u src/usr.bin/indent/args.c:1.46 src/usr.bin/indent/args.c:1.47
--- src/usr.bin/indent/args.c:1.46 Thu Oct 7 17:38:21 2021
+++ src/usr.bin/indent/args.c Thu Oct 7 18:07:25 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: args.c,v 1.46 2021/10/07 17:38:21 rillig Exp $ */
+/* $NetBSD: args.c,v 1.47 2021/10/07 18:07:25 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c 8.1 (
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.46 2021/10/07 17:38:21 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.47 2021/10/07 18:07:25 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
#endif
@@ -282,9 +282,10 @@ set_option(const char *arg)
errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1);
found:
- if (p->p_is_bool)
+ if (p->p_is_bool) {
+ /* XXX: Trailing garbage in param_start is silently ignored. */
*(bool *)p->p_var = p->p_may_negate ? arg[0] != 'n' : p->p_bool_value;
- else {
+ } else {
if (!isdigit((unsigned char)*param_start))
errx(1, "%s: ``%s'' requires a parameter",
option_source, p->p_name);
Added files:
Index: src/tests/usr.bin/indent/opt.0
diff -u /dev/null src/tests/usr.bin/indent/opt.0:1.1
--- /dev/null Thu Oct 7 18:07:25 2021
+++ src/tests/usr.bin/indent/opt.0 Thu Oct 7 18:07:25 2021
@@ -0,0 +1,12 @@
+/* $NetBSD: opt.0,v 1.1 2021/10/07 18:07:25 rillig Exp $ */
+/* $FreeBSD$ */
+
+/*
+ * Test parsing of command line options from a profile file.
+ */
+
+int global_var;
+
+int function(int expr) {
+switch (expr) { case 1: return 1; default: return 0; }
+}
Index: src/tests/usr.bin/indent/opt.0.pro
diff -u /dev/null src/tests/usr.bin/indent/opt.0.pro:1.1
--- /dev/null Thu Oct 7 18:07:25 2021
+++ src/tests/usr.bin/indent/opt.0.pro Thu Oct 7 18:07:25 2021
@@ -0,0 +1,27 @@
+/* $NetBSD: opt.0.pro,v 1.1 2021/10/07 18:07:25 rillig Exp $ */
+/* $FreeBSD$ */
+
+/* The latter of the two options wins. */
+-di5
+-di12
+
+/* It is possible to embed comments in the options, but nobody does that. */
+-/* comment */bacc
+-T/* define a type */custom_type
+
+/*
+ * For int or float options, trailing garbage is ignored.
+ *
+ * See atoi, atof.
+ */
+-i3garbage
+-cli3.5garbage
+
+-b/*/acc /* The comment is '/' '*' '/', making the option '-bacc'. */
+
+/*
+ * For boolean options, trailing garbage is ignored.
+ *
+ * See strncmp
+ */
+-bacchus /* Is interpreted as '-bacc'. */
Index: src/tests/usr.bin/indent/opt.0.stdout
diff -u /dev/null src/tests/usr.bin/indent/opt.0.stdout:1.1
--- /dev/null Thu Oct 7 18:07:25 2021
+++ src/tests/usr.bin/indent/opt.0.stdout Thu Oct 7 18:07:25 2021
@@ -0,0 +1,24 @@
+/* $NetBSD: opt.0.stdout,v 1.1 2021/10/07 18:07:25 rillig Exp $ */
+/* $FreeBSD$ */
+
+/*
+ * Test parsing of command line options from a profile file.
+ */
+
+/* $ The variable name is indented by 12 characters due to -di12. */
+int global_var;
+
+int
+function(int expr)
+{
+ switch (expr) {
+/* $ The indentation is 3 + (int)(3.5 * 3), so 3 + 10.5, so 13. */
+/* $ See parse.c, function parse, 'case switch_expr'. */
+ case 1:
+/* $ The indentation is 3 + (int)3.5 * 3 + 3, so 3 + 9 + 3, so 15. */
+/* $ See parse.c, function parse, 'case switch_expr'. */
+ return 1;
+ default:
+ return 0;
+ }
+}