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: refine and extend tests



details:   https://anonhg.NetBSD.org/src/rev/21cac150b9ae
branches:  trunk
changeset: 1026346:21cac150b9ae
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Nov 19 22:24:29 2021 +0000

description:
tests/indent: refine and extend tests

diffstat:

 tests/usr.bin/indent/fmt_block.c        |   51 ++++++++++++++-
 tests/usr.bin/indent/fmt_decl.c         |   37 +++++++++-
 tests/usr.bin/indent/fmt_else_comment.c |   52 ++++++++++----
 tests/usr.bin/indent/fmt_expr.c         |    8 +-
 tests/usr.bin/indent/indent_off_on.c    |   58 +++++++++++++++-
 tests/usr.bin/indent/lex_char.c         |    6 +-
 tests/usr.bin/indent/lex_ident.c        |    5 +-
 tests/usr.bin/indent/lex_string.c       |    7 +-
 tests/usr.bin/indent/lsym_offsetof.c    |   13 +++-
 tests/usr.bin/indent/opt_P.c            |    8 +-
 tests/usr.bin/indent/opt_T.c            |   44 +++++++-----
 tests/usr.bin/indent/opt_bacc.c         |   51 +++++++++++++-
 tests/usr.bin/indent/opt_badp.c         |  112 ++++++++++++++++++++-----------
 tests/usr.bin/indent/opt_bap.c          |    8 +-
 tests/usr.bin/indent/opt_bap_sob.c      |   32 ++++++++-
 tests/usr.bin/indent/opt_bbb.c          |   32 +--------
 tests/usr.bin/indent/opt_bc.c           |   43 +++++++++++-
 tests/usr.bin/indent/opt_bl_br.c        |   59 ++++++++++------
 tests/usr.bin/indent/opt_bs.c           |    8 +-
 tests/usr.bin/indent/opt_c.c            |   40 +++++++++++-
 tests/usr.bin/indent/opt_cd.c           |    5 +-
 tests/usr.bin/indent/t_misc.sh          |   22 ++++++-
 22 files changed, 538 insertions(+), 163 deletions(-)

diffs (truncated from 1163 to 300 lines):

diff -r 55d6e2a9e091 -r 21cac150b9ae tests/usr.bin/indent/fmt_block.c
--- a/tests/usr.bin/indent/fmt_block.c  Fri Nov 19 20:23:17 2021 +0000
+++ b/tests/usr.bin/indent/fmt_block.c  Fri Nov 19 22:24:29 2021 +0000
@@ -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 @@
        }
 }
 #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
diff -r 55d6e2a9e091 -r 21cac150b9ae tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c   Fri Nov 19 20:23:17 2021 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c   Fri Nov 19 22:24:29 2021 +0000
@@ -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 @@
 #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 @@
 #indent end
 
 
+/* See opt_bc.c. */
 #indent input
 void t2 (char *x, int y)
 {
@@ -214,13 +243,13 @@
 /* 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
 
diff -r 55d6e2a9e091 -r 21cac150b9ae tests/usr.bin/indent/fmt_else_comment.c
--- a/tests/usr.bin/indent/fmt_else_comment.c   Fri Nov 19 20:23:17 2021 +0000
+++ b/tests/usr.bin/indent/fmt_else_comment.c   Fri Nov 19 22:24:29 2021 +0000
@@ -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)
 {
-       /* 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)
        {
 
diff -r 55d6e2a9e091 -r 21cac150b9ae tests/usr.bin/indent/fmt_expr.c
--- a/tests/usr.bin/indent/fmt_expr.c   Fri Nov 19 20:23:17 2021 +0000
+++ b/tests/usr.bin/indent/fmt_expr.c   Fri Nov 19 22:24:29 2021 +0000
@@ -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);
diff -r 55d6e2a9e091 -r 21cac150b9ae tests/usr.bin/indent/indent_off_on.c
--- a/tests/usr.bin/indent/indent_off_on.c      Fri Nov 19 20:23:17 2021 +0000
+++ b/tests/usr.bin/indent/indent_off_on.c      Fri Nov 19 22:24:29 2021 +0000
@@ -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 @@
  * 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 @@
 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
+



Home | Main Index | Thread Index | Old Index