Module Name:    src
Committed By:   rillig
Date:           Sat Oct 23 21:45:14 UTC 2021

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/usr.bin/indent: Makefile t_misc.sh
Removed Files:
        src/tests/usr.bin/indent: opt-U.0 opt-U.0.list opt-U.0.pro
            opt-U.0.stdout opt-npro.0 opt-npro.0.pro opt-npro.0.stdout opt.0
            opt.0.pro opt.0.stdout t_indent.sh types_from_file.0
            types_from_file.0.list types_from_file.0.pro
            types_from_file.0.stdout

Log Message:
tests/indent: migrate remaining tests from t_indent to t_options

The test types_from_file was a subset of opt_U and thus has been
removed.


To generate a diff of this commit:
cvs rdiff -u -r1.1160 -r1.1161 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.32 -r1.33 src/tests/usr.bin/indent/Makefile
cvs rdiff -u -r1.2 -r0 src/tests/usr.bin/indent/opt-U.0 \
    src/tests/usr.bin/indent/opt-U.0.stdout \
    src/tests/usr.bin/indent/opt-npro.0 \
    src/tests/usr.bin/indent/opt-npro.0.stdout
cvs rdiff -u -r1.1 -r0 src/tests/usr.bin/indent/opt-U.0.list \
    src/tests/usr.bin/indent/opt-U.0.pro \
    src/tests/usr.bin/indent/opt-npro.0.pro src/tests/usr.bin/indent/opt.0 \
    src/tests/usr.bin/indent/opt.0.stdout \
    src/tests/usr.bin/indent/types_from_file.0 \
    src/tests/usr.bin/indent/types_from_file.0.list \
    src/tests/usr.bin/indent/types_from_file.0.pro \
    src/tests/usr.bin/indent/types_from_file.0.stdout
cvs rdiff -u -r1.3 -r0 src/tests/usr.bin/indent/opt.0.pro
cvs rdiff -u -r1.7 -r0 src/tests/usr.bin/indent/t_indent.sh
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/t_misc.sh

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.1160 src/distrib/sets/lists/tests/mi:1.1161
--- src/distrib/sets/lists/tests/mi:1.1160	Sat Oct 23 20:30:23 2021
+++ src/distrib/sets/lists/tests/mi	Sat Oct 23 21:45:14 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1160 2021/10/23 20:30:23 rillig Exp $
+# $NetBSD: mi,v 1.1161 2021/10/23 21:45:14 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4798,10 +4798,10 @@
 ./usr/tests/usr.bin/indent/opt-T.0					tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-T.0.pro					tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-T.0.stdout				tests-obsolete		obsolete,atf
-./usr/tests/usr.bin/indent/opt-U.0					tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/indent/opt-U.0.list					tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/indent/opt-U.0.pro					tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/indent/opt-U.0.stdout				tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/indent/opt-U.0					tests-obsolete		obsolete,atf
+./usr/tests/usr.bin/indent/opt-U.0.list					tests-obsolete		obsolete,atf
+./usr/tests/usr.bin/indent/opt-U.0.pro					tests-obsolete		obsolete,atf
+./usr/tests/usr.bin/indent/opt-U.0.stdout				tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-bacc.0					tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-bacc.0.pro				tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-bacc.0.stdout				tests-obsolete		obsolete,atf
@@ -4958,9 +4958,9 @@
 ./usr/tests/usr.bin/indent/opt-npcs.0					tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-npcs.0.pro				tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-npcs.0.stdout				tests-obsolete		obsolete,atf
-./usr/tests/usr.bin/indent/opt-npro.0					tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/indent/opt-npro.0.pro				tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/indent/opt-npro.0.stdout				tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/indent/opt-npro.0					tests-obsolete		obsolete,atf
+./usr/tests/usr.bin/indent/opt-npro.0.pro				tests-obsolete		obsolete,atf
+./usr/tests/usr.bin/indent/opt-npro.0.stdout				tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-npsl.0					tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-npsl.0.pro				tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-npsl.0.stdout				tests-obsolete		obsolete,atf
@@ -5000,9 +5000,9 @@
 ./usr/tests/usr.bin/indent/opt-v.0					tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-v.0.pro					tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt-v.0.stdout				tests-obsolete		obsolete,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/opt.0					tests-obsolete		obsolete,atf
+./usr/tests/usr.bin/indent/opt.0.pro					tests-obsolete		obsolete,atf
+./usr/tests/usr.bin/indent/opt.0.stdout					tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/opt_P.c					tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/opt_T.c					tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/opt_bacc.c					tests-usr.bin-tests	compattestfile,atf
@@ -5061,7 +5061,7 @@
 ./usr/tests/usr.bin/indent/surplusbad.0.pro				tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/surplusbad.0.stdout				tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/t_errors					tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/indent/t_indent					tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/indent/t_indent					tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/t_misc					tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/t_options					tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/t_options.awk				tests-usr.bin-tests	compattestfile,atf
@@ -5217,10 +5217,10 @@
 ./usr/tests/usr.bin/indent/token_type_def.c				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/token_unary_op.c				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/token_while_expr.c				tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/indent/types_from_file.0				tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/indent/types_from_file.0.list			tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/indent/types_from_file.0.pro			tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/indent/types_from_file.0.stdout			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/indent/types_from_file.0				tests-obsolete		obsolete,atf
+./usr/tests/usr.bin/indent/types_from_file.0.list			tests-obsolete		obsolete,atf
+./usr/tests/usr.bin/indent/types_from_file.0.pro			tests-obsolete		obsolete,atf
+./usr/tests/usr.bin/indent/types_from_file.0.stdout			tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/wchar.0					tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/indent/wchar.0.stdout				tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/infocmp				tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/indent/Makefile
diff -u src/tests/usr.bin/indent/Makefile:1.32 src/tests/usr.bin/indent/Makefile:1.33
--- src/tests/usr.bin/indent/Makefile:1.32	Sat Oct 23 20:30:23 2021
+++ src/tests/usr.bin/indent/Makefile	Sat Oct 23 21:45:14 2021
@@ -1,10 +1,9 @@
-#	$NetBSD: Makefile,v 1.32 2021/10/23 20:30:23 rillig Exp $
+#	$NetBSD: Makefile,v 1.33 2021/10/23 21:45:14 rillig Exp $
 
 .include <bsd.own.mk>
 
 TESTSDIR=	${TESTSBASE}/usr.bin/indent
 TESTS_SH=	t_errors
-TESTS_SH+=	t_indent
 TESTS_SH+=	t_misc
 TESTS_SH+=	t_options
 
@@ -18,16 +17,6 @@ FILES+=		label.c
 FILES+=		lex_ident.c
 FILES+=		lex_char.c
 FILES+=		lex_string.c
-FILES+=		opt-U.0
-FILES+=		opt-U.0.list
-FILES+=		opt-U.0.pro
-FILES+=		opt-U.0.stdout
-FILES+=		opt-npro.0
-FILES+=		opt-npro.0.pro
-FILES+=		opt-npro.0.stdout
-FILES+=		opt.0
-FILES+=		opt.0.pro
-FILES+=		opt.0.stdout
 FILES+=		opt_P.c
 FILES+=		opt_T.c
 FILES+=		opt_bacc.c
@@ -110,10 +99,6 @@ FILES+=		token_switch_expr.c
 FILES+=		token_type_def.c
 FILES+=		token_unary_op.c
 FILES+=		token_while_expr.c
-FILES+=		types_from_file.0
-FILES+=		types_from_file.0.stdout
-FILES+=		types_from_file.0.list
-FILES+=		types_from_file.0.pro
 
 add-test: .PHONY
 	@set -eu; \

Index: src/tests/usr.bin/indent/t_misc.sh
diff -u src/tests/usr.bin/indent/t_misc.sh:1.4 src/tests/usr.bin/indent/t_misc.sh:1.5
--- src/tests/usr.bin/indent/t_misc.sh:1.4	Fri Oct 22 20:54:36 2021
+++ src/tests/usr.bin/indent/t_misc.sh	Sat Oct 23 21:45:14 2021
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_misc.sh,v 1.4 2021/10/22 20:54:36 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.5 2021/10/23 21:45:14 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -190,10 +190,129 @@ option_P_in_profile_file_body()
 	    "$indent" < code.c
 }
 
+atf_test_case 'opt'
+opt_body()
+{
+	# Test parsing of command line options from a profile file.
+
+	cat <<-\EOF > code.c
+		int global_var;
+
+		int function(int expr) {
+		switch (expr) { case 1: return 1; default: return 0; }
+		}
+	EOF
+
+	cat << \EOF > .indent.pro
+/* The latter of the two options wins. */
+-di5
+-di12
+
+/*
+ * It is possible to embed comments in the middle of an option, but nobody
+ * does that.
+ */
+-/* comment */bacc
+-T/* define
+a type */custom_type
+
+/* For int options, trailing garbage would lead to an error message. */
+-i3
+
+/*
+ * For float options, trailing garbage is ignored.
+ *
+ * See atof.
+ */
+-cli3.5garbage
+
+-b/*/acc	/* The comment is '/' '*' '/', making the option '-bacc'. */
+EOF
+
+	sed '/[$]/d' << \EOF > code.exp
+/* $ 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;
+   }
+}
+EOF
+
+	atf_check -o 'file:code.exp' \
+	    "$indent" code.c -st
+}
+
+atf_test_case 'opt_npro'
+opt_npro_body()
+{
+	# Mentioning the option -npro in a .pro file has no effect since at
+	# that point, indent has already decided to load the .pro file, and
+	# it only decides once.
+
+	echo ' -npro -di8' > .indent.pro
+	echo 'int var;' > code.c
+	printf 'int\tvar;\n' > code.exp
+
+	atf_check -o 'file:code.exp' \
+	    "$indent" code.c -st
+}
+
+atf_test_case 'opt_U'
+opt_U_body()
+{
+	# From each line of this file, the first word is taken to be a type
+	# name.
+	#
+	# Since neither '/*' nor '' are syntactically valid type names, this
+	# means that all kinds of comments are effectively ignored.  When a
+	# type name is indented by whitespace, it is ignored as well.
+	#
+	# Since only the first word of each line is relevant, any remaining
+	# words can be used for comments.
+	cat <<-\EOF > code.types
+		/* Comments are effectively ignored since they never match. */
+		# This comment is ignored as well.
+		; So is this comment.
+		# The following line is empty and adds a type whose name is empty.
+
+		size_t			from stddef.h
+		off_t			for file offsets
+ 		 ignored_t		is ignored since it is indented
+	EOF
+
+	cat <<-\EOF > code.c
+		int known_1 = (size_t)   *   arg;
+		int known_2 = (off_t)   *   arg;
+		int ignored = (ignored_t)   *   arg;
+	EOF
+	cat <<-\EOF > code.exp
+		int known_1 = (size_t)*arg;
+		int known_2 = (off_t)*arg;
+		int ignored = (ignored_t) * arg;
+	EOF
+
+	atf_check -o 'file:code.exp' \
+	    "$indent" -Ucode.types code.c -di0 -st
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case 'in_place'
 	atf_add_test_case 'verbose_profile'
 	atf_add_test_case 'nested_struct_declarations'
 	atf_add_test_case 'option_P_in_profile_file'
+	atf_add_test_case 'opt'
+	atf_add_test_case 'opt_npro'
+	atf_add_test_case 'opt_U'
 }

Reply via email to