Module Name:    src
Committed By:   rillig
Date:           Sat Sep  4 20:39:18 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint2: t_lint2.sh

Log Message:
tests/lint: test error handling when reading .ln files


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint2/t_lint2.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/xlint/lint2/t_lint2.sh
diff -u src/tests/usr.bin/xlint/lint2/t_lint2.sh:1.6 src/tests/usr.bin/xlint/lint2/t_lint2.sh:1.7
--- src/tests/usr.bin/xlint/lint2/t_lint2.sh:1.6	Tue Aug 24 21:30:52 2021
+++ src/tests/usr.bin/xlint/lint2/t_lint2.sh	Sat Sep  4 20:39:17 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_lint2.sh,v 1.6 2021/08/24 21:30:52 rillig Exp $
+# $NetBSD: t_lint2.sh,v 1.7 2021/09/04 20:39:17 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -76,11 +76,108 @@ emit_lp64_body()
 	std_emit_body 'emit_lp64'
 }
 
+test_error()
+{
+	printf '%s\n' \
+	    "$1"
+	printf '%s\n' \
+	    '0sinput.ln' \
+	    'Sinput.ln' \
+	    "$1" \
+	    > 'input.ln'
+
+	atf_check -s 'exit:1' -e "match:input file error: input\\.ln,3 \($2\)\$" \
+	    "$lint2" 'input.ln'
+}
+
+test_error_ignored()
+{
+	printf '%s\n' \
+	    "$1"
+	printf '%s\n' \
+	    '0sinput.ln' \
+	    'Sinput.ln' \
+	    "$1" \
+	    > 'input.ln'
+
+	atf_check -o 'ignore' \
+	    "$lint2" 'input.ln'
+}
+
+error_cases_head()
+{
+	std_head
+}
+error_cases_body()
+{
+	test_error ''			'missing record type'
+	test_error '123'		'missing record type'
+	test_error '0X'			'not a number: '
+	test_error '0d'			'not a number: '
+	test_error '0dXYZ'		'not a number: XYZ'
+	test_error '0d123'		'bad line number'
+	test_error '0d123.XYZ'		'not a number: XYZ'
+	test_error '0X0.0'		'bad record type X'
+
+	# function calls
+	test_error '0c0.0'		'not a number: '
+	test_error '0c0.0uu'		'used or discovered: u'
+	test_error '0c0.0du'		'used or discovered: u'
+	test_error '0c0.0ui'		'used or discovered: i'
+	test_error '0c0.0di'		'used or discovered: i'
+	test_error '0c0.0ud'		'used or discovered: d'
+	test_error '0c0.0dd'		'used or discovered: d'
+	# Unlike 'd' and 'u', the 'i' may be repeated.
+	test_error '0c0.0iiiiiii1n_'	'bad type: _ '
+	# Negative argument numbers like in 'z-1' are accepted but ignored.
+	test_error '0c0.0z-1d_'		'not a number: _'
+	# Argument 1 is both positive '1p' and negative '1n', which is
+	# impossible in practice.  It is not worth handling this though since
+	# only lint1 generates these .ln files.
+	test_error '0c0.0p1n1d_'	'not a number: _'
+	test_error '0c0.0s'		'not a number: '
+	test_error '0c0.0s2'		'not quote: '
+	test_error '0c0.0s2|'		'not quote: |'
+	test_error '0c0.0s2"'		'trailing data: '
+	test_error '0c0.0s2"%'		'missing closing quote'
+	# shellcheck disable=SC1003
+	test_error '0c0.0s2"\'		'missing after \'
+	# shellcheck disable=SC1003
+	test_error '0c0.0s2"%\'		'missing after \'
+
+	# declarations and definitions
+	test_error '0d0'		'bad line number'
+	test_error '0d0.0'		'not a number: '
+	test_error '0d0.0dd'		'def'
+	test_error '0d0.0de'		'decl'
+	test_error '0d0.0ee'		'decl'
+	test_error '0d0.0ii'		'inline'
+	test_error '0d0.0oo'		'osdef'
+	test_error '0d0.0rr'		'r'
+	test_error '0d0.0ss'		'static'
+	test_error '0d0.0tt'		'tdef'
+	test_error '0d0.0uu'		'used'
+	test_error '0d0.0v1v1'		'v'
+	test_error '0d0.0P1P1'		'P'
+	test_error '0d0.0S1S1'		'S'
+	test_error '0d0.0v1P1S_'	'not a number: _'
+	test_error '0d0.0d3var_'	'bad type: _ '
+	test_error '0d0.0d3varPV_'	'trailing line: _'
+
+	# usage of a variable or a function
+	test_error '0u0.0'		'bad delim '
+	test_error '0u0.0_'		'bad delim _'
+	test_error '0u0.0x'		'not a number: '
+	# trailing garbage is not detected
+	test_error_ignored '0u0.0x3var_'
+}
+
 atf_init_test_cases()
 {
 	local i
 
 	# shellcheck disable=SC2013
+	# shellcheck disable=SC2035
 	for i in $(cd "$(atf_get_srcdir)" && echo *.ln); do
 		i=${i%.ln}
 
@@ -98,4 +195,6 @@ atf_init_test_cases()
 		|| eval "${i}_body() { std_body '$i'; }"
 		atf_add_test_case "$i"
 	done
+
+	atf_add_test_case 'error_cases'
 }

Reply via email to