Module Name: src
Committed By: rillig
Date: Fri Nov 19 22:24:29 UTC 2021
Modified Files:
src/tests/usr.bin/indent: fmt_block.c fmt_decl.c fmt_else_comment.c
fmt_expr.c indent_off_on.c lex_char.c lex_ident.c lex_string.c
lsym_offsetof.c opt_P.c opt_T.c opt_bacc.c opt_badp.c opt_bap.c
opt_bap_sob.c opt_bbb.c opt_bc.c opt_bl_br.c opt_bs.c opt_c.c
opt_cd.c t_misc.sh
Log Message:
tests/indent: refine and extend tests
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/fmt_block.c \
src/tests/usr.bin/indent/fmt_else_comment.c \
src/tests/usr.bin/indent/fmt_expr.c src/tests/usr.bin/indent/lex_char.c \
src/tests/usr.bin/indent/lex_string.c \
src/tests/usr.bin/indent/lsym_offsetof.c src/tests/usr.bin/indent/opt_P.c \
src/tests/usr.bin/indent/opt_T.c src/tests/usr.bin/indent/opt_bap_sob.c \
src/tests/usr.bin/indent/opt_c.c src/tests/usr.bin/indent/opt_cd.c
cvs rdiff -u -r1.18 -r1.19 src/tests/usr.bin/indent/fmt_decl.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/indent_off_on.c \
src/tests/usr.bin/indent/opt_bap.c src/tests/usr.bin/indent/opt_bbb.c \
src/tests/usr.bin/indent/opt_bc.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/lex_ident.c \
src/tests/usr.bin/indent/opt_bl_br.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/opt_bacc.c \
src/tests/usr.bin/indent/opt_bs.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/opt_badp.c
cvs rdiff -u -r1.15 -r1.16 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.1 src/tests/usr.bin/indent/fmt_block.c:1.2
--- src/tests/usr.bin/indent/fmt_block.c:1.1 Fri Oct 22 19:27:53 2021
+++ src/tests/usr.bin/indent/fmt_block.c Fri Nov 19 22:24:29 2021
@@ -1,6 +1,15 @@
-/* $NetBSD: fmt_block.c,v 1.1 2021/10/22 19:27:53 rillig Exp $ */
+/* $NetBSD: fmt_block.c,v 1.2 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
+/*
+ * Tests for formatting blocks of statements and declarations.
+ *
+ * See also:
+ * lsym_lbrace.c
+ * psym_stmt.c
+ * psym_stmt_list.c
+ */
+
#indent input
void
function(void)
@@ -29,3 +38,43 @@ function(void)
}
}
#indent end
+
+
+/*
+ * Two adjacent blocks must not be merged. They are typically used in C90 and
+ * earlier to declare local variables with a limited scope.
+ */
+#indent input
+void
+function(void)
+{
+ {}{}
+}
+#indent end
+
+#indent run
+void
+function(void)
+{
+ {
+/* $ FIXME: '{' must start a new line. */
+ } {
+ }
+}
+#indent end
+
+/*
+ * The buggy behavior only occurs with the default setting '-br', which
+ * places an opening brace to the right of the preceding 'if (expr)' or
+ * similar statements.
+ */
+#indent run -bl
+void
+function(void)
+{
+ {
+ }
+ {
+ }
+}
+#indent end
Index: src/tests/usr.bin/indent/fmt_else_comment.c
diff -u src/tests/usr.bin/indent/fmt_else_comment.c:1.1 src/tests/usr.bin/indent/fmt_else_comment.c:1.2
--- src/tests/usr.bin/indent/fmt_else_comment.c:1.1 Fri Oct 22 19:27:53 2021
+++ src/tests/usr.bin/indent/fmt_else_comment.c Fri Nov 19 22:24:29 2021
@@ -1,19 +1,51 @@
-/* $NetBSD: fmt_else_comment.c,v 1.1 2021/10/22 19:27:53 rillig Exp $ */
+/* $NetBSD: fmt_else_comment.c,v 1.2 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD: head/usr.bin/indent/tests/elsecomment.0.pro 314613 2017-03-03 20:15:22Z ngie $ */
-/* See r303484 and r309342 */
-
+/*
+ * Tests for comments after 'if (expr)' and 'else'. If the option '-br' is
+ * given (or rather, if '-bl' is not given), indent looks ahead to the
+ * following significant token to see whether it is a '{', it then moves the
+ * comments after the '{'.
+ *
+ * See also:
+ * FreeBSD r303484
+ * FreeBSD r309342
+ */
+
+/*
+ * The two 'if' statements below exercise two different code paths, even
+ * though they look very similar.
+ */
#indent input
void t(void) {
- /* The two if statements below excercise two different code paths. */
-
if (1) /* a */ int a; else /* b */ int b;
if (1) /* a */
int a;
else /* b */
int b;
+}
+#indent end
+#indent run
+void
+t(void)
+{
+ if (1) /* a */
+ int a;
+ else /* b */
+ int b;
+
+ if (1) /* a */
+ int a;
+ else /* b */
+ int b;
+}
+#indent end
+
+
+#indent input
+void t(void) {
if (1) {
}
@@ -50,18 +82,6 @@ void t(void) {
void
t(void)
{
- /* The two if statements below excercise two different code paths. */
-
- if (1) /* a */
- int a;
- else /* b */
- int b;
-
- if (1) /* a */
- int a;
- else /* b */
- int b;
-
if (1)
{
Index: src/tests/usr.bin/indent/fmt_expr.c
diff -u src/tests/usr.bin/indent/fmt_expr.c:1.1 src/tests/usr.bin/indent/fmt_expr.c:1.2
--- src/tests/usr.bin/indent/fmt_expr.c:1.1 Sat Oct 23 20:17:08 2021
+++ src/tests/usr.bin/indent/fmt_expr.c Fri Nov 19 22:24:29 2021
@@ -1,14 +1,16 @@
-/* $NetBSD: fmt_expr.c,v 1.1 2021/10/23 20:17:08 rillig Exp $ */
+/* $NetBSD: fmt_expr.c,v 1.2 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
* Tests for all kinds of expressions that are not directly related to unary
* or binary operators.
*
- * See also: token_binary_op, token_unary_op.
+ * See also:
+ * lsym_binary_op.c
+ * lsym_unary_op.c
*/
-/* See FreeBSD r303718. */
+/* See lsym_offsetof.c. */
#indent input
void t(void) {
int n = malloc(offsetof(struct s, f) + 1);
Index: src/tests/usr.bin/indent/lex_char.c
diff -u src/tests/usr.bin/indent/lex_char.c:1.1 src/tests/usr.bin/indent/lex_char.c:1.2
--- src/tests/usr.bin/indent/lex_char.c:1.1 Fri Oct 22 20:54:36 2021
+++ src/tests/usr.bin/indent/lex_char.c Fri Nov 19 22:24:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex_char.c,v 1.1 2021/10/22 20:54:36 rillig Exp $ */
+/* $NetBSD: lex_char.c,v 1.2 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -21,6 +21,10 @@ int escape_v = '\v';
int escape_single_quote = '\'';
int escape_double_quote = '\"';
int escape_backslash = '\\';
+int line_break_before = '\
+x';
+int line_break_after = 'x\
+';
#indent end
#indent run-equals-input -di0
Index: src/tests/usr.bin/indent/lex_string.c
diff -u src/tests/usr.bin/indent/lex_string.c:1.1 src/tests/usr.bin/indent/lex_string.c:1.2
--- src/tests/usr.bin/indent/lex_string.c:1.1 Fri Oct 22 20:54:36 2021
+++ src/tests/usr.bin/indent/lex_string.c Fri Nov 19 22:24:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex_string.c,v 1.1 2021/10/22 20:54:36 rillig Exp $ */
+/* $NetBSD: lex_string.c,v 1.2 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -28,7 +28,10 @@ char escape_newline[] = "\
#indent run-equals-input -di0
-/* Concatenated string literals are separated with a single space. */
+
+/*
+ * Concatenated string literals are separated with a single space.
+ */
#indent input
char concat[] = "line 1\n"
"line2" "has" "several""words\n";
Index: src/tests/usr.bin/indent/lsym_offsetof.c
diff -u src/tests/usr.bin/indent/lsym_offsetof.c:1.1 src/tests/usr.bin/indent/lsym_offsetof.c:1.2
--- src/tests/usr.bin/indent/lsym_offsetof.c:1.1 Thu Nov 18 21:19:19 2021
+++ src/tests/usr.bin/indent/lsym_offsetof.c Fri Nov 19 22:24:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_offsetof.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */
+/* $NetBSD: lsym_offsetof.c,v 1.2 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -7,7 +7,16 @@
*/
#indent input
-// TODO: add input
+size_t offset = offsetof(struct s, member);
#indent end
#indent run-equals-input
+#indent run-equals-input -bs
+
+/*
+ * The option '-pcs' forces a blank after the function name. That option
+ * applies to 'offsetof' as well, even though it is not really a function.
+ */
+#indent run -pcs
+size_t offset = offsetof (struct s, member);
+#indent end
Index: src/tests/usr.bin/indent/opt_P.c
diff -u src/tests/usr.bin/indent/opt_P.c:1.1 src/tests/usr.bin/indent/opt_P.c:1.2
--- src/tests/usr.bin/indent/opt_P.c:1.1 Fri Oct 22 20:54:36 2021
+++ src/tests/usr.bin/indent/opt_P.c Fri Nov 19 22:24:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_P.c,v 1.1 2021/10/22 20:54:36 rillig Exp $ */
+/* $NetBSD: opt_P.c,v 1.2 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -6,8 +6,10 @@
* instead of '$HOME/.indent.pro'.
*
* The format of the tests in t_options.sh does not allow the tests to create
- * arbitrary files, therefore this test is rather restricted. See t_misc.sh
- * for more related tests with individual setup.
+ * arbitrary files, therefore this test is rather restricted.
+ *
+ * See also:
+ * t_misc for test with custom setup
*/
#indent input
Index: src/tests/usr.bin/indent/opt_T.c
diff -u src/tests/usr.bin/indent/opt_T.c:1.1 src/tests/usr.bin/indent/opt_T.c:1.2
--- src/tests/usr.bin/indent/opt_T.c:1.1 Fri Oct 22 20:54:36 2021
+++ src/tests/usr.bin/indent/opt_T.c Fri Nov 19 22:24:29 2021
@@ -1,28 +1,36 @@
-/* $NetBSD: opt_T.c,v 1.1 2021/10/22 20:54:36 rillig Exp $ */
+/* $NetBSD: opt_T.c,v 1.2 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
+/*
+ * Tests for the option '-T', which specifies a single identifier that indent
+ * will recognize as a type name. This affects the formatting of
+ * syntactically ambiguous expressions that could be casts or multiplications,
+ * among others.
+ */
+
#indent input
-void
-example(void *arg)
-{
- int cast = (custom_type_name) * arg;
-
- int mult = (unknown_type_name) * arg;
-
- /* See the option -ta for handling these types. */
- int suff = (unknown_type_name_t) * arg;
-}
+int cast = (custom_type_name) * arg;
+
+int mult = (unknown_type_name) * arg;
+
+/* See the option -ta for handling these types. */
+int suff = (unknown_type_name_t) * arg;
#indent end
-#indent run -Tcustom_type_name
-void
-example(void *arg)
-{
- int cast = (custom_type_name)*arg;
-
- int mult = (unknown_type_name) * arg;
-
- /* See the option -ta for handling these types. */
- int suff = (unknown_type_name_t) * arg;
-}
+#indent run -Tcustom_type_name -di0
+int cast = (custom_type_name)*arg;
+
+int mult = (unknown_type_name) * arg;
+
+/* See the option -ta for handling these types. */
+int suff = (unknown_type_name_t) * arg;
+#indent end
+
+#indent run -Tcustom_type_name -di0 -cs
+int cast = (custom_type_name) *arg;
+
+int mult = (unknown_type_name) * arg;
+
+/* See the option -ta for handling these types. */
+int suff = (unknown_type_name_t) * arg;
#indent end
Index: src/tests/usr.bin/indent/opt_bap_sob.c
diff -u src/tests/usr.bin/indent/opt_bap_sob.c:1.1 src/tests/usr.bin/indent/opt_bap_sob.c:1.2
--- src/tests/usr.bin/indent/opt_bap_sob.c:1.1 Sat Oct 23 20:30:23 2021
+++ src/tests/usr.bin/indent/opt_bap_sob.c Fri Nov 19 22:24:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bap_sob.c,v 1.1 2021/10/23 20:30:23 rillig Exp $ */
+/* $NetBSD: opt_bap_sob.c,v 1.2 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -13,12 +13,19 @@ function1(void)
{
}
-///// separator /////
+///// C99 separator /////
void
function2(void)
{
}
+
+/* C block separator */
+
+void
+function3(void)
+{
+}
#indent end
#indent run -bap -sob
@@ -27,10 +34,29 @@ function1(void)
{
}
/* $ FIXME: Keep the empty line between the '}' and the '//'. */
-///// separator /////
+///// C99 separator /////
void
function2(void)
{
}
+/* $ FIXME: Keep the empty line. */
+/* C block separator */
+
+void
+function3(void)
+{
+}
#indent end
+
+/*
+ * XXX: Strangely, the option '-nbap' keeps the empty lines after the
+ * function bodies. That's exactly the opposite of the behavior that's
+ * described in the manual.
+ */
+#indent run-equals-input -nbap -sob
+
+/*
+ * Without '-sob', the option '-bap' works as intended.
+ */
+#indent run-equals-input -bap
Index: src/tests/usr.bin/indent/opt_c.c
diff -u src/tests/usr.bin/indent/opt_c.c:1.1 src/tests/usr.bin/indent/opt_c.c:1.2
--- src/tests/usr.bin/indent/opt_c.c:1.1 Fri Oct 22 20:54:36 2021
+++ src/tests/usr.bin/indent/opt_c.c Fri Nov 19 22:24:29 2021
@@ -1,6 +1,11 @@
-/* $NetBSD: opt_c.c,v 1.1 2021/10/22 20:54:36 rillig Exp $ */
+/* $NetBSD: opt_c.c,v 1.2 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
+/*
+ * Tests for the option '-c', which specifies the column in which the comments
+ * to the right of the code start.
+ */
+
#indent input
bool
is_prime(int n)
@@ -24,3 +29,36 @@ is_prime(int n)
return true;
}
#indent end
+
+/*
+ * If the code is too wide to allow the comment in its preferred column, it is
+ * nevertheless indented with a single tab, to keep multiple comments
+ * vertically aligned.
+ */
+#indent run -c9
+bool
+is_prime(int n)
+{
+ if (n <= 3)
+ return n >= 2; /* special case */
+ if (n % 2 == 0)
+ return false; /* even numbers */
+ return true;
+}
+#indent end
+
+/*
+ * Usually, comments are aligned at a tabstop, but indent can also align them
+ * at any other column.
+ */
+#indent run -c37
+bool
+is_prime(int n)
+{
+ if (n <= 3)
+ return n >= 2; /* special case */
+ if (n % 2 == 0)
+ return false; /* even numbers */
+ return true;
+}
+#indent end
Index: src/tests/usr.bin/indent/opt_cd.c
diff -u src/tests/usr.bin/indent/opt_cd.c:1.1 src/tests/usr.bin/indent/opt_cd.c:1.2
--- src/tests/usr.bin/indent/opt_cd.c:1.1 Fri Oct 22 20:54:36 2021
+++ src/tests/usr.bin/indent/opt_cd.c Fri Nov 19 22:24:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_cd.c,v 1.1 2021/10/22 20:54:36 rillig Exp $ */
+/* $NetBSD: opt_cd.c,v 1.2 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
#indent input
@@ -8,3 +8,6 @@ int aflag; /* Apply to all files. */
#indent run -cd49
int aflag; /* Apply to all files. */
#indent end
+
+/* If '-cd' is not given, it falls back to '-c'. */
+#indent run-equals-prev-output -c49
Index: src/tests/usr.bin/indent/fmt_decl.c
diff -u src/tests/usr.bin/indent/fmt_decl.c:1.18 src/tests/usr.bin/indent/fmt_decl.c:1.19
--- src/tests/usr.bin/indent/fmt_decl.c:1.18 Fri Nov 19 19:37:13 2021
+++ src/tests/usr.bin/indent/fmt_decl.c Fri Nov 19 22:24:29 2021
@@ -1,10 +1,22 @@
-/* $NetBSD: fmt_decl.c,v 1.18 2021/11/19 19:37:13 rillig Exp $ */
+/* $NetBSD: fmt_decl.c,v 1.19 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD: head/usr.bin/indent/tests/declarations.0 334478 2018-06-01 09:41:15Z pstef $ */
+/*
+ * Tests for declarations of global variables, external functions, and local
+ * variables.
+ *
+ * See also:
+ * opt_di.c
+ */
+
/* See FreeBSD r303570 */
+/*
+ * A type definition usually declares a single type, so there is no need to
+ * align the newly declared type name with the other variables.
+ */
#indent input
-typedef void (*voidptr) (int *);
+typedef void ( * voidptr ) ( int * ) ;
#indent end
#indent run
@@ -12,6 +24,22 @@ typedef void (*voidptr)(int *);
#indent end
+/*
+ * In variable declarations, the names of the first declarators are indented
+ * by the amount given in '-di', which defaults to 16.
+ */
+#indent input
+extern void ( * function_pointer ) ( int * ) ;
+extern void * pointer;
+#indent end
+
+#indent run
+/* $ XXX: Why is the token 'function_pointer' not aligned with 'pointer'? */
+extern void (*function_pointer)(int *);
+extern void *pointer;
+#indent end
+
+
#indent input
static const struct
{
@@ -108,6 +136,7 @@ t1(char *a, int b,
#indent end
+/* See opt_bc.c. */
#indent input
void t2 (char *x, int y)
{
@@ -214,13 +243,13 @@ print_error(const char *fmt, ...)
/* See FreeBSD r309380 */
#indent input
static LIST_HEAD(, alq) ald_active;
-static int ald_shutingdown = 0;
+static int ald_shutting_down = 0;
struct thread *ald_thread;
#indent end
#indent run
static LIST_HEAD(, alq) ald_active;
-static int ald_shutingdown = 0;
+static int ald_shutting_down = 0;
struct thread *ald_thread;
#indent end
Index: src/tests/usr.bin/indent/indent_off_on.c
diff -u src/tests/usr.bin/indent/indent_off_on.c:1.3 src/tests/usr.bin/indent/indent_off_on.c:1.4
--- src/tests/usr.bin/indent/indent_off_on.c:1.3 Tue Oct 19 21:21:07 2021
+++ src/tests/usr.bin/indent/indent_off_on.c Fri Nov 19 22:24:29 2021
@@ -1,9 +1,10 @@
-/* $NetBSD: indent_off_on.c,v 1.3 2021/10/19 21:21:07 rillig Exp $ */
+/* $NetBSD: indent_off_on.c,v 1.4 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
* Tests for the comments 'INDENT OFF' and 'INDENT ON', which temporarily
- * disable formatting.
+ * disable formatting, copying the input directly to the output. Internally,
+ * indent still keeps track of the number of braces and other indentation.
*/
#indent input
@@ -116,16 +117,16 @@ int decl;
* between the two words.
*/
#indent input
-int decl;
+int decl ;
/* INDENT OFF */
int decl ;
/* INDENT ON */
-int decl;
+int decl ;
#indent end
/*
* XXX: It is asymmetric that 'INDENT OFF' is indented, while 'INDENT ON'
- * is aligned.
+ * is pushed to the start of the line.
*/
#indent run -di0
int decl;
@@ -213,3 +214,50 @@ indent_still_on(void); /* due to the co
void
indent_still_on(void); /* due to the extra comment to the right */
#indent end
+
+
+/*
+ * Try to confuse indent by having a string literal that has an embedded
+ * INDENT comment. Indent doesn't get confused though because it requires the
+ * INDENT comment to go from the very beginning of the line to the very end of
+ * the line.
+ */
+#indent input
+const char *str = "\
+/* INDENT OFF */\
+" , ch;
+#indent end
+
+#indent run
+const char *str = "\
+/* INDENT OFF */\
+", ch;
+#indent end
+
+
+/*
+ * The keywords in the INDENT comments must all be uppercase.
+ */
+#indent input
+int on ;
+/* indent off */
+int still_on ;
+/* INDENT off */
+int still_on ;
+/* indent OFF */
+int still_on ;
+/* INDENT OFF */
+int finally_off ;
+#indent end
+
+#indent run -di0
+int on;
+/* indent off */
+int still_on;
+/* INDENT off */
+int still_on;
+/* indent OFF */
+int still_on;
+/* INDENT OFF */
+int finally_off ;
+#indent end
Index: src/tests/usr.bin/indent/opt_bap.c
diff -u src/tests/usr.bin/indent/opt_bap.c:1.3 src/tests/usr.bin/indent/opt_bap.c:1.4
--- src/tests/usr.bin/indent/opt_bap.c:1.3 Mon Oct 18 07:11:31 2021
+++ src/tests/usr.bin/indent/opt_bap.c Fri Nov 19 22:24:29 2021
@@ -1,12 +1,16 @@
-/* $NetBSD: opt_bap.c,v 1.3 2021/10/18 07:11:31 rillig Exp $ */
+/* $NetBSD: opt_bap.c,v 1.4 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
- * Tests for the options '-bap' and '-nbap'.
+ * Tests for the options '-bap' and '-nbap' ("blank line after procedure
+ * body").
*
* The option '-bap' forces a blank line after every function body.
*
* The option '-nbap' keeps everything as is.
+ *
+ * FIXME: These options don't have any effect since at least 2000.
+ * TODO: Investigate how nobody could have noticed this for 20 years.
*/
#indent input
Index: src/tests/usr.bin/indent/opt_bbb.c
diff -u src/tests/usr.bin/indent/opt_bbb.c:1.3 src/tests/usr.bin/indent/opt_bbb.c:1.4
--- src/tests/usr.bin/indent/opt_bbb.c:1.3 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_bbb.c Fri Nov 19 22:24:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bbb.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_bbb.c,v 1.4 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -21,11 +21,11 @@
/*
* Documentation of global_variable.
*/
-int global_variable;
+int global_variable;
/*
* Documentation of function_declaration.
*/
-void function_declaration(void);
+void function_declaration(void);
/*
* Documentation of function_definition.
*/
@@ -65,28 +65,4 @@ function_definition(void)
}
#indent end
-#indent run -nbbb
-/*
- * This is a block comment.
- */
-/* This is not a block comment since it is single-line. */
-/*
- * This is a second block comment.
- */
-/* This is not a block comment. */
-/*
- * Documentation of global_variable.
- */
-int global_variable;
-/*
- * Documentation of function_declaration.
- */
-void function_declaration(void);
-/*
- * Documentation of function_definition.
- */
-void
-function_definition(void)
-{
-}
-#indent end
+#indent run-equals-input -nbbb
Index: src/tests/usr.bin/indent/opt_bc.c
diff -u src/tests/usr.bin/indent/opt_bc.c:1.3 src/tests/usr.bin/indent/opt_bc.c:1.4
--- src/tests/usr.bin/indent/opt_bc.c:1.3 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_bc.c Fri Nov 19 22:24:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bc.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_bc.c,v 1.4 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -6,12 +6,17 @@
*
* The option '-bc' forces a newline after each comma in a declaration.
*
- * The option '-nbc' keeps everything as is.
+ * The option '-nbc' removes line breaks between declarators. In most other
+ * places, indent preserves line breaks.
*/
#indent input
int a,b,c;
void function_declaration(int a,int b,int c);
+int m1,
+m2,
+m3;
+char plain, *pointer;
#indent end
#indent run -bc
@@ -19,9 +24,43 @@ int a,
b,
c;
void function_declaration(int a, int b, int c);
+int m1,
+ m2,
+ m3;
+char plain,
+ *pointer;
#indent end
#indent run -nbc
int a, b, c;
void function_declaration(int a, int b, int c);
+int m1, m2, m3;
+char plain, *pointer;
+#indent end
+
+
+#indent input
+old_style_definition(a, b, c)
+double a,b,c;
+{
+ return a+b+c;
+}
+#indent end
+
+#indent run -bc
+old_style_definition(a, b, c)
+double a,
+ b,
+ c;
+{
+ return a + b + c;
+}
+#indent end
+
+#indent run -nbc
+old_style_definition(a, b, c)
+double a, b, c;
+{
+ return a + b + c;
+}
#indent end
Index: src/tests/usr.bin/indent/lex_ident.c
diff -u src/tests/usr.bin/indent/lex_ident.c:1.2 src/tests/usr.bin/indent/lex_ident.c:1.3
--- src/tests/usr.bin/indent/lex_ident.c:1.2 Sun Oct 31 19:13:41 2021
+++ src/tests/usr.bin/indent/lex_ident.c Fri Nov 19 22:24:29 2021
@@ -1,8 +1,9 @@
-/* $NetBSD: lex_ident.c,v 1.2 2021/10/31 19:13:41 rillig Exp $ */
+/* $NetBSD: lex_ident.c,v 1.3 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
- * Test lexing of tokens, such as keywords, identifiers, operators.
+ * Test lexing of word-like tokens, such as keywords, identifiers, numeric
+ * constants, character constants, string literals.
*/
/*
Index: src/tests/usr.bin/indent/opt_bl_br.c
diff -u src/tests/usr.bin/indent/opt_bl_br.c:1.2 src/tests/usr.bin/indent/opt_bl_br.c:1.3
--- src/tests/usr.bin/indent/opt_bl_br.c:1.2 Sun Nov 7 19:18:56 2021
+++ src/tests/usr.bin/indent/opt_bl_br.c Fri Nov 19 22:24:29 2021
@@ -1,14 +1,10 @@
-/* $NetBSD: opt_bl_br.c,v 1.2 2021/11/07 19:18:56 rillig Exp $ */
+/* $NetBSD: opt_bl_br.c,v 1.3 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
#indent input
void
example(int n)
{
- /*
- * XXX: The '} else' looks strange in this style since the 'else' is
- * not at the left margin of the code.
- */
if (n > 99) { print("large"); }
else if (n > 9) { print("double-digit"); }
else if (n > 0) print("positive");
@@ -16,14 +12,14 @@ example(int n)
}
#indent end
+/*
+ * XXX: The '} else' looks strange in this style since the 'else' is
+ * not at the left margin of the code.
+ */
#indent run -bl
void
example(int n)
{
- /*
- * XXX: The '} else' looks strange in this style since the 'else' is
- * not at the left margin of the code.
- */
if (n > 99)
{
print("large");
@@ -39,17 +35,6 @@ example(int n)
}
#indent end
-#indent input
-void
-example(int n)
-{
- if (n > 99) { print("large"); }
- else if (n > 9) { print("double-digit"); }
- else if (n > 0) print("positive");
- else { print("negative"); }
-}
-#indent end
-
#indent run -br
void
example(int n)
@@ -68,7 +53,7 @@ example(int n)
/*
- * Test C99 comments after 'if (expr)', which is handled by search_stmt.
+ * Test C99 comments after 'if (expr)', which are handled by search_stmt.
*/
#indent input
void function(void)
@@ -121,3 +106,35 @@ function(void)
stmt();
}
#indent end
+
+
+/*
+ *
+ */
+#indent input
+void
+function(void)
+{
+ if (cond)
+ {
+ stmt();
+ }
+ else
+ if (cond)
+ {
+ stmt();
+ }
+}
+#indent end
+
+#indent run -br
+void
+function(void)
+{
+ if (cond) {
+ stmt();
+ } else if (cond) {
+ stmt();
+ }
+}
+#indent end
Index: src/tests/usr.bin/indent/opt_bacc.c
diff -u src/tests/usr.bin/indent/opt_bacc.c:1.5 src/tests/usr.bin/indent/opt_bacc.c:1.6
--- src/tests/usr.bin/indent/opt_bacc.c:1.5 Fri Nov 19 19:37:13 2021
+++ src/tests/usr.bin/indent/opt_bacc.c Fri Nov 19 22:24:29 2021
@@ -1,8 +1,9 @@
-/* $NetBSD: opt_bacc.c,v 1.5 2021/11/19 19:37:13 rillig Exp $ */
+/* $NetBSD: opt_bacc.c,v 1.6 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
- * Test the options '-bacc' and '-nbacc'.
+ * Tests for the options '-bacc' and '-nbacc' ("blank line around conditional
+ * compilation").
*
* The option '-bacc' forces a blank line around every conditional compilation
* block. For example, in front of every #ifdef and after every #endif.
@@ -22,8 +23,8 @@ int c;
#indent end
/*
- * XXX: As of 2021-10-05, the option -bacc has no effect on declarations since
- * process_decl resets blank_line_before unconditionally.
+ * XXX: As of 2021-11-19, the option -bacc has no effect on declarations since
+ * process_type resets blank_line_before unconditionally.
*/
#indent run -bacc
int a;
@@ -70,6 +71,7 @@ int space_c;
/* The option '-nbacc' does not remove anything. */
#indent run-equals-input -nbacc
+
/*
* Preprocessing directives can also occur in function bodies.
*/
@@ -104,3 +106,44 @@ os_name(void)
#indent end
#indent run-equals-input -nbacc
+
+
+/*
+ * Test nested preprocessor directives.
+ */
+#indent input
+#if outer
+#if inner
+int decl;
+#endif
+#endif
+#indent end
+
+#indent run -di0 -bacc
+#if outer
+
+#if inner
+int decl;
+#endif
+
+#endif
+#indent end
+
+#indent run-equals-input -di0 -nbacc
+
+
+/*
+ * Test nested preprocessor directives that are interleaved with declarations.
+ */
+#indent input
+#ifdef outer
+int outer_above;
+#ifdef inner
+int inner;
+#endif
+int outer_below;
+#endif
+#indent end
+
+#indent run-equals-input -di0 -bacc
+#indent run-equals-input -di0 -nbacc
Index: src/tests/usr.bin/indent/opt_bs.c
diff -u src/tests/usr.bin/indent/opt_bs.c:1.5 src/tests/usr.bin/indent/opt_bs.c:1.6
--- src/tests/usr.bin/indent/opt_bs.c:1.5 Tue Oct 26 20:37:26 2021
+++ src/tests/usr.bin/indent/opt_bs.c Fri Nov 19 22:24:29 2021
@@ -1,13 +1,13 @@
-/* $NetBSD: opt_bs.c,v 1.5 2021/10/26 20:37:26 rillig Exp $ */
+/* $NetBSD: opt_bs.c,v 1.6 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
- * Tests for the options '-bs' and '-nbs'.
+ * Tests for the options '-bs' and '-nbs' ("blank after sizeof").
*
* The option '-bs' forces a space after the keyword 'sizeof'.
*
- * The option '-nbs' removes all whitespace after the keyword 'sizeof', unless
- * the next token is a word as well.
+ * The option '-nbs' removes horizontal whitespace after the keyword 'sizeof',
+ * unless the next token is a word as well.
*/
#indent input
Index: src/tests/usr.bin/indent/opt_badp.c
diff -u src/tests/usr.bin/indent/opt_badp.c:1.4 src/tests/usr.bin/indent/opt_badp.c:1.5
--- src/tests/usr.bin/indent/opt_badp.c:1.4 Mon Oct 18 07:11:31 2021
+++ src/tests/usr.bin/indent/opt_badp.c Fri Nov 19 22:24:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_badp.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
+/* $NetBSD: opt_badp.c,v 1.5 2021/11/19 22:24:29 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -9,71 +9,105 @@
*/
#indent input
-static void
-no_declarations(void)
+void
+empty_body(void)
{
- action();
}
+#indent end
-static void
-declarations_without_blank_line(void)
-{
- int local_variable;
- action();
-}
+#indent run-equals-input -badp
+#indent run-equals-input -nbadp
-static void
-declaration_with_blank_line(void)
+
+#indent input
+void
+empty_line(void)
{
- int local_variable;
- action();
}
+#indent end
-static void
-declaration_with_several_blank_lines(void)
+#indent run-equals-input -badp
+#indent run-equals-input -nbadp
+
+
+#indent input
+void
+only_declaration(void)
{
- int local_variable;
+ int decl;
+}
+#indent end
+#indent run-equals-input -badp
+#indent run-equals-input -nbadp
- action();
+#indent input
+void
+only_statement(void)
+{
+ stmt();
}
#indent end
#indent run -badp
-static void
-no_declarations(void)
+void
+only_statement(void)
{
- action();
+ stmt();
}
+#indent end
+#indent run-equals-input -nbadp
-static void
-declarations_without_blank_line(void)
+
+#indent input
+void
+declaration_and_statement(void)
{
- int local_variable;
- /* $ FIXME: need empty line here */
- action();
+ int decl;
+ stmt();
}
+#indent end
+#indent run -badp
+void
+declaration_and_statement(void)
+{
+ int decl;
+ /* $ FIXME: missing empty line */
+ stmt();
+}
+#indent end
+#indent run-equals-input -nbadp
+
+
+#indent input
static void
-declaration_with_blank_line(void)
+declaration_blank_statement(void)
{
- int local_variable;
+ int decl;
- action();
+ stmt();
}
+#indent end
+
+#indent run-equals-input -badp
+#indent run-equals-input -nbadp
+
+#indent input
static void
-declaration_with_several_blank_lines(void)
+declaration_blank_blank_statement(void)
{
- int local_variable;
+ int decl;
- action();
+ stmt();
}
#indent end
-#indent run-equals-input -nbadp -ldi0
+#indent run-equals-input -badp
+#indent run-equals-input -nbadp
Index: src/tests/usr.bin/indent/t_misc.sh
diff -u src/tests/usr.bin/indent/t_misc.sh:1.15 src/tests/usr.bin/indent/t_misc.sh:1.16
--- src/tests/usr.bin/indent/t_misc.sh:1.15 Sun Nov 7 19:18:56 2021
+++ src/tests/usr.bin/indent/t_misc.sh Fri Nov 19 22:24:29 2021
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: t_misc.sh,v 1.15 2021/11/07 19:18:56 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.16 2021/11/19 22:24:29 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -364,6 +364,25 @@ several_profiles_body()
"$indent" -Pnonexistent.pro -Perror.pro -Plast.pro code.c -st
}
+
+atf_test_case 'command_line_vs_profile'
+command_line_vs_profile_body()
+{
+ # Options from the command line override those from a profile file,
+ # no matter if they appear earlier or later than the '-P' in the
+ # command line.
+
+ echo ' -di24' > custom.pro
+ printf 'int\t\tdecl;\n' > code.c
+
+ atf_check -o 'inline:int decl;\n' \
+ "$indent" -di0 -Pcustom.pro code.c -st
+ atf_check -o 'inline:int decl;\n' \
+ "$indent" -Pcustom.pro -di0 code.c -st
+ atf_check -o 'inline:int decl;\n' \
+ "$indent" -Pcustom.pro code.c -st -di0
+}
+
atf_init_test_cases()
{
atf_add_test_case 'in_place'
@@ -377,4 +396,5 @@ atf_init_test_cases()
atf_add_test_case 'line_no_counting'
atf_add_test_case 'default_backup_extension'
atf_add_test_case 'several_profiles'
+ atf_add_test_case 'command_line_vs_profile'
}