Module Name:    src
Committed By:   rillig
Date:           Thu Nov 25 21:39:21 UTC 2021

Modified Files:
        src/tests/usr.bin/indent: t_misc.sh

Log Message:
tests/indent: test in-place formatting with parse errors

The file gets formatted until the end, despite the parse error. This may
destroy layout details of the code but usually preserves the overall
structure. Since all source code is supposed to be under version
control, this is not a problem.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/usr.bin/indent/t_misc.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/t_misc.sh
diff -u src/tests/usr.bin/indent/t_misc.sh:1.17 src/tests/usr.bin/indent/t_misc.sh:1.18
--- src/tests/usr.bin/indent/t_misc.sh:1.17	Sat Nov 20 09:59:53 2021
+++ src/tests/usr.bin/indent/t_misc.sh	Thu Nov 25 21:39:21 2021
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_misc.sh,v 1.17 2021/11/20 09:59:53 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.18 2021/11/25 21:39:21 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -53,6 +53,24 @@ in_place_body()
 	    cat code.c.bak
 }
 
+atf_test_case 'in_place_parse_error'
+in_place_parse_error_body()
+{
+	# On normal parse errors, indent continues until the end of the file.
+	# This means that even in the case of errors, not much is lost.
+
+	cat <<-\EOF > code.c
+		int line1;
+		}
+		int line3;
+	EOF
+
+	atf_check -s 'exit:1' -e 'ignore' \
+	   "$indent" code.c
+	atf_check -o 'inline:int\t\tline1;\n}\nint\t\tline3;\n' \
+	    cat code.c
+}
+
 atf_test_case 'verbose_profile'
 verbose_profile_body()
 {
@@ -397,4 +415,5 @@ atf_init_test_cases()
 	atf_add_test_case 'default_backup_extension'
 	atf_add_test_case 'several_profiles'
 	atf_add_test_case 'command_line_vs_profile'
+	atf_add_test_case 'in_place_parse_error'
 }

Reply via email to