Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/indent tests/indent: migrate token tests to ot...
details: https://anonhg.NetBSD.org/src/rev/a874dd25461a
branches: trunk
changeset: 365773:a874dd25461a
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Apr 24 10:36:37 2022 +0000
description:
tests/indent: migrate token tests to other tests
In indent.h 1.49 from 2021-10-25, the enumeration token_type was split
into lexer_symbol and parser_symbol to more clearly express that these
tokens fall into completely different classes of usage patterns.
diffstat:
distrib/sets/lists/tests/mi | 58 +-
tests/usr.bin/indent/Makefile | 31 +-
tests/usr.bin/indent/edge_cases.c | 42 +
tests/usr.bin/indent/fmt_decl.c | 23 +-
tests/usr.bin/indent/fmt_init.c | 39 +
tests/usr.bin/indent/lsym_binary_op.c | 88 +-
tests/usr.bin/indent/lsym_comment.c | 1081 +++++++++++++++-
tests/usr.bin/indent/lsym_do.c | 18 +-
tests/usr.bin/indent/lsym_eof.c | 11 +-
tests/usr.bin/indent/lsym_for.c | 81 +-
tests/usr.bin/indent/lsym_form_feed.c | 40 +-
tests/usr.bin/indent/lsym_funcname.c | 12 +-
tests/usr.bin/indent/lsym_if.c | 17 +-
tests/usr.bin/indent/lsym_newline.c | 25 +-
tests/usr.bin/indent/lsym_preprocessing.c | 176 ++-
tests/usr.bin/indent/lsym_rparen_or_rbracket.c | 11 +-
tests/usr.bin/indent/lsym_semicolon.c | 31 +-
tests/usr.bin/indent/lsym_storage_class.c | 8 +-
tests/usr.bin/indent/lsym_tag.c | 76 +-
tests/usr.bin/indent/lsym_typedef.c | 13 +-
tests/usr.bin/indent/lsym_unary_op.c | 36 +-
tests/usr.bin/indent/lsym_while.c | 21 +-
tests/usr.bin/indent/lsym_word.c | 115 +-
tests/usr.bin/indent/psym_decl.c | 26 +-
tests/usr.bin/indent/psym_do.c | 42 +-
tests/usr.bin/indent/psym_do_stmt.c | 24 +-
tests/usr.bin/indent/psym_else.c | 65 +-
tests/usr.bin/indent/psym_stmt.c | 18 +-
tests/usr.bin/indent/psym_stmt_list.c | 39 +-
tests/usr.bin/indent/token_binary_op.c | 153 --
tests/usr.bin/indent/token_comment.c | 1092 ----------------
tests/usr.bin/indent/token_decl.c | 31 -
tests/usr.bin/indent/token_do_stmt.c | 29 -
tests/usr.bin/indent/token_end_of_file.c | 16 -
tests/usr.bin/indent/token_for_exprs.c | 70 -
tests/usr.bin/indent/token_form_feed.c | 45 -
tests/usr.bin/indent/token_funcname.c | 17 -
tests/usr.bin/indent/token_ident.c | 94 -
tests/usr.bin/indent/token_keyword_do.c | 24 -
tests/usr.bin/indent/token_keyword_do_else.c | 30 -
tests/usr.bin/indent/token_keyword_else.c | 46 -
tests/usr.bin/indent/token_keyword_for_if_while.c | 35 -
tests/usr.bin/indent/token_keyword_struct_union_enum.c | 78 -
tests/usr.bin/indent/token_newline.c | 29 -
tests/usr.bin/indent/token_postfix_op.c | 18 -
tests/usr.bin/indent/token_preprocessing.c | 178 --
tests/usr.bin/indent/token_rparen.c | 17 -
tests/usr.bin/indent/token_semicolon.c | 42 -
tests/usr.bin/indent/token_stmt.c | 25 -
tests/usr.bin/indent/token_stmt_list.c | 25 -
tests/usr.bin/indent/token_storage_class.c | 13 -
tests/usr.bin/indent/token_string_prefix.c | 28 -
tests/usr.bin/indent/token_switch_expr.c | 16 -
tests/usr.bin/indent/token_type_def.c | 15 -
tests/usr.bin/indent/token_unary_op.c | 19 -
tests/usr.bin/indent/token_while_expr.c | 29 -
56 files changed, 2153 insertions(+), 2328 deletions(-)
diffs (truncated from 5004 to 300 lines):
diff -r a7df0d046cb3 -r a874dd25461a distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Sun Apr 24 10:35:15 2022 +0000
+++ b/distrib/sets/lists/tests/mi Sun Apr 24 10:36:37 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1197 2022/04/24 08:48:17 rillig Exp $
+# $NetBSD: mi,v 1.1198 2022/04/24 10:36:37 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4771,6 +4771,7 @@
./usr/tests/usr.bin/indent/declarations.0 tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/declarations.0.stderr tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/declarations.0.stdout tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/edge_cases.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/elsecomment.0 tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/elsecomment.0.pro tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/elsecomment.0.stdout tests-obsolete obsolete,atf
@@ -4782,6 +4783,7 @@
./usr/tests/usr.bin/indent/fmt_decl.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/fmt_else_comment.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/fmt_expr.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/indent/fmt_init.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/indent_off_on.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/indent_variables.0 tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/indent_variables.0.pro tests-obsolete obsolete,atf
@@ -5253,44 +5255,44 @@
./usr/tests/usr.bin/indent/token-while_expr.0 tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token-while_expr.0.pro tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token-while_expr.0.stdout tests-obsolete obsolete,atf
-./usr/tests/usr.bin/indent/token_binary_op.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/indent/token_binary_op.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_case_label.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_colon.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_comma.c tests-obsolete obsolete,atf
-./usr/tests/usr.bin/indent/token_comment.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_decl.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_do_stmt.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_end_of_file.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_for_exprs.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_form_feed.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_funcname.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_ident.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/indent/token_comment.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_decl.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_do_stmt.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_end_of_file.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_for_exprs.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_form_feed.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_funcname.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_ident.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_if_expr.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_if_expr_stmt.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_if_expr_stmt_else.c tests-obsolete obsolete,atf
-./usr/tests/usr.bin/indent/token_keyword_do.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_keyword_do_else.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_keyword_else.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_keyword_for_if_while.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_keyword_struct_union_enum.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/indent/token_keyword_do.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_keyword_do_else.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_keyword_else.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_keyword_for_if_while.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_keyword_struct_union_enum.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_lbrace.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_lparen.c tests-obsolete obsolete,atf
-./usr/tests/usr.bin/indent/token_newline.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/indent/token_newline.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_period.c tests-obsolete obsolete,atf
-./usr/tests/usr.bin/indent/token_postfix_op.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_preprocessing.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/indent/token_postfix_op.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_preprocessing.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_question.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_rbrace.c tests-obsolete obsolete,atf
-./usr/tests/usr.bin/indent/token_rparen.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_semicolon.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_stmt.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_stmt_list.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_storage_class.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_string_prefix.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_switch_expr.c tests-usr.bin-tests compattestfile,atf
-./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/token_rparen.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_semicolon.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_stmt.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_stmt_list.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_storage_class.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_string_prefix.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_switch_expr.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_type_def.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_unary_op.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_while_expr.c tests-obsolete obsolete,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
diff -r a7df0d046cb3 -r a874dd25461a tests/usr.bin/indent/Makefile
--- a/tests/usr.bin/indent/Makefile Sun Apr 24 10:35:15 2022 +0000
+++ b/tests/usr.bin/indent/Makefile Sun Apr 24 10:36:37 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.44 2022/04/24 09:04:12 rillig Exp $
+# $NetBSD: Makefile,v 1.45 2022/04/24 10:36:37 rillig Exp $
.include <bsd.own.mk>
@@ -8,10 +8,12 @@
TESTS_SH+= t_options
FILESDIR= ${TESTSDIR}
+FILES+= edge_cases.c
FILES+= fmt_block.c
FILES+= fmt_decl.c
FILES+= fmt_else_comment.c
FILES+= fmt_expr.c
+FILES+= fmt_init.c
FILES+= indent_off_on.c
FILES+= label.c
FILES+= lex_char.c
@@ -110,33 +112,6 @@
FILES+= psym_switch_expr.c
FILES+= psym_while_expr.c
FILES+= t_options.awk
-FILES+= token_binary_op.c
-FILES+= token_comment.c
-FILES+= token_decl.c
-FILES+= token_do_stmt.c
-FILES+= token_end_of_file.c
-FILES+= token_for_exprs.c
-FILES+= token_form_feed.c
-FILES+= token_funcname.c
-FILES+= token_ident.c
-FILES+= token_keyword_do.c
-FILES+= token_keyword_do_else.c
-FILES+= token_keyword_else.c
-FILES+= token_keyword_for_if_while.c
-FILES+= token_keyword_struct_union_enum.c
-FILES+= token_newline.c
-FILES+= token_postfix_op.c
-FILES+= token_preprocessing.c
-FILES+= token_rparen.c
-FILES+= token_semicolon.c
-FILES+= token_stmt.c
-FILES+= token_stmt_list.c
-FILES+= token_storage_class.c
-FILES+= token_string_prefix.c
-FILES+= token_switch_expr.c
-FILES+= token_type_def.c
-FILES+= token_unary_op.c
-FILES+= token_while_expr.c
add-test: .PHONY
@set -eu; \
diff -r a7df0d046cb3 -r a874dd25461a tests/usr.bin/indent/edge_cases.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/indent/edge_cases.c Sun Apr 24 10:36:37 2022 +0000
@@ -0,0 +1,42 @@
+/* $NetBSD: edge_cases.c,v 1.1 2022/04/24 10:36:37 rillig Exp $ */
+
+/*
+ * Tests for edge cases in the C programming language that indent does not
+ * support or in which cases indent behaves strangely.
+ */
+
+/*
+ * Digraphs are replacements for the characters '[', '{' and '#', which are
+ * missing in some exotic restricted source character sets.
+ *
+ * See C99 6.4.6
+ */
+//indent input
+void
+digraphs(void)
+{
+ /* same as 'array[subscript]' */
+ number = array<:subscript:>;
+
+ /* same as '(int){ initializer }' */
+ number = (int)<% initializer %>;
+}
+//indent end
+
+//indent run
+void
+digraphs(void)
+{
+ /* same as 'array[subscript]' */
+// $ XXX: The indentation is completely wrong.
+// $ XXX: The space between 'array' and '<' doesn't belong there.
+number = array <:subscript:>;
+
+ /* same as '(int){ initializer }' */
+// $ XXX: The space between '%' and '>' doesn't belong there.
+ number = (int)<%initializer % >;
+}
+//indent end
+
+/* TODO: test trigraphs, which are as unusual as digraphs */
+/* TODO: test digraphs and trigraphs in string literals, just for fun */
diff -r a7df0d046cb3 -r a874dd25461a tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c Sun Apr 24 10:35:15 2022 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c Sun Apr 24 10:36:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fmt_decl.c,v 1.35 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: fmt_decl.c,v 1.36 2022/04/24 10:36:37 rillig Exp $ */
/*
* Tests for declarations of global variables, external functions, and local
@@ -884,3 +884,24 @@
{
}
//indent end
+
+
+/*
+ * Before NetBSD indent.c 1.178 from 2021-10-29, indent removed the blank
+ * before the '=', in the second and third of these function pointer
+ * declarations. This was because indent interpreted the prototype parameters
+ * 'int' and 'int, int' as type casts, which doesn't make sense at all. Fixing
+ * this properly requires large style changes since indent is based on simple
+ * heuristics all over. This didn't change in indent.c 1.178; instead, the
+ * rule for inserting a blank before a binary operator was changed to always
+ * insert a blank, except at the beginning of a line.
+ */
+//indent input
+char *(*fn)() = NULL;
+char *(*fn)(int) = NULL;
+char *(*fn)(int, int) = NULL;
+//indent end
+
+/* XXX: The parameter '(int)' is wrongly interpreted as a type cast. */
+/* XXX: The parameter '(int, int)' is wrongly interpreted as a type cast. */
+//indent run-equals-input -di0
diff -r a7df0d046cb3 -r a874dd25461a tests/usr.bin/indent/fmt_init.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/indent/fmt_init.c Sun Apr 24 10:36:37 2022 +0000
@@ -0,0 +1,39 @@
+/* $NetBSD: fmt_init.c,v 1.1 2022/04/24 10:36:37 rillig Exp $ */
+
+/*
+ * Tests for variable initializations.
+ */
+
+//indent input
+int global = { initializer };
+int global = {
+ initializer
+};
+
+void
+example(void)
+{
+ int local = { initializer };
+ int local = {
+ initializer
+ };
+}
+//indent end
+
+//indent run -di0
+// $ XXX: The spaces around the initializer are gone.
+int global = {initializer};
+int global = {
+ initializer
+};
+
+void
+example(void)
+{
+ // $ XXX: The spaces around the initializer are gone.
+ int local = {initializer};
+ int local = {
+ initializer
+ };
+}
+//indent end
diff -r a7df0d046cb3 -r a874dd25461a tests/usr.bin/indent/lsym_binary_op.c
--- a/tests/usr.bin/indent/lsym_binary_op.c Sun Apr 24 10:35:15 2022 +0000
+++ b/tests/usr.bin/indent/lsym_binary_op.c Sun Apr 24 10:36:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_binary_op.c,v 1.5 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: lsym_binary_op.c,v 1.6 2022/04/24 10:36:37 rillig Exp $ */
/*
* Tests for the token lsym_binary_op, which represents a binary operator in
@@ -74,3 +74,89 @@
//indent run -di0
int var = expr * *ptr;
//indent end
+
+
+/*
+ * When indent tokenizes some operators, it allows for
+ * arbitrary repetitions of the operator character, followed by an
+ * arbitrary amount of '='. This is used for operators like '&&' or
+ * '|||==='.
+ *
+ * Before 2021-03-07 22:11:01, the comment '//' was treated as an
+ * operator as well, and so was the comment '/////', leading to
+ * unexpected results.
Home |
Main Index |
Thread Index |
Old Index