Wed Jun 14 17:07:33 2023 UTC ()
tests/indent: separate stdout from stderr

Due to buffering, there was no guarantee that the output would be
exactly in the same order as written in the tests.


(rillig)
diff -r1.7 -r1.8 src/tests/usr.bin/indent/fmt_expr.c
diff -r1.12 -r1.13 src/tests/usr.bin/indent/lsym_preprocessing.c
diff -r1.5 -r1.6 src/tests/usr.bin/indent/psym_else.c
diff -r1.4 -r1.5 src/tests/usr.bin/indent/t_options.lua

cvs diff -r1.7 -r1.8 src/tests/usr.bin/indent/fmt_expr.c (expand / switch to unified diff)

--- src/tests/usr.bin/indent/fmt_expr.c 2023/06/10 08:17:04 1.7
+++ src/tests/usr.bin/indent/fmt_expr.c 2023/06/14 17:07:32 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fmt_expr.c,v 1.7 2023/06/10 08:17:04 rillig Exp $ */ 1/* $NetBSD: fmt_expr.c,v 1.8 2023/06/14 17:07:32 rillig Exp $ */
2 2
3/* 3/*
4 * Tests for all kinds of expressions that are not directly related to unary 4 * Tests for all kinds of expressions that are not directly related to unary
5 * or binary operators. 5 * or binary operators.
6 * 6 *
7 * See also: 7 * See also:
8 * lsym_binary_op.c 8 * lsym_binary_op.c
9 * lsym_unary_op.c 9 * lsym_unary_op.c
10 */ 10 */
11 11
12//indent input 12//indent input
13{ 13{
14 // See lsym_offsetof.c. 14 // See lsym_offsetof.c.
@@ -34,27 +34,27 @@ @@ -34,27 +34,27 @@
34{ 34{
35 int var = ({1}); 35 int var = ({1});
36 int var = ({ 36 int var = ({
37 1 37 1
38 }); 38 });
39 int var = ({ 39 int var = ({
40 int decl = 1; 40 int decl = 1;
41 stmt; 41 stmt;
42 }); 42 });
43} 43}
44//indent end 44//indent end
45 45
46//indent run -di0 46//indent run -di0
47error: Standard Input:7: Unbalanced parentheses 
48warning: Standard Input:9: Extra ')' 
49{ 47{
50 int var = ({1}); 48 int var = ({1});
51 int var = ({ 49 int var = ({
52 1 50 1
53 }); 51 });
54 int var = ({ 52 int var = ({
55 int decl = 1; 53 int decl = 1;
56 stmt; 54 stmt;
57 }); 55 });
58} 56}
59exit 1 57exit 1
 58error: Standard Input:7: Unbalanced parentheses
 59warning: Standard Input:9: Extra ')'
60//indent end 60//indent end

cvs diff -r1.12 -r1.13 src/tests/usr.bin/indent/lsym_preprocessing.c (expand / switch to unified diff)

--- src/tests/usr.bin/indent/lsym_preprocessing.c 2023/06/14 10:29:52 1.12
+++ src/tests/usr.bin/indent/lsym_preprocessing.c 2023/06/14 17:07:32 1.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lsym_preprocessing.c,v 1.12 2023/06/14 10:29:52 rillig Exp $ */ 1/* $NetBSD: lsym_preprocessing.c,v 1.13 2023/06/14 17:07:32 rillig Exp $ */
2 2
3/* 3/*
4 * Tests for the token lsym_preprocessing, which represents a '#' that starts 4 * Tests for the token lsym_preprocessing, which represents a '#' that starts
5 * a preprocessing line. 5 * a preprocessing line.
6 * 6 *
7 * #define 7 * #define
8 * #ifdef 8 * #ifdef
9 * #include 9 * #include
10 * #line 10 * #line
11 * #pragma 11 * #pragma
12 * 12 *
13 * The whole preprocessing line is processed separately from the main source 13 * The whole preprocessing line is processed separately from the main source
14 * code, without much tokenizing or parsing. 14 * code, without much tokenizing or parsing.
@@ -284,26 +284,26 @@ int before; @@ -284,26 +284,26 @@ int before;
284 * Unrecognized and unmatched preprocessing directives are preserved. 284 * Unrecognized and unmatched preprocessing directives are preserved.
285 */ 285 */
286//indent input 286//indent input
287#else 287#else
288#elif 0 288#elif 0
289#elifdef var 289#elifdef var
290#endif 290#endif
291 291
292#unknown 292#unknown
293# 3 "file.c" 293# 3 "file.c"
294//indent end 294//indent end
295 295
296//indent run 296//indent run
297error: Standard Input:1: Unmatched #else 
298error: Standard Input:2: Unmatched #elif 
299error: Standard Input:3: Unmatched #elifdef 
300error: Standard Input:4: Unmatched #endif 
301#else 297#else
302#elif 0 298#elif 0
303#elifdef var 299#elifdef var
304#endif 300#endif
305 301
306#unknown 302#unknown
307# 3 "file.c" 303# 3 "file.c"
308exit 1 304exit 1
 305error: Standard Input:1: Unmatched #else
 306error: Standard Input:2: Unmatched #elif
 307error: Standard Input:3: Unmatched #elifdef
 308error: Standard Input:4: Unmatched #endif
309//indent end 309//indent end

cvs diff -r1.5 -r1.6 src/tests/usr.bin/indent/psym_else.c (expand / switch to unified diff)

--- src/tests/usr.bin/indent/psym_else.c 2023/06/10 17:35:41 1.5
+++ src/tests/usr.bin/indent/psym_else.c 2023/06/14 17:07:32 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: psym_else.c,v 1.5 2023/06/10 17:35:41 rillig Exp $ */ 1/* $NetBSD: psym_else.c,v 1.6 2023/06/14 17:07:32 rillig Exp $ */
2 2
3/* 3/*
4 * Tests for the parser symbol psym_else, which represents the keyword 'else' 4 * Tests for the parser symbol psym_else, which represents the keyword 'else'
5 * that is being shifted on the parser stack. 5 * that is being shifted on the parser stack.
6 * 6 *
7 * This parser symbol never ends up on the stack itself. 7 * This parser symbol never ends up on the stack itself.
8 */ 8 */
9 9
10/* 10/*
11 * When parsing nested incomplete 'if' statements, the problem of the 11 * When parsing nested incomplete 'if' statements, the problem of the
12 * 'dangling else' occurs. It is resolved by binding the 'else' to the 12 * 'dangling else' occurs. It is resolved by binding the 'else' to the
13 * innermost incomplete 'if' statement. 13 * innermost incomplete 'if' statement.
14 * 14 *
@@ -70,19 +70,19 @@ function(void) @@ -70,19 +70,19 @@ function(void)
70 else 70 else
71 (var = 3); 71 (var = 3);
72} 72}
73//indent end 73//indent end
74 74
75 75
76//indent input 76//indent input
77{ 77{
78 else 78 else
79} 79}
80//indent end 80//indent end
81 81
82//indent run 82//indent run
83error: Standard Input:2: Unmatched 'else' 
84{ 83{
85 else 84 else
86} 85}
87exit 1 86exit 1
 87error: Standard Input:2: Unmatched 'else'
88//indent end 88//indent end

cvs diff -r1.4 -r1.5 src/tests/usr.bin/indent/t_options.lua (expand / switch to unified diff)

--- src/tests/usr.bin/indent/t_options.lua 2023/05/22 06:35:56 1.4
+++ src/tests/usr.bin/indent/t_options.lua 2023/06/14 17:07:32 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1-- $NetBSD: t_options.lua,v 1.4 2023/05/22 06:35:56 rillig Exp $ 1-- $NetBSD: t_options.lua,v 1.5 2023/06/14 17:07:32 rillig Exp $
2-- 2--
3-- Copyright (c) 2023 The NetBSD Foundation, Inc. 3-- Copyright (c) 2023 The NetBSD Foundation, Inc.
4-- All rights reserved. 4-- All rights reserved.
5-- 5--
6-- Redistribution and use in source and binary forms, with or without 6-- Redistribution and use in source and binary forms, with or without
7-- modification, are permitted provided that the following conditions 7-- modification, are permitted provided that the following conditions
8-- are met: 8-- are met:
9-- 1. Redistributions of source code must retain the above copyright 9-- 1. Redistributions of source code must retain the above copyright
10-- notice, this list of conditions and the following disclaimer. 10-- notice, this list of conditions and the following disclaimer.
11-- 2. Redistributions in binary form must reproduce the above copyright 11-- 2. Redistributions in binary form must reproduce the above copyright
12-- notice, this list of conditions and the following disclaimer in the 12-- notice, this list of conditions and the following disclaimer in the
13-- documentation and/or other materials provided with the distribution. 13-- documentation and/or other materials provided with the distribution.
14-- 14--
@@ -116,34 +116,37 @@ local function check_empty_lines_block(n @@ -116,34 +116,37 @@ local function check_empty_lines_block(n
116 warn(lineno, ("expecting %d empty %s, got %d") 116 warn(lineno, ("expecting %d empty %s, got %d")
117 :format(n, lines, max_empty_lines)) 117 :format(n, lines, max_empty_lines))
118 end 118 end
119end 119end
120 120
121local function check_unused_input() 121local function check_unused_input()
122 if unused_input_lineno ~= 0 then 122 if unused_input_lineno ~= 0 then
123 warn(unused_input_lineno, "input is not used") 123 warn(unused_input_lineno, "input is not used")
124 end 124 end
125end 125end
126 126
127local function run_indent(inp, args) 127local function run_indent(inp, args)
128 local indent = os.getenv("INDENT") or "indent" 128 local indent = os.getenv("INDENT") or "indent"
129 local cmd = indent .. " " .. args .. " 2>&1" 129 local cmd = indent .. " " .. args .. " 2>t_options.err"
130 130
131 local indent_in = assert(io.popen(cmd, "w")) 131 local indent_in = assert(io.popen(cmd, "w"))
132 indent_in:write(inp) 132 indent_in:write(inp)
133 local ok, kind, info = indent_in:close() 133 local ok, kind, info = indent_in:close()
134 if not ok then 134 if not ok then
135 print(kind .. " " .. info) 135 print(kind .. " " .. info)
136 end 136 end
 137 for line in io.lines("t_options.err") do
 138 print(line)
 139 end
137end 140end
138 141
139local function handle_empty_section(line) 142local function handle_empty_section(line)
140 if line == "" then 143 if line == "" then
141 curr_empty_lines = curr_empty_lines + 1 144 curr_empty_lines = curr_empty_lines + 1
142 else 145 else
143 if curr_empty_lines > max_empty_lines then 146 if curr_empty_lines > max_empty_lines then
144 max_empty_lines = curr_empty_lines 147 max_empty_lines = curr_empty_lines
145 end 148 end
146 if curr_empty_lines > 0 then 149 if curr_empty_lines > 0 then
147 if prev_empty_lines > 1 then 150 if prev_empty_lines > 1 then
148 warn(lineno - curr_empty_lines - 1, 151 warn(lineno - curr_empty_lines - 1,
149 prev_empty_lines .. " empty lines a few " 152 prev_empty_lines .. " empty lines a few "