Module Name: src
Committed By: rillig
Date: Sat May 13 06:52:48 UTC 2023
Modified Files:
src/tests/usr.bin/indent: fmt_block.c fmt_decl.c lsym_binary_op.c
lsym_comma.c lsym_comment.c lsym_do.c lsym_unary_op.c lsym_while.c
t_misc.sh
Log Message:
tests/indent: explain, clean up and add some tests
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/fmt_block.c \
src/tests/usr.bin/indent/lsym_comma.c \
src/tests/usr.bin/indent/lsym_comment.c \
src/tests/usr.bin/indent/lsym_do.c \
src/tests/usr.bin/indent/lsym_unary_op.c
cvs rdiff -u -r1.37 -r1.38 src/tests/usr.bin/indent/fmt_decl.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_binary_op.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_while.c
cvs rdiff -u -r1.22 -r1.23 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/tests/usr.bin/indent/fmt_block.c
diff -u src/tests/usr.bin/indent/fmt_block.c:1.5 src/tests/usr.bin/indent/fmt_block.c:1.6
--- src/tests/usr.bin/indent/fmt_block.c:1.5 Thu May 11 09:28:53 2023
+++ src/tests/usr.bin/indent/fmt_block.c Sat May 13 06:52:48 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: fmt_block.c,v 1.5 2023/05/11 09:28:53 rillig Exp $ */
+/* $NetBSD: fmt_block.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
/*
* Tests for formatting blocks of statements and declarations.
@@ -23,6 +23,10 @@ function(void)
}
//indent end
+/*
+ * Before 2023-05-11, indent incorrectly merged the '} {' into a single line,
+ * even though they are completely unrelated.
+ */
//indent run-equals-input
Index: src/tests/usr.bin/indent/lsym_comma.c
diff -u src/tests/usr.bin/indent/lsym_comma.c:1.5 src/tests/usr.bin/indent/lsym_comma.c:1.6
--- src/tests/usr.bin/indent/lsym_comma.c:1.5 Sun Apr 24 09:04:12 2022
+++ src/tests/usr.bin/indent/lsym_comma.c Sat May 13 06:52:48 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comma.c,v 1.5 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: lsym_comma.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
/*
* Tests for the token lsym_comma, which represents a ',' in these contexts:
@@ -150,8 +150,6 @@ function(void)
/*
* In an initializer list, a ',' separates the initializer expressions.
- *
- * If a ',' starts a line, indent doesn't put a space before it.
*/
//indent input
int arr[] = {1, 2, 3};
Index: src/tests/usr.bin/indent/lsym_comment.c
diff -u src/tests/usr.bin/indent/lsym_comment.c:1.5 src/tests/usr.bin/indent/lsym_comment.c:1.6
--- src/tests/usr.bin/indent/lsym_comment.c:1.5 Thu May 11 09:28:53 2023
+++ src/tests/usr.bin/indent/lsym_comment.c Sat May 13 06:52:48 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comment.c,v 1.5 2023/05/11 09:28:53 rillig Exp $ */
+/* $NetBSD: lsym_comment.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
/*
* Tests for the token lsym_comment, which starts a comment.
@@ -337,7 +337,7 @@ tab1+++ tab2--- tab3+++ tab4--- tab5+++
}
//indent end
-/* The comment in the output has moved to the right of the '{'. */
+/* Before 2023-05-11, the comment moved to the right of the '{'. */
//indent run
{
if (0) /* comment */ {
Index: src/tests/usr.bin/indent/lsym_do.c
diff -u src/tests/usr.bin/indent/lsym_do.c:1.5 src/tests/usr.bin/indent/lsym_do.c:1.6
--- src/tests/usr.bin/indent/lsym_do.c:1.5 Thu May 11 10:39:26 2023
+++ src/tests/usr.bin/indent/lsym_do.c Sat May 13 06:52:48 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_do.c,v 1.5 2023/05/11 10:39:26 rillig Exp $ */
+/* $NetBSD: lsym_do.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
/*
* Tests for the token lsym_do, which represents the keyword 'do' that starts
@@ -49,3 +49,40 @@ else_do(int i)
} while (0);
}
//indent end
+
+
+//indent input
+void
+variants(void)
+{
+ do stmt(); while (0);
+
+ do { stmt(); } while (0);
+
+ do /* comment */ stmt(); while (0);
+
+ while (0) do {} while (0);
+}
+//indent end
+
+//indent run
+void
+variants(void)
+{
+ do
+ stmt();
+ while (0);
+
+ do {
+ stmt();
+ } while (0);
+
+ do /* comment */
+ stmt();
+ while (0);
+
+ while (0)
+ do {
+ } while (0);
+}
+//indent end
Index: src/tests/usr.bin/indent/lsym_unary_op.c
diff -u src/tests/usr.bin/indent/lsym_unary_op.c:1.5 src/tests/usr.bin/indent/lsym_unary_op.c:1.6
--- src/tests/usr.bin/indent/lsym_unary_op.c:1.5 Sun Apr 24 10:36:37 2022
+++ src/tests/usr.bin/indent/lsym_unary_op.c Sat May 13 06:52:48 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_unary_op.c,v 1.5 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_unary_op.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
/*
* Tests for the token lsym_unary_op, which represents a unary operator.
@@ -8,6 +8,12 @@
*
* In a type name, the "unary operator" '*' represents the derivation of a
* pointer type.
+ *
+ * See also:
+ * lsym_binary_op.c
+ * lsym_postfix_op.c
+ * C11 6.4.6 "Punctuators"
+ * C11 6.5 "Expressions"
*/
//indent input
@@ -54,3 +60,20 @@ int var = p -> member;
//indent run -di0
int var = p->member;
//indent end
+
+
+//indent input
+void
+unary_operators(void)
+{
+ ++prefix_increment;
+ --prefix_decrement;
+ int *address = &lvalue;
+ int dereferenced = *address;
+ int positive = +number;
+ int negative = -number;
+ bool negated = !condition;
+}
+//indent end
+
+//indent run-equals-input -di0
Index: src/tests/usr.bin/indent/fmt_decl.c
diff -u src/tests/usr.bin/indent/fmt_decl.c:1.37 src/tests/usr.bin/indent/fmt_decl.c:1.38
--- src/tests/usr.bin/indent/fmt_decl.c:1.37 Thu May 11 09:28:53 2023
+++ src/tests/usr.bin/indent/fmt_decl.c Sat May 13 06:52:48 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: fmt_decl.c,v 1.37 2023/05/11 09:28:53 rillig Exp $ */
+/* $NetBSD: fmt_decl.c,v 1.38 2023/05/13 06:52:48 rillig Exp $ */
/*
* Tests for declarations of global variables, external functions, and local
@@ -88,38 +88,8 @@ typedef struct Complex
/*
- * As of 2021-11-07, indent parses the following function definition as these
- * tokens:
- *
- * line 1: type_outside_parentheses "void"
- * line 1: newline "\n"
- * line 2: funcname "t1"
- * line 2: newline "\n" repeated, see search_stmt
- * line 3: funcname "t1" XXX: wrong line_no
- * line 3: lparen_or_lbracket "("
- * line 3: type_in_parentheses "char"
- * line 3: unary_op "*"
- * line 3: word "a"
- * line 3: comma ","
- * line 3: type_in_parentheses "int"
- * line 3: word "b"
- * line 3: comma ","
- * line 3: newline "\n"
- * line 4: type_in_parentheses "void"
- * line 4: lparen_or_lbracket "("
- * line 4: unary_op "*"
- * line 4: word "fn"
- * line 4: rparen_or_rbracket ")"
- * line 4: lparen_or_lbracket "("
- * line 4: type_in_parentheses "void"
- * line 4: rparen_or_rbracket ")"
- * line 4: rparen_or_rbracket ")"
- * line 4: newline "\n"
- * line 5: lbrace "{"
- * line 5: lbrace "{" repeated, see search_stmt
- * line 5: newline "\n" FIXME: there is no newline in the source
- * line 6: rbrace "}"
- * line 6: eof "\n"
+ * Ensure that function definitions are reasonably indented. Before
+ * 2023-05-11, tokens were repeatedly read, and the line numbers were wrong.
*/
//indent input
void
@@ -527,7 +497,10 @@ function_name_____20________30________40
{}
//indent end
-/* FIXME: The space between '){' is missing. */
+/*
+ * Before 2023-05-11, indent moved the '{' right after the '(void)', without
+ * any space in between.
+ */
//indent run
int *function_name_____20________30________40________50
(void)
@@ -547,6 +520,10 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
{}
//indent end
+/*
+ * Before 2023-05-11, indent moved the '{' right after the '(void)', without
+ * any space in between.
+ */
//indent run
int *aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
(void)
@@ -607,7 +584,8 @@ buffer_add(buffer *buf, char ch)
/*
- * Indent gets easily confused by type names it does not know about.
+ * Before lexi.c 1.153 from 2021-11-25, indent did not recognize 'Token' as a
+ * type name and then messed up the positioning of the '{'.
*/
//indent input
static Token
Index: src/tests/usr.bin/indent/lsym_binary_op.c
diff -u src/tests/usr.bin/indent/lsym_binary_op.c:1.6 src/tests/usr.bin/indent/lsym_binary_op.c:1.7
--- src/tests/usr.bin/indent/lsym_binary_op.c:1.6 Sun Apr 24 10:36:37 2022
+++ src/tests/usr.bin/indent/lsym_binary_op.c Sat May 13 06:52:48 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_binary_op.c,v 1.6 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_binary_op.c,v 1.7 2023/05/13 06:52:48 rillig Exp $ */
/*
* Tests for the token lsym_binary_op, which represents a binary operator in
@@ -160,3 +160,14 @@ int col_9 //
= //
9;
//indent end
+
+
+/*
+ * The ternary conditional operator is not a binary operator, but both its
+ * components '?' and ':' follow the same spacing rules.
+ */
+//indent input
+int conditional = condition ? number : number;
+//indent end
+
+//indent run-equals-input -di0
Index: src/tests/usr.bin/indent/lsym_while.c
diff -u src/tests/usr.bin/indent/lsym_while.c:1.4 src/tests/usr.bin/indent/lsym_while.c:1.5
--- src/tests/usr.bin/indent/lsym_while.c:1.4 Sun Apr 24 10:36:37 2022
+++ src/tests/usr.bin/indent/lsym_while.c Sat May 13 06:52:48 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_while.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_while.c,v 1.5 2023/05/13 06:52:48 rillig Exp $ */
/*
* Tests for the token 'lsym_while', which represents the keyword 'while' that
@@ -25,3 +25,26 @@ function(void)
while (cond);
}
//indent end
+
+
+/*
+ * The keyword 'while' must only be indented if it follows a psym_do_stmt,
+ * otherwise it starts a new statement and must start a new line.
+ */
+//indent input
+void
+function(void)
+{
+ {} while (0);
+}
+//indent end
+
+//indent run
+void
+function(void)
+{
+ {
+/* $ FIXME: The '} while' is misleading. */
+ } while (0);
+}
+//indent end
Index: src/tests/usr.bin/indent/t_misc.sh
diff -u src/tests/usr.bin/indent/t_misc.sh:1.22 src/tests/usr.bin/indent/t_misc.sh:1.23
--- src/tests/usr.bin/indent/t_misc.sh:1.22 Fri May 12 10:53:33 2023
+++ src/tests/usr.bin/indent/t_misc.sh Sat May 13 06:52:48 2023
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: t_misc.sh,v 1.22 2023/05/12 10:53:33 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.23 2023/05/13 06:52:48 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -26,7 +26,7 @@
# POSSIBILITY OF SUCH DAMAGE.
# Tests for indent that do not follow the input-profile-output scheme that is
-# used in t_indent.
+# used in t_options.
indent=$(atf_config_get usr.bin.indent.test_indent /usr/bin/indent)