Module Name:    src
Committed By:   rillig
Date:           Sat May 20 22:08:07 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: t_options.lua

Log Message:
tests/indent: prevent 'indent end' with arguments


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/t_options.lua

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/t_options.lua
diff -u src/tests/usr.bin/indent/t_options.lua:1.1 src/tests/usr.bin/indent/t_options.lua:1.2
--- src/tests/usr.bin/indent/t_options.lua:1.1	Sat May 20 21:32:05 2023
+++ src/tests/usr.bin/indent/t_options.lua	Sat May 20 22:08:07 2023
@@ -1,4 +1,4 @@
--- $NetBSD: t_options.lua,v 1.1 2023/05/20 21:32:05 rillig Exp $
+-- $NetBSD: t_options.lua,v 1.2 2023/05/20 22:08:07 rillig Exp $
 --
 -- Copyright (c) 2023 The NetBSD Foundation, Inc.
 -- All rights reserved.
@@ -129,7 +129,7 @@ local function run_indent(inp, args)
 	local indent_in = assert(io.open("indent.in", "w"))
 	indent_in:write(inp)
 	indent_in:close()
-	ok, kind, info = os.execute(cmd)
+	local ok, kind, info = os.execute(cmd)
 	if not ok then
 		print(kind .. " " .. info)
 	end
@@ -155,84 +155,103 @@ local function handle_empty_section(line
 	end
 end
 
-local function handle_indent_directive(line, command, args)
-	print(line)
-	expected_out:write(line .. "\n")
+local function handle_indent_input()
+	if prev_empty_lines ~= 2 and seen_input_section then
+		warn(lineno, "input section needs 2 empty lines "
+		    .. "above, not " .. prev_empty_lines)
+	end
+	check_empty_lines_block(2)
+	check_unused_input()
+	section = "input"
+	section_excl_comm = ""
+	section_incl_comm = ""
+	unused_input_lineno = lineno
+	seen_input_section = true
+	output_excl_comm = ""
+	output_incl_comm = ""
+	output_lineno = 0
+end
 
-	if command == "input" then
-		if prev_empty_lines ~= 2 and seen_input_section then
-			warn(lineno, "input section needs 2 empty lines "
-			    .. "above, not " .. prev_empty_lines)
-		end
-		check_empty_lines_block(2)
-		check_unused_input()
-		section = "input"
-		section_excl_comm = ""
-		section_incl_comm = ""
-		unused_input_lineno = lineno
-		seen_input_section = true
-		output_excl_comm = ""
-		output_incl_comm = ""
-		output_lineno = 0
+local function handle_indent_run(args)
+	if section ~= "" then
+		warn(lineno, "unfinished section '" .. section .. "'")
+	end
+	check_empty_lines_block(1)
+	if prev_empty_lines ~= 1 then
+		warn(lineno, "run section needs 1 empty line above, "
+		    .. "not " .. prev_empty_lines)
+	end
+	section = "run"
+	output_lineno = lineno
+	section_excl_comm = ""
+	section_incl_comm = ""
 
-	elseif command == "run" then
-		if section ~= "" then
-			warn(lineno, "unfinished section '" .. section .. "'")
-		end
-		check_empty_lines_block(1)
-		if prev_empty_lines ~= 1 then
-			warn(lineno, "run section needs 1 empty line above, "
-			    .. "not " .. prev_empty_lines)
-		end
-		section = "run"
-		output_lineno = lineno
-		section_excl_comm = ""
-		section_incl_comm = ""
+	run_indent(input_excl_comm, args)
+	unused_input_lineno = 0
+end
 
-		run_indent(input_excl_comm, args)
-		unused_input_lineno = 0
+local function handle_indent_run_equals_input(args)
+	check_empty_lines_block(1)
+	run_indent(input_excl_comm, args)
+	expected_out:write(input_excl_comm)
+	unused_input_lineno = 0
+	max_empty_lines = 0
+end
 
-	elseif command == "run-equals-input" then
-		check_empty_lines_block(1)
-		run_indent(input_excl_comm, args)
-		expected_out:write(input_excl_comm)
-		unused_input_lineno = 0
-		max_empty_lines = 0
+local function handle_indent_run_equals_prev_output(args)
+	check_empty_lines_block(1)
+	run_indent(input_excl_comm, args)
+	expected_out:write(output_excl_comm)
+	max_empty_lines = 0
+end
 
-	elseif command == "run-equals-prev-output" then
-		check_empty_lines_block(1)
-		run_indent(input_excl_comm, args)
-		expected_out:write(output_excl_comm)
-		max_empty_lines = 0
+local function handle_indent_end_input()
+	if section_incl_comm == input_incl_comm then
+		warn(lineno, "duplicate input; remove this section")
+	end
 
-	elseif command == "end" and section == "input" then
-		if section_incl_comm == input_incl_comm then
-			warn(lineno, "duplicate input; remove this section")
-		end
+	input_excl_comm = section_excl_comm
+	input_incl_comm = section_incl_comm
+	section = ""
+	max_empty_lines = 0
+end
 
-		input_excl_comm = section_excl_comm
-		input_incl_comm = section_incl_comm
-		section = ""
-		max_empty_lines = 0
+local function handle_indent_end_run()
+	if section_incl_comm == input_incl_comm then
+		warn(output_lineno,
+		    "output == input; use run-equals-input")
+	end
+	if section_incl_comm == output_incl_comm then
+		warn(output_lineno,
+		    "duplicate output; use run-equals-prev-output")
+	end
 
-	elseif command == "end" and section == "run" then
-		if section_incl_comm == input_incl_comm then
-			warn(output_lineno,
-			    "output == input; use run-equals-input")
-		end
-		if section_incl_comm == output_incl_comm then
-			warn(output_lineno,
-			    "duplicate output; use run-equals-prev-output")
-		end
+	output_excl_comm = section_excl_comm
+	output_incl_comm = section_incl_comm
+	section = ""
+	max_empty_lines = 0
+end
 
-		output_excl_comm = section_excl_comm
-		output_incl_comm = section_incl_comm
-		section = ""
-		max_empty_lines = 0
+local function handle_indent_directive(line, command, args)
+	print(line)
+	expected_out:write(line .. "\n")
 
+	if command == "input" and args == "" then
+		handle_indent_input()
+	elseif command == "run" then
+		handle_indent_run(args)
+	elseif command == "run-equals-input" then
+		handle_indent_run_equals_input(args)
+	elseif command == "run-equals-prev-output" then
+		handle_indent_run_equals_prev_output(args)
+	elseif command == "end" and args ~= "" then
+		warn(lineno, "'//indent end' does not take arguments")
+	elseif command == "end" and section == "input" then
+		handle_indent_end_input()
+	elseif command == "end" and section == "run" then
+		handle_indent_end_run()
 	elseif command == "end" then
 		warn(lineno, "misplaced '//indent end'")
-
 	else
 		die(lineno, "invalid line '" .. line .. "'")
 	end

Reply via email to