From 36e939358a121cee73ea3f5e1adfaf0c627084b1 Mon Sep 17 00:00:00 2001 From: rillig Date: Sun, 24 Apr 2022 08:52:44 +0000 Subject: [PATCH] tests/indent: normalize amount of empty lines between test cases --- tests/usr.bin/indent/fmt_decl.c | 5 ++++- tests/usr.bin/indent/lsym_offsetof.c | 3 ++- tests/usr.bin/indent/opt_bacc.c | 3 ++- tests/usr.bin/indent/opt_badp.c | 9 ++++++++- tests/usr.bin/indent/opt_bs.c | 3 ++- tests/usr.bin/indent/opt_ci.c | 8 +++++++- tests/usr.bin/indent/opt_fcb.c | 4 +++- tests/usr.bin/indent/opt_l.c | 4 +++- tests/usr.bin/indent/t_options.awk | 19 ++++++++++++++++++- tests/usr.bin/indent/token_comment.c | 6 +++++- tests/usr.bin/indent/token_string_prefix.c | 4 +++- 11 files changed, 57 insertions(+), 11 deletions(-) diff --git a/tests/usr.bin/indent/fmt_decl.c b/tests/usr.bin/indent/fmt_decl.c index 1ded3b1ec0d5..19edee795a49 100644 --- a/tests/usr.bin/indent/fmt_decl.c +++ b/tests/usr.bin/indent/fmt_decl.c @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_decl.c,v 1.33 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: fmt_decl.c,v 1.34 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for declarations of global variables, external functions, and local @@ -613,6 +613,7 @@ ToToken(bool cond) #indent end #indent run-equals-input -TToken + /* Since lexi.c 1.153 from 2021-11-25. */ #indent run-equals-input @@ -647,6 +648,7 @@ static CachedDir *dot = NULL; #indent end #indent run-equals-input -TCachedDir + /* Since lexi.c 1.153 from 2021-11-25. */ #indent run-equals-input @@ -713,6 +715,7 @@ CachedDir_Assign(CachedDir **var, CachedDir *dir) #indent end #indent run-equals-input + #indent run-equals-input -TCachedDir diff --git a/tests/usr.bin/indent/lsym_offsetof.c b/tests/usr.bin/indent/lsym_offsetof.c index 20bfa253d022..6e12e7e462e0 100644 --- a/tests/usr.bin/indent/lsym_offsetof.c +++ b/tests/usr.bin/indent/lsym_offsetof.c @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_offsetof.c,v 1.3 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: lsym_offsetof.c,v 1.4 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for the token lsym_offsetof, which represents the keyword 'offsetof' @@ -10,6 +10,7 @@ size_t offset = offsetof(struct s, member); #indent end #indent run-equals-input + #indent run-equals-input -bs /* diff --git a/tests/usr.bin/indent/opt_bacc.c b/tests/usr.bin/indent/opt_bacc.c index 4371fb9bbe20..3c64c327d4bd 100644 --- a/tests/usr.bin/indent/opt_bacc.c +++ b/tests/usr.bin/indent/opt_bacc.c @@ -1,4 +1,4 @@ -/* $NetBSD: opt_bacc.c,v 1.8 2022/04/23 06:43:23 rillig Exp $ */ +/* $NetBSD: opt_bacc.c,v 1.9 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for the options '-bacc' and '-nbacc' ("blank line around conditional @@ -145,4 +145,5 @@ int outer_below; #indent end #indent run-equals-input -di0 -bacc + #indent run-equals-input -di0 -nbacc diff --git a/tests/usr.bin/indent/opt_badp.c b/tests/usr.bin/indent/opt_badp.c index 75ded4fcb92c..de5954704b65 100644 --- a/tests/usr.bin/indent/opt_badp.c +++ b/tests/usr.bin/indent/opt_badp.c @@ -1,4 +1,4 @@ -/* $NetBSD: opt_badp.c,v 1.7 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: opt_badp.c,v 1.8 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for the options '-badp' and '-nbadp'. @@ -15,6 +15,7 @@ empty(void) #indent end #indent run-equals-input -badp + #indent run-equals-input -nbadp @@ -27,6 +28,7 @@ blank(void) #indent end #indent run-equals-input -badp + #indent run-equals-input -nbadp @@ -39,6 +41,7 @@ declaration(void) #indent end #indent run-equals-input -badp + #indent run-equals-input -nbadp @@ -58,6 +61,7 @@ statement(void) stmt(); } #indent end + #indent run-equals-input -nbadp @@ -79,6 +83,7 @@ declaration_statement(void) stmt(); } #indent end + #indent run-equals-input -nbadp @@ -93,6 +98,7 @@ declaration_blank_statement(void) #indent end #indent run-equals-input -badp + #indent run-equals-input -nbadp @@ -109,4 +115,5 @@ declaration_blank_blank_statement(void) #indent end #indent run-equals-input -badp + #indent run-equals-input -nbadp diff --git a/tests/usr.bin/indent/opt_bs.c b/tests/usr.bin/indent/opt_bs.c index 8046069b7c65..c71cc32a99f6 100644 --- a/tests/usr.bin/indent/opt_bs.c +++ b/tests/usr.bin/indent/opt_bs.c @@ -1,4 +1,4 @@ -/* $NetBSD: opt_bs.c,v 1.8 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: opt_bs.c,v 1.9 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for the options '-bs' and '-nbs' ("blank after sizeof"). @@ -106,6 +106,7 @@ int sizeof_newline = sizeof #indent end #indent run-equals-input -di0 -bs + #indent run-equals-input -di0 -nbs diff --git a/tests/usr.bin/indent/opt_ci.c b/tests/usr.bin/indent/opt_ci.c index 90d13542347b..c17306ca056d 100644 --- a/tests/usr.bin/indent/opt_ci.c +++ b/tests/usr.bin/indent/opt_ci.c @@ -1,4 +1,4 @@ -/* $NetBSD: opt_ci.c,v 1.6 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: opt_ci.c,v 1.7 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for the option '-ci', which controls the indentation of continuation @@ -23,8 +23,11 @@ int top_level = (1 + 2 + ( 3)); #indent end + #indent run-equals-prev-output -ci2 + #indent run-equals-prev-output -ci4 + #indent run-equals-prev-output -ci8 #indent run -ci0 -nlp @@ -143,8 +146,11 @@ sum(int a, int b) third)); } #indent end + #indent run-equals-prev-output -ci2 + #indent run-equals-prev-output -ci4 + #indent run-equals-prev-output -ci8 #indent run -ci2 -nlp diff --git a/tests/usr.bin/indent/opt_fcb.c b/tests/usr.bin/indent/opt_fcb.c index 5b856b9b26de..787e614ce80f 100644 --- a/tests/usr.bin/indent/opt_fcb.c +++ b/tests/usr.bin/indent/opt_fcb.c @@ -1,4 +1,4 @@ -/* $NetBSD: opt_fcb.c,v 1.6 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: opt_fcb.c,v 1.7 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for the options '-fcb' and '-nfcb'. @@ -63,6 +63,7 @@ #indent end #indent run-equals-input -fcb + #indent run-equals-input -nfcb @@ -137,4 +138,5 @@ example(void) #indent end #indent run-equals-input -fcb + #indent run-equals-input -nfcb diff --git a/tests/usr.bin/indent/opt_l.c b/tests/usr.bin/indent/opt_l.c index 05fd6f04c671..fc554afc3593 100644 --- a/tests/usr.bin/indent/opt_l.c +++ b/tests/usr.bin/indent/opt_l.c @@ -1,4 +1,4 @@ -/* $NetBSD: opt_l.c,v 1.3 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: opt_l.c,v 1.4 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for the option '-l', which specifies the maximum length of a line. @@ -27,9 +27,11 @@ * same output. */ #indent end + #indent run-equals-prev-output -lc38 #indent run-equals-input -l78 + #indent run-equals-input -lc78 diff --git a/tests/usr.bin/indent/t_options.awk b/tests/usr.bin/indent/t_options.awk index 47f2f92b3ddb..bfa0968bb166 100644 --- a/tests/usr.bin/indent/t_options.awk +++ b/tests/usr.bin/indent/t_options.awk @@ -1,4 +1,4 @@ -# $NetBSD: t_options.awk,v 1.8 2022/04/22 21:21:20 rillig Exp $ +# $NetBSD: t_options.awk,v 1.9 2022/04/24 08:52:44 rillig Exp $ # # Copyright (c) 2021 The NetBSD Foundation, Inc. # All rights reserved. @@ -54,6 +54,7 @@ BEGIN { prev_empty_lines = 0 # the finished "block" of empty lines curr_empty_lines = 0 # the ongoing "block" of empty lines + max_empty_lines = 0 # between sections seen_input_section = 0 # the first input section is not checked section = "" # "", "input" or "run" @@ -89,6 +90,12 @@ function quote(s) return "'" s "'" } +function check_empty_lines_block(n) +{ + if (max_empty_lines != n && seen_input_section) + warn(NR, "expecting " n " empty " (n != 1 ? "lines" : "line") ", got " max_empty_lines) +} + function check_unused_input() { if (unused_input_lineno != 0) @@ -110,6 +117,8 @@ section == "" { if (NF == 0) curr_empty_lines++ else { + if (curr_empty_lines > max_empty_lines) + max_empty_lines = curr_empty_lines if (curr_empty_lines > 0) { if (prev_empty_lines > 1) warn(NR - curr_empty_lines - 1, @@ -138,6 +147,7 @@ section == "" { if (prev_empty_lines != 2 && seen_input_section) warn(NR, "input section needs 2 empty lines above, " \ "not " prev_empty_lines) + check_empty_lines_block(2) check_unused_input() section = "input" section_excl_comm = "" @@ -148,6 +158,7 @@ section == "" { } else if ($2 == "run") { if (section != "") warn(NR, "unfinished section " quote(section)) + check_empty_lines_block(1) if (prev_empty_lines != 1) warn(NR, "run section needs 1 empty line above, " \ "not " prev_empty_lines) @@ -160,13 +171,17 @@ section == "" { unused_input_lineno = 0 } else if ($2 == "run-equals-input") { + check_empty_lines_block(1) run_indent(input_excl_comm) printf("%s", input_excl_comm) > "expected.out" unused_input_lineno = 0 + max_empty_lines = 0 } else if ($2 == "run-equals-prev-output") { + check_empty_lines_block(1) run_indent(input_excl_comm) printf("%s", output_excl_comm) > "expected.out" + max_empty_lines = 0 } else if ($2 == "end" && section == "input") { if (section_incl_comm == input_incl_comm) @@ -175,6 +190,7 @@ section == "" { input_excl_comm = section_excl_comm input_incl_comm = section_incl_comm section = "" + max_empty_lines = 0 } else if ($2 == "end" && section == "run") { if (section_incl_comm == input_incl_comm) @@ -187,6 +203,7 @@ section == "" { output_excl_comm = section_excl_comm output_incl_comm = section_incl_comm section = "" + max_empty_lines = 0 } else if ($2 == "end") { warn(NR, "misplaced " quote("#indent end")) diff --git a/tests/usr.bin/indent/token_comment.c b/tests/usr.bin/indent/token_comment.c index 7ea1ef17ac16..53e4cbd6c9f4 100644 --- a/tests/usr.bin/indent/token_comment.c +++ b/tests/usr.bin/indent/token_comment.c @@ -1,4 +1,4 @@ -/* $NetBSD: token_comment.c,v 1.28 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: token_comment.c,v 1.29 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for formatting comments. C99 defines block comments and end-of-line @@ -851,6 +851,7 @@ comment_at_end_of_function(void) int decl; // end-of-line comment at the end of the file #indent end + #indent run-equals-input @@ -861,6 +862,7 @@ int decl; */ /*-A E*/ #indent end + #indent run-equals-input @@ -975,6 +977,7 @@ f(void) #indent end #indent run-equals-input -l5 + #indent run-equals-input -l32 @@ -1010,6 +1013,7 @@ line 4 */ #indent end #indent run-equals-input -nfc1 + #indent run-equals-input -nfc1 -nsc #indent run -nsc diff --git a/tests/usr.bin/indent/token_string_prefix.c b/tests/usr.bin/indent/token_string_prefix.c index c09d86989fce..8b1700409166 100644 --- a/tests/usr.bin/indent/token_string_prefix.c +++ b/tests/usr.bin/indent/token_string_prefix.c @@ -1,4 +1,4 @@ -/* $NetBSD: token_string_prefix.c,v 1.3 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: token_string_prefix.c,v 1.4 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for strings of wide characters, which are prefixed with 'L'. @@ -15,7 +15,9 @@ wchar_t wide_string[] = L"wide string"; * string literal. */ #indent run-equals-input -di0 + #indent run-equals-input -di0 -l25 + #indent run-equals-input -di0 -l1