Module Name: src
Committed By: rillig
Date: Mon Oct 18 07:11:31 UTC 2021
Modified Files:
src/tests/usr.bin/indent: opt_bacc.c opt_bad.c opt_badp.c opt_bap.c
opt_cdb.c opt_dj.c opt_eei.c opt_ei.c opt_fc1.c opt_fcb.c opt_ip.c
opt_lpl.c opt_psl.c opt_sc.c t_options.sh
Log Message:
tests/indent: merge duplicate input/output and output/output
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/opt_bacc.c \
src/tests/usr.bin/indent/opt_bad.c src/tests/usr.bin/indent/opt_bap.c \
src/tests/usr.bin/indent/opt_dj.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/opt_badp.c \
src/tests/usr.bin/indent/opt_cdb.c src/tests/usr.bin/indent/opt_eei.c \
src/tests/usr.bin/indent/opt_ei.c src/tests/usr.bin/indent/opt_fc1.c \
src/tests/usr.bin/indent/opt_fcb.c src/tests/usr.bin/indent/opt_ip.c \
src/tests/usr.bin/indent/opt_lpl.c src/tests/usr.bin/indent/opt_psl.c \
src/tests/usr.bin/indent/opt_sc.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/t_options.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/opt_bacc.c
diff -u src/tests/usr.bin/indent/opt_bacc.c:1.2 src/tests/usr.bin/indent/opt_bacc.c:1.3
--- src/tests/usr.bin/indent/opt_bacc.c:1.2 Sat Oct 16 06:02:18 2021
+++ src/tests/usr.bin/indent/opt_bacc.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bacc.c,v 1.2 2021/10/16 06:02:18 rillig Exp $ */
+/* $NetBSD: opt_bacc.c,v 1.3 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -39,13 +39,7 @@ int c;
* With '-nbacc' the code is unchanged since there are no blank lines to
* remove.
*/
-#indent run -nbacc
-int a;
-#if 0
-int b;
-#endif
-int c;
-#indent end
+#indent run-equals-input -nbacc
/* Example code containing blank lines. */
@@ -74,17 +68,7 @@ int space_c;
#indent end
/* The option '-nbacc' does not remove anything. */
-#indent run -nbacc
-int space_a;
-
-#if 0
-
-int space_b;
-
-#endif
-
-int space_c;
-#indent end
+#indent run-equals-input -nbacc
/*
* Preprocessing directives can also occur in function bodies.
Index: src/tests/usr.bin/indent/opt_bad.c
diff -u src/tests/usr.bin/indent/opt_bad.c:1.2 src/tests/usr.bin/indent/opt_bad.c:1.3
--- src/tests/usr.bin/indent/opt_bad.c:1.2 Sat Oct 16 09:39:21 2021
+++ src/tests/usr.bin/indent/opt_bad.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bad.c,v 1.2 2021/10/16 09:39:21 rillig Exp $ */
+/* $NetBSD: opt_bad.c,v 1.3 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -28,13 +28,7 @@ void function_declaration(void);
/* comment */
#indent end
-#indent run -nbad
-int global_variable;
-void function_declaration(void);
-#if 0
-#endif
-/* comment */
-#indent end
+#indent run-equals-prev-output -nbad
/* Test local declarations. */
#indent input
Index: src/tests/usr.bin/indent/opt_bap.c
diff -u src/tests/usr.bin/indent/opt_bap.c:1.2 src/tests/usr.bin/indent/opt_bap.c:1.3
--- src/tests/usr.bin/indent/opt_bap.c:1.2 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_bap.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bap.c,v 1.2 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_bap.c,v 1.3 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -65,33 +65,4 @@ has_several_blank_lines_below(void)
int the_end;
#indent end
-#indent run -nbap
-static void
-one_liner(void)
-{
-}
-static void
-several_lines(void)
-{
- action();
-}
-int
-main(void)
-{
-}
-int global_variable;
-
-void
-already_has_blank_line_below(void)
-{
-}
-
-void
-has_several_blank_lines_below(void)
-{
-}
-
-
-
-int the_end;
-#indent end
+#indent run-equals-prev-output -nbap
Index: src/tests/usr.bin/indent/opt_dj.c
diff -u src/tests/usr.bin/indent/opt_dj.c:1.2 src/tests/usr.bin/indent/opt_dj.c:1.3
--- src/tests/usr.bin/indent/opt_dj.c:1.2 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_dj.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_dj.c,v 1.2 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_dj.c,v 1.3 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -28,14 +28,7 @@ const void ******vpppppp;
const void ********vpppppppp;
#indent end
-#indent run -ndj
-int i;
-int *ip;
-const char *ccp;
-const void *****vppppp;
-const void ******vpppppp;
-const void ********vpppppppp;
-#indent end
+#indent run-equals-prev-output -ndj
#indent input
void example(void) {
Index: src/tests/usr.bin/indent/opt_badp.c
diff -u src/tests/usr.bin/indent/opt_badp.c:1.3 src/tests/usr.bin/indent/opt_badp.c:1.4
--- src/tests/usr.bin/indent/opt_badp.c:1.3 Sun Oct 17 17:20:47 2021
+++ src/tests/usr.bin/indent/opt_badp.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_badp.c,v 1.3 2021/10/17 17:20:47 rillig Exp $ */
+/* $NetBSD: opt_badp.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -76,4 +76,4 @@ declaration_with_several_blank_lines(voi
}
#indent end
-#indent run-identity -nbadp -ldi0
+#indent run-equals-input -nbadp -ldi0
Index: src/tests/usr.bin/indent/opt_cdb.c
diff -u src/tests/usr.bin/indent/opt_cdb.c:1.3 src/tests/usr.bin/indent/opt_cdb.c:1.4
--- src/tests/usr.bin/indent/opt_cdb.c:1.3 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_cdb.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_cdb.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_cdb.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -72,13 +72,7 @@ int gb; /* A multi-line comment. */
int gc; /* A multi-line comment. */
#indent end
-#indent run -ncdb
-int ga; /* A single-line comment. */
-
-int gb; /* A multi-line comment. */
-
-int gc; /* A multi-line comment. */
-#indent end
+#indent run-equals-prev-output -ncdb
/*
* Block comments that are inside a function.
Index: src/tests/usr.bin/indent/opt_eei.c
diff -u src/tests/usr.bin/indent/opt_eei.c:1.3 src/tests/usr.bin/indent/opt_eei.c:1.4
--- src/tests/usr.bin/indent/opt_eei.c:1.3 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_eei.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_eei.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_eei.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -40,19 +40,7 @@ less(int a, int b)
}
#indent end
-#indent run -neei
-bool
-less(int a, int b)
-{
- if (a <
- b)
- return true;
- if (a
- <
- b)
- return true;
-}
-#indent end
+#indent run-equals-input -neei
/*
* When the indentation level is the same as the continuation indentation, the
Index: src/tests/usr.bin/indent/opt_ei.c
diff -u src/tests/usr.bin/indent/opt_ei.c:1.3 src/tests/usr.bin/indent/opt_ei.c:1.4
--- src/tests/usr.bin/indent/opt_ei.c:1.3 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_ei.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_ei.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_ei.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -27,21 +27,7 @@ example(int n)
}
#indent end
-#indent run -ei
-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-equals-input -ei
#indent run -nei
void
Index: src/tests/usr.bin/indent/opt_fc1.c
diff -u src/tests/usr.bin/indent/opt_fc1.c:1.3 src/tests/usr.bin/indent/opt_fc1.c:1.4
--- src/tests/usr.bin/indent/opt_fc1.c:1.3 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_fc1.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_fc1.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_fc1.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -28,15 +28,7 @@
*/
#indent end
-#indent run -nfc1
-/*
- * A comment
- * in column 1.
- *
- *
- *
- */
-#indent end
+#indent run-equals-input -nfc1
#indent input
@@ -146,9 +138,4 @@
* second comment */
#indent end
-#indent run -nfc1
- /* comment */ int decl2; /* comment */
- /* looooooooooooooooooooooooooooooooooooooooong first comment */ int decl2; /* second comment */
- /* first comment */ int decl2; /* looooooooooooooooooooooooooooooooooooooooong
- * second comment */
-#indent end
+#indent run-equals-prev-output -nfc1
Index: src/tests/usr.bin/indent/opt_fcb.c
diff -u src/tests/usr.bin/indent/opt_fcb.c:1.3 src/tests/usr.bin/indent/opt_fcb.c:1.4
--- src/tests/usr.bin/indent/opt_fcb.c:1.3 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_fcb.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_fcb.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_fcb.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -40,19 +40,7 @@
*/
#indent end
-#indent run -nfcb
-/*
- * Not
- *
- * so carefully formatted comment
- */
-
-/*-
- * car mat men
- * efu for ted com t
- * lly box .
- */
-#indent end
+#indent run-equals-prev-output -nfcb
#indent input
@@ -91,20 +79,4 @@ example(void)
}
#indent end
-#indent run -nfcb
-void
-example(void)
-{
- /*
- * Not
- *
- * so carefully formatted comment
- */
-
- /*-
- * car mat men
- * efu for ted com t
- * lly box .
- */
-}
-#indent end
+#indent run-equals-prev-output -nfcb
Index: src/tests/usr.bin/indent/opt_ip.c
diff -u src/tests/usr.bin/indent/opt_ip.c:1.3 src/tests/usr.bin/indent/opt_ip.c:1.4
--- src/tests/usr.bin/indent/opt_ip.c:1.3 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_ip.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_ip.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_ip.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -49,21 +49,4 @@ several_parameters_3(
const char *cp);
#indent end
-#indent run -nip
-int
-several_parameters_1(int a,
- int b,
- const char *cp);
-
-int
-several_parameters_2(
- int a,
- int b,
- const char *cp);
-
-int
-several_parameters_3(
- int a1, int a2,
- int b1, int b2,
- const char *cp);
-#indent end
+#indent run-equals-prev-output -nip
Index: src/tests/usr.bin/indent/opt_lpl.c
diff -u src/tests/usr.bin/indent/opt_lpl.c:1.3 src/tests/usr.bin/indent/opt_lpl.c:1.4
--- src/tests/usr.bin/indent/opt_lpl.c:1.3 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_lpl.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_lpl.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_lpl.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -66,28 +66,4 @@ example(void)
}
#indent end
-#indent run -nlpl
-void
-example(void)
-{
- int sum1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21;
- int sum2 = (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21);
-
-/* $ XXX: There should be at least _some_ indentation for the */
-/* $ continuation lines. */
- int sum3 = 1 + 2 + 3 + 4 + 5 +
- 6 + 7 + 8 + 9 + 10 +
- 11 + 12 + 13 + 14 + 15 +
- 16 + 17 + 18 + 19 + 20 +
- 21;
- int sum4 = (1 + 2 + 3 + 4 + 5 +
- 6 + 7 + 8 + 9 + 10 +
- 11 + 12 + 13 + 14 + 15 +
- 16 + 17 + 18 + 19 + 20 +
- 21);
-
- call_function(call_function(call_function(call_function(call_function(call_function())))));
-
- call_function((call_function(call_function(call_function(call_function(call_function()))))));
-}
-#indent end
+#indent run-equals-prev-output -nlpl
Index: src/tests/usr.bin/indent/opt_psl.c
diff -u src/tests/usr.bin/indent/opt_psl.c:1.3 src/tests/usr.bin/indent/opt_psl.c:1.4
--- src/tests/usr.bin/indent/opt_psl.c:1.3 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_psl.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_psl.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_psl.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -20,9 +20,7 @@ void function_declaration(void);
void function_declaration(void);
#indent end
-#indent run -npsl
-void function_declaration(void);
-#indent end
+#indent run-equals-prev-output -npsl
/*
* Multi-line function declarations are affected by these options since indent
Index: src/tests/usr.bin/indent/opt_sc.c
diff -u src/tests/usr.bin/indent/opt_sc.c:1.3 src/tests/usr.bin/indent/opt_sc.c:1.4
--- src/tests/usr.bin/indent/opt_sc.c:1.3 Sat Oct 16 21:32:10 2021
+++ src/tests/usr.bin/indent/opt_sc.c Mon Oct 18 07:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_sc.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_sc.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -59,14 +59,6 @@ comment without asterisks
*/
#indent end
-#indent run -sc
-/**
- * Javadoc, adopted by several other programming languages.
- */
-#indent end
+#indent run-equals-input -sc
-#indent run -nsc
-/**
- * Javadoc, adopted by several other programming languages.
- */
-#indent end
+#indent run-equals-input -nsc
Index: src/tests/usr.bin/indent/t_options.sh
diff -u src/tests/usr.bin/indent/t_options.sh:1.4 src/tests/usr.bin/indent/t_options.sh:1.5
--- src/tests/usr.bin/indent/t_options.sh:1.4 Sun Oct 17 17:23:59 2021
+++ src/tests/usr.bin/indent/t_options.sh Mon Oct 18 07:11:31 2021
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: t_options.sh,v 1.4 2021/10/17 17:23:59 rillig Exp $
+# $NetBSD: t_options.sh,v 1.5 2021/10/18 07:11:31 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -40,10 +40,13 @@
# Runs indent on the input, using the given options.
# #indent end [description]
# Finishes an '#indent input' or '#indent run' section.
-# #indent run-identity [options]
+# #indent run-equals-input [options]
# Runs indent on the input, expecting unmodified output.
+# #indent run-equals-prev-output [options]
+# Runs indent on the input, expecting the same output as from
+# the previous run.
#
-# All text between these directives is not passed to indent.
+# All text outside these directives is not passed to indent.
srcdir=$(atf_get_srcdir)
indent=$(atf_config_get usr.bin.indent.test_indent /usr/bin/indent)
@@ -53,82 +56,122 @@ indent=$(atf_config_get usr.bin.indent.t
#
# shellcheck disable=SC2016
check_awk='
-function die(msg)
+function die(lineno, msg)
{
if (!died) {
died = 1
- print msg > "/dev/stderr"
+ print FILENAME ":" lineno ": error: " msg > "/dev/stderr"
exit(1)
}
}
-# Skip comments starting with dollar; they are used for marking bugs and
-# adding other remarks directly in the input or output sections.
+BEGIN {
+ section = "" # "", "input" or "run"
+ section_excl_comm = "" # without dollar comments
+ section_incl_comm = "" # with dollar comments
+
+ input_excl_comm = "" # stdin for indent
+ input_incl_comm = "" # used for duplicate checks
+ unused_input_lineno = 0
+
+ output_excl_comm = "" # expected output
+ output_incl_comm = "" # used for duplicate checks
+ output_lineno = 0
+}
+
+# Hide comments starting with dollar from indent; they are used for marking
+# bugs and adding other remarks directly in the input or output sections.
/^[[:space:]]*\/[*][[:space:]]*[$].*[*]\/$/ ||
/^[[:space:]]*\/\/[[:space:]]*[$]/ {
+ if (section != "")
+ section_incl_comm = section_incl_comm $0 "\n"
next
}
+function check_unused_input()
+{
+ if (unused_input_lineno != 0)
+ die(unused_input_lineno, "input is not used")
+}
+
+function run_indent(inp, i, cmd)
+{
+ cmd = ENVIRON["INDENT"]
+ for (i = 3; i <= NF; i++)
+ cmd = cmd " " $i
+ printf("%s", inp) | cmd
+ close(cmd)
+}
+
/^#/ && $1 == "#indent" {
print $0
print $0 > "expected.out"
if ($2 == "input") {
- if (unused != 0)
- die(FILENAME ":" unused ": input is not used")
- mode = "input"
- in_lines_len = 0
- prev_input_all = input_all
- input_all = ""
- unused = NR
+ section = "input"
+ section_excl_comm = ""
+ section_incl_comm = ""
+ unused_input_lineno = NR
} else if ($2 == "run") {
- mode = "run"
- cmd = ENVIRON["INDENT"]
- for (i = 3; i <= NF; i++)
- cmd = cmd " " $i
- for (i = 0; i < in_lines_len; i++)
- print in_lines[i] | cmd
- close(cmd)
- unused = 0
-
- } else if ($2 == "run-identity") {
- cmd = ENVIRON["INDENT"]
- for (i = 3; i <= NF; i++)
- cmd = cmd " " $i
- for (i = 0; i < in_lines_len; i++) {
- print in_lines[i] | cmd
- print in_lines[i] > "expected.out"
- }
- close(cmd)
- unused = 0
+ section = "run"
+ output_lineno = NR
+ section_excl_comm = ""
+ section_incl_comm = ""
+
+ run_indent(input_excl_comm)
+ unused_input_lineno = 0
+
+ } else if ($2 == "run-equals-input") {
+ run_indent(input_excl_comm)
+ printf("%s", input_excl_comm) > "expected.out"
+ unused_input_lineno = 0
+
+ } else if ($2 == "run-equals-prev-output") {
+ run_indent(input_excl_comm)
+ printf("%s", output_excl_comm) > "expected.out"
+ unused_input_lineno = 0
} else if ($2 == "end") {
- if (mode == "input" && input_all == prev_input_all)
- die(FILENAME ":" NR ": error: duplicate input")
- mode = ""
+ if (section == "input" && section_incl_comm == input_incl_comm)
+ die(NR, "duplicate input; remove this section")
+ if (section == "run" && section_incl_comm == input_incl_comm)
+ die(output_lineno,
+ "output == input; use run-equals-input")
+ if (section == "run" && section_incl_comm == output_incl_comm)
+ die(output_lineno,
+ "duplicate output; use run-equals-prev-output")
+
+ if (section == "input") {
+ input_excl_comm = section_excl_comm
+ input_incl_comm = section_incl_comm
+ }
+ if (section == "run") {
+ output_excl_comm = section_excl_comm
+ output_incl_comm = section_incl_comm
+ }
+ section = ""
} else {
- die(FILENAME ":" NR ": error: invalid line \"" $0 "\"")
+ die(NR, "invalid line \"" $0 "\"")
}
next
}
-mode == "input" {
- in_lines[in_lines_len++] = $0
- input_all = input_all $0 "\n"
+section == "input" || section == "run" {
+ section_excl_comm = section_excl_comm $0 "\n"
+ section_incl_comm = section_incl_comm $0 "\n"
}
-mode == "run" {
+section == "run" {
print $0 > "expected.out"
}
END {
- if (mode != "")
- die(FILENAME ":" NR ": still in mode \"" mode "\"")
- if (unused != 0)
- die(FILENAME ":" unused ": input is not used")
+ if (section != "")
+ die(NR, "still in section \"" section "\"")
+ check_unused_input()
}
'