Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent tests/indent: test parsing of command line op...
details: https://anonhg.NetBSD.org/src/rev/4c9db758b01a
branches: trunk
changeset: 1024010:4c9db758b01a
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Oct 07 18:07:25 2021 +0000
description:
tests/indent: test parsing of command line options in profile file
diffstat:
distrib/sets/lists/tests/mi | 5 ++++-
tests/usr.bin/indent/Makefile | 5 ++++-
tests/usr.bin/indent/opt.0 | 12 ++++++++++++
tests/usr.bin/indent/opt.0.pro | 27 +++++++++++++++++++++++++++
tests/usr.bin/indent/opt.0.stdout | 24 ++++++++++++++++++++++++
usr.bin/indent/args.c | 9 +++++----
6 files changed, 76 insertions(+), 6 deletions(-)
diffs (144 lines):
diff -r 607a31acd66c -r 4c9db758b01a distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Thu Oct 07 17:38:21 2021 +0000
+++ b/distrib/sets/lists/tests/mi Thu Oct 07 18:07:25 2021 +0000
@@ -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
diff -r 607a31acd66c -r 4c9db758b01a tests/usr.bin/indent/Makefile
--- a/tests/usr.bin/indent/Makefile Thu Oct 07 17:38:21 2021 +0000
+++ b/tests/usr.bin/indent/Makefile Thu Oct 07 18:07:25 2021 +0000
@@ -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-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
diff -r 607a31acd66c -r 4c9db758b01a tests/usr.bin/indent/opt.0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/indent/opt.0 Thu Oct 07 18:07:25 2021 +0000
@@ -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; }
+}
diff -r 607a31acd66c -r 4c9db758b01a tests/usr.bin/indent/opt.0.pro
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/indent/opt.0.pro Thu Oct 07 18:07:25 2021 +0000
@@ -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'. */
diff -r 607a31acd66c -r 4c9db758b01a tests/usr.bin/indent/opt.0.stdout
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/indent/opt.0.stdout Thu Oct 07 18:07:25 2021 +0000
@@ -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;
+ }
+}
diff -r 607a31acd66c -r 4c9db758b01a usr.bin/indent/args.c
--- a/usr.bin/indent/args.c Thu Oct 07 17:38:21 2021 +0000
+++ b/usr.bin/indent/args.c Thu Oct 07 18:07:25 2021 +0000
@@ -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 @@
#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 @@
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);
Home |
Main Index |
Thread Index |
Old Index