Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint2 tests/lint: test error handling wh...
details: https://anonhg.NetBSD.org/src/rev/9547aa9d0dc9
branches: trunk
changeset: 1023372:9547aa9d0dc9
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Sep 04 20:39:17 2021 +0000
description:
tests/lint: test error handling when reading .ln files
diffstat:
tests/usr.bin/xlint/lint2/t_lint2.sh | 101 ++++++++++++++++++++++++++++++++++-
1 files changed, 100 insertions(+), 1 deletions(-)
diffs (125 lines):
diff -r 0f76f0e1c38b -r 9547aa9d0dc9 tests/usr.bin/xlint/lint2/t_lint2.sh
--- a/tests/usr.bin/xlint/lint2/t_lint2.sh Sat Sep 04 19:27:43 2021 +0000
+++ b/tests/usr.bin/xlint/lint2/t_lint2.sh Sat Sep 04 20:39:17 2021 +0000
@@ -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 @@
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 @@
|| eval "${i}_body() { std_body '$i'; }"
atf_add_test_case "$i"
done
+
+ atf_add_test_case 'error_cases'
}
Home |
Main Index |
Thread Index |
Old Index