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: demonstrate several real-...



details:   https://anonhg.NetBSD.org/src/rev/1c012bc37a15
branches:  trunk
changeset: 1026428:1c012bc37a15
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Nov 24 21:34:34 2021 +0000

description:
tests/indent: demonstrate several real-life formatting bugs

Collected by indenting usr.bin/make with the default profile.

The heuristic for distinguishing between type names and other
identifiers is way too primitive, it seems to have stopped evolving
somewhere before function prototypes were standardized in C90, at least
it handles function prototypes poorly.

indent-2014.09.04.04.06.07 added seemingly random spaces to
declarations, which were fixed in indent-2019.04.04.15.27.35, which came
5 years later. The latter commit introduced many new bugs, but it also
fixed this one.

The wrongly indented struct member declaration for HashTable has been
there since at least indent-2000.10.11.14.46.04.

The wrongly indented initializer expression was added in
indent-2019.04.04.15.27.35 (see above).

diffstat:

 tests/usr.bin/indent/fmt_decl.c        |  208 ++++++++++++++++++++++++++++++++-
 tests/usr.bin/indent/lsym_case_label.c |   40 ++++++-
 2 files changed, 246 insertions(+), 2 deletions(-)

diffs (270 lines):

diff -r 84233fa14a1a -r 1c012bc37a15 tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c   Wed Nov 24 18:57:24 2021 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c   Wed Nov 24 21:34:34 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fmt_decl.c,v 1.22 2021/11/21 11:02:25 rillig Exp $     */
+/*     $NetBSD: fmt_decl.c,v 1.23 2021/11/24 21:34:34 rillig Exp $     */
 /* $FreeBSD: head/usr.bin/indent/tests/declarations.0 334478 2018-06-01 09:41:15Z pstef $ */
 
 /*
@@ -571,3 +571,209 @@
        *buf->e++ = ch;
 }
 #indent end
+
+
+/*
+ * Indent gets easily confused by type names it does not know about.
+ */
+#indent input
+static Token
+ToToken(bool cond)
+{
+}
+#indent end
+
+#indent run
+static Token
+/* $ FIXME: missing space between ')' and '{'. */
+ToToken(bool cond){
+}
+#indent end
+
+#indent run-equals-input -TToken
+
+
+/*
+ * Indent gets easily confused by unknown type names in struct declarations.
+ */
+#indent input
+typedef struct OpenDirs {
+       CachedDirList   list;
+       HashTable /* of CachedDirListNode */ table;
+}              OpenDirs;
+#indent end
+
+/* FIXME: The word 'HashTable' must not be aligned like a member name. */
+#indent run
+typedef struct OpenDirs {
+       CachedDirList   list;
+                       HashTable /* of CachedDirListNode */ table;
+}              OpenDirs;
+#indent end
+
+#indent run-equals-input -THashTable
+
+
+/*
+ * Indent gets easily confused by unknown type names, even in declarations
+ * that are syntactically unambiguous.
+ */
+#indent input
+static CachedDir *dot = NULL;
+#indent end
+
+/* FIXME: The space after '*' is wrong. */
+#indent run
+static CachedDir * dot = NULL;
+#indent end
+
+#indent run-equals-input -TCachedDir
+
+
+/*
+ * Indent gets easily confused by unknown type names in declarations.
+ */
+#indent input
+static CachedDir *
+CachedDir_New(const char *name)
+{
+}
+#indent end
+
+/* FIXME: The space between '){' is missing. */
+/* FIXME: The '{' must be in column 1 of the next line. */
+#indent run
+static CachedDir *
+CachedDir_New(const char *name){
+}
+#indent end
+
+
+/*
+ * Indent gets easily confused by unknown type names in function declarations.
+ */
+#indent input
+static CachedDir *
+CachedDir_Ref(CachedDir *dir)
+{
+}
+#indent end
+
+/* FIXME: Extraneous ' ' between '*' and 'dir'. */
+/* FIXME: The '{' must be in column 1 of the next line. */
+#indent run
+static CachedDir *
+CachedDir_Ref(CachedDir * dir) {
+}
+#indent end
+
+
+/*
+ * In some cases, indent does not get confused by unknown type names. At least
+ * it gets the placement of the '{' correct in this example.
+ */
+#indent input
+static bool
+HashEntry_KeyEquals(const HashEntry *he, Substring key)
+{
+}
+#indent end
+
+#indent run
+static bool
+HashEntry_KeyEquals(const HashEntry * he, Substring key)
+{
+}
+#indent end
+
+
+/*
+ * Indent doesn't notice that the two '*' are in a declaration, instead it
+ * interprets the first '*' as a binary operator.
+ */
+#indent input
+static void
+CachedDir_Assign(CachedDir **var, CachedDir *dir)
+{
+}
+#indent end
+
+/* FIXME: Extraneous space between '*' and '*'. */
+#indent run
+static void
+CachedDir_Assign(CachedDir * *var, CachedDir * dir)
+{
+}
+#indent end
+
+#indent run-equals-input -TCachedDir
+
+
+/*
+ * All initializer expressions after the first one are indented as if they
+ * would be statement continuations. Maybe the comma is interpreted as a
+ * binary operator instead of being a separator.
+ */
+#indent input
+static Shell shells[] = {
+       {
+               first,
+               second,
+       },
+};
+#indent end
+
+#indent run
+static Shell shells[] = {
+       {
+               first,
+/* $ FIXME: The identifier 'second' gets indented too far. */
+                       second,
+       },
+};
+#indent end
+
+
+/*
+ * Indent gets easily confused by function attribute macros that follow the
+ * function declaration.
+ */
+#indent input
+static void JobInterrupt(bool, int) MAKE_ATTR_DEAD;
+static void JobRestartJobs(void);
+#indent end
+
+#indent run
+/* $ FIXME: This is a declaration, not a definition, thus no line break before the name. */
+/* $ FIXME: Missing space before 'MAKE_ATTR_DEAD'. */
+static void
+JobInterrupt(bool, int)MAKE_ATTR_DEAD;
+/* $ FIXME: Must not be indented. */
+       static void     JobRestartJobs(void);
+#indent end
+
+
+/*
+ * Indent gets easily confused by function modifier macros.
+ */
+#indent input
+MAKE_INLINE const char *
+GNode_VarTarget(GNode *gn) { return GNode_ValueDirect(gn, TARGET); }
+#indent end
+
+/* FIXME: The function name must be in column 1 of a separate line. */
+/* FIXME: The '{' must be in column 1 of the next line. */
+/* FIXME: The '*' before 'gn' is extraneous. */
+/* FIXME: The indentation depends on the function body; try 'return 0'. */
+#indent run
+MAKE_INLINE const char *GNode_VarTarget(GNode * gn) {
+       return GNode_ValueDirect(gn, TARGET);
+}
+#indent end
+
+/* FIXME: Missing space between '*' and 'gn'. */
+#indent run -TGNode
+MAKE_INLINE const char *GNode_VarTarget(GNode *gn){
+       return GNode_ValueDirect(gn, TARGET);
+}
+#indent end
diff -r 84233fa14a1a -r 1c012bc37a15 tests/usr.bin/indent/lsym_case_label.c
--- a/tests/usr.bin/indent/lsym_case_label.c    Wed Nov 24 18:57:24 2021 +0000
+++ b/tests/usr.bin/indent/lsym_case_label.c    Wed Nov 24 21:34:34 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_case_label.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */
+/* $NetBSD: lsym_case_label.c,v 1.3 2021/11/24 21:34:34 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -21,3 +21,41 @@
 #indent end
 
 #indent run-equals-input
+
+
+/*
+ * If there is a '{' after a case label, it gets indented using tabs instead
+ * of spaces. Indent does not necessarily insert a space in this situation,
+ * which looks strange.
+ */
+#indent input
+void
+function(void)
+{
+       switch (expr) {
+       case 1: {
+               break;
+       }
+       case 11: {
+               break;
+       }
+       }
+}
+#indent end
+
+#indent run
+void
+function(void)
+{
+       switch (expr) {
+       /* $ The space between the ':' and the '{' is actually a tab. */
+       case 1: {
+                       break;
+               }
+       /* $ FIXME: missing space between ':' and '{'. */
+       case 11:{
+                       break;
+               }
+       }
+}
+#indent end



Home | Main Index | Thread Index | Old Index