Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/indent tests/indent: provide full line coverag...
details: https://anonhg.NetBSD.org/src/rev/956f20ac0f2a
branches: trunk
changeset: 989498:956f20ac0f2a
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Oct 14 17:42:12 2021 +0000
description:
tests/indent: provide full line coverage for argument handling
diffstat:
distrib/sets/lists/tests/mi | 3 +-
tests/usr.bin/indent/Makefile | 3 +-
tests/usr.bin/indent/t_errors.sh | 96 ++++++++++++++++++++++++++++++++++++---
tests/usr.bin/indent/t_misc.sh | 76 +++++++++++++++++++++++++++++++
4 files changed, 167 insertions(+), 11 deletions(-)
diffs (247 lines):
diff -r 43f0dac1ebec -r 956f20ac0f2a distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Thu Oct 14 15:40:00 2021 +0000
+++ b/distrib/sets/lists/tests/mi Thu Oct 14 17:42:12 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1137 2021/10/13 23:33:52 rillig Exp $
+# $NetBSD: mi,v 1.1138 2021/10/14 17:42:12 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -5007,6 +5007,7 @@
./usr/tests/usr.bin/indent/surplusbad.0.stdout tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/t_errors tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/t_indent tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/indent/t_misc tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/token-binary_op.0 tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/token-binary_op.0.pro tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/token-binary_op.0.stdout tests-usr.bin-tests compattestfile,atf
diff -r 43f0dac1ebec -r 956f20ac0f2a tests/usr.bin/indent/Makefile
--- a/tests/usr.bin/indent/Makefile Thu Oct 14 15:40:00 2021 +0000
+++ b/tests/usr.bin/indent/Makefile Thu Oct 14 17:42:12 2021 +0000
@@ -1,10 +1,11 @@
-# $NetBSD: Makefile,v 1.14 2021/10/13 23:33:52 rillig Exp $
+# $NetBSD: Makefile,v 1.15 2021/10/14 17:42:13 rillig Exp $
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/usr.bin/indent
TESTS_SH= t_errors
TESTS_SH+= t_indent
+TESTS_SH+= t_misc
FILESDIR= ${TESTSDIR}
FILES= binary.0
diff -r 43f0dac1ebec -r 956f20ac0f2a tests/usr.bin/indent/t_errors.sh
--- a/tests/usr.bin/indent/t_errors.sh Thu Oct 14 15:40:00 2021 +0000
+++ b/tests/usr.bin/indent/t_errors.sh Thu Oct 14 17:42:12 2021 +0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: t_errors.sh,v 1.1 2021/10/13 23:33:52 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.2 2021/10/14 17:42:13 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -27,32 +27,105 @@
#
# $FreeBSD$
+# Tests for error handling in indent.
+
indent=$(atf_config_get usr.bin.indent.test_indent /usr/bin/indent)
nl='
'
+expect_error()
+{
+ local msg
+
+ msg="$1"
+ shift
+
+ atf_check -s 'exit:1' \
+ -e "inline:$msg$nl" \
+ "$indent" "$@"
+}
+
atf_test_case 'option_unknown'
option_unknown_body()
{
- atf_check -s 'exit:1' \
- -e 'inline:indent: Command line: unknown option "-Z-unknown"'"$nl" \
- "$indent" -Z-unknown
+ expect_error \
+ 'indent: Command line: unknown option "-Z-unknown"' \
+ -Z-unknown
}
atf_test_case 'option_bool_trailing_garbage'
option_bool_trailing_garbage_body()
{
- atf_check -s 'exit:1' \
- -e 'inline:indent: Command line: unknown option "-bacchus"'"$nl" \
- "$indent" -bacchus
+ expect_error \
+ 'indent: Command line: unknown option "-bacchus"' \
+ -bacchus
}
atf_test_case 'option_int_missing_parameter'
option_int_missing_parameter_body()
{
+ expect_error \
+ 'indent: Command line: option "-ts" requires an integer parameter' \
+ -tsx
+}
+
+atf_test_case 'option_profile_not_found'
+option_profile_not_found_body()
+{
+ expect_error \
+ 'indent: profile ./nonexistent: No such file or directory' \
+ -P./nonexistent
+}
+
+atf_test_case 'option_typedefs_not_found'
+option_typedefs_not_found_body()
+{
+ expect_error \
+ 'indent: cannot open file ./nonexistent' \
+ -U./nonexistent
+}
+
+atf_test_case 'option_buffer_overflow'
+option_buffer_overflow_body()
+{
+ opt='12345678123456781234567812345678' # 32
+ opt="$opt$opt$opt$opt$opt$opt$opt$opt" # 256
+ opt="$opt$opt$opt$opt$opt$opt$opt$opt" # 2048
+ opt="$opt$opt$opt$opt$opt$opt$opt$opt" # 16384
+ printf '%s\n' "-$opt" > indent.pro
+
+ # TODO: The call to 'diag' should be replaced with 'errx'.
+ expect_error \
+ 'Error@1: buffer overflow in indent.pro, starting with '\''-123456781'\''' \
+ -Pindent.pro
+}
+
+atf_test_case 'option_special_missing_param'
+option_special_missing_param_body()
+{
+ # TODO: Write '-cli' instead of only 'cli'.
+ expect_error \
+ 'indent: Command line: ``cli'\'\'' requires a parameter' \
+ -cli
+
+ expect_error \
+ 'indent: Command line: ``T'\'\'' requires a parameter' \
+ -T
+
+ expect_error \
+ 'indent: Command line: ``U'\'\'' requires a parameter' \
+ -U
+}
+
+atf_test_case 'unterminated_comment'
+unterminated_comment_body()
+{
+ echo '/*' > comment.c
+
atf_check -s 'exit:1' \
- -e 'inline:indent: Command line: option "-ts" requires an integer parameter'"$nl" \
- "$indent" -tsx
+ -o 'inline:/*'"$nl"' *'"$nl" \
+ -e 'inline:/**INDENT** Error@2: Unterminated comment */'"$nl" \
+ "$indent" -st < comment.c
}
atf_init_test_cases()
@@ -60,4 +133,9 @@
atf_add_test_case 'option_unknown'
atf_add_test_case 'option_bool_trailing_garbage'
atf_add_test_case 'option_int_missing_parameter'
+ atf_add_test_case 'option_profile_not_found'
+ atf_add_test_case 'option_buffer_overflow'
+ atf_add_test_case 'option_typedefs_not_found'
+ atf_add_test_case 'option_special_missing_param'
+ atf_add_test_case 'unterminated_comment'
}
diff -r 43f0dac1ebec -r 956f20ac0f2a tests/usr.bin/indent/t_misc.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/indent/t_misc.sh Thu Oct 14 17:42:12 2021 +0000
@@ -0,0 +1,76 @@
+#! /bin/sh
+# $NetBSD: t_misc.sh,v 1.1 2021/10/14 17:42:13 rillig Exp $
+#
+# Copyright (c) 2021 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD$
+
+# Tests for indent that do not follow the input-profile-output scheme that is
+# used in t_indent.
+
+indent=$(atf_config_get usr.bin.indent.test_indent /usr/bin/indent)
+
+atf_test_case 'verbose_profile'
+verbose_profile_body()
+{
+ cat <<-\EOF > .indent.pro
+ -/* comment */bacc
+ -v
+ -fc1
+ EOF
+ cat <<-\EOF > before.c
+ int decl;
+ EOF
+ cat <<-\EOF > after.c.exp
+ int decl;
+ EOF
+ cat <<-\EOF > stdout.exp
+ profile: -fc1
+ profile: -bacc
+ profile: -v
+ profile: -fc1
+ There were 1 output lines and 0 comments
+ (Lines with comments)/(Lines with code): 0.000
+ EOF
+
+ # The code in args.c function set_profile suggests that options from
+ # profile files are echoed to stdout during startup. But since the
+ # command line options are handled after the profile files, a '-v' in
+ # the command line has no effect. That's why '-bacc' is not listed
+ # in stdout, but '-fc1' is. The second round of '-bacc', '-v', '-fc1'
+ # is listed because when running ATF, $HOME equals $PWD.
+
+ atf_check \
+ -o 'file:stdout.exp' \
+ "$indent" -v before.c after.c
+ atf_check \
+ -o 'file:after.c.exp' \
+ cat after.c
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case 'verbose_profile'
+}
Home |
Main Index |
Thread Index |
Old Index