Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/bin/sh New tests from kre
details: https://anonhg.NetBSD.org/src/rev/30943fbbcc8b
branches: trunk
changeset: 344178:30943fbbcc8b
user: christos <christos%NetBSD.org@localhost>
date: Wed Mar 16 15:49:19 2016 +0000
description:
New tests from kre
diffstat:
tests/bin/sh/Makefile | 6 +-
tests/bin/sh/t_arith.sh | 1055 ++++++++++++++++++++++++++++++++++++++++++++++
tests/bin/sh/t_varval.sh | 251 ++++++++++
3 files changed, 1310 insertions(+), 2 deletions(-)
diffs (truncated from 1343 to 300 lines):
diff -r 65b03584e0e6 -r 30943fbbcc8b tests/bin/sh/Makefile
--- a/tests/bin/sh/Makefile Wed Mar 16 15:48:01 2016 +0000
+++ b/tests/bin/sh/Makefile Wed Mar 16 15:49:19 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.8 2016/03/13 18:55:12 christos Exp $
+# $NetBSD: Makefile,v 1.9 2016/03/16 15:49:19 christos Exp $
#
.include <bsd.own.mk>
@@ -7,9 +7,10 @@
TESTS_SUBDIRS += dotcmd
+TESTS_SH+= t_arith
+TESTS_SH+= t_evaltested
TESTS_SH+= t_exit
TESTS_SH+= t_expand
-TESTS_SH+= t_evaltested
TESTS_SH+= t_fsplit
TESTS_SH+= t_here
TESTS_SH+= t_option
@@ -18,6 +19,7 @@
TESTS_SH+= t_set_e
TESTS_SH+= t_ulimit
TESTS_SH+= t_varquote
+TESTS_SH+= t_varval
TESTS_SH+= t_wait
.include <bsd.test.mk>
diff -r 65b03584e0e6 -r 30943fbbcc8b tests/bin/sh/t_arith.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/bin/sh/t_arith.sh Wed Mar 16 15:49:19 2016 +0000
@@ -0,0 +1,1055 @@
+# $NetBSD: t_arith.sh,v 1.1 2016/03/16 15:49:19 christos Exp $
+#
+# Copyright (c) 2016 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.
+#
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
+
+# Requirement is to support at least "signed long" whatever that means
+# (number of bits in "long" is not specified - but should be at lease 32).
+
+# These tests use -o inline:"..." rather than -o match:'...' as we have
+# only digits to examine, and it is good to be sure that 1 + 2 really gives 2
+# and that 42 or 123 don't look like success because there is a 2 in them.
+
+ARITH_BITS='?'
+discover_range()
+{
+ # cannot use arithmetic "test" operators, range of test in
+ # ATF_SHELL (or even TEST_SH) might not be as big as that
+ # supported by $(( )) in TEST_SH
+
+ if ! ${TEST_SH} -c ': $(( 0x10000 ))' 2>/dev/null
+ then
+ # 16 bits or less, or hex unsupported, just give up...
+ return
+ fi
+ test $( ${TEST_SH} -c 'echo $(( 0x1FFFF ))' ) = 131071 || return
+
+ # when attempting to exceed the number of available bits
+ # the shell may react in any of 3 (rational) ways
+ # 1. syntax error (maybe even core dump...) and fail
+ # 2. represent a positive number input as negative value
+ # 3. keep the number positive, but not the value expected
+ # (perhaps pegged at the max possible value)
+ # any of those may be accompanied by a message to stderr
+
+ # Must check all 3 possibilities for each plausible size
+ # Tests do not use 0x8000... because that value can have weird
+ # other side effects that are not relevant to discover here.
+ # But we do want to try and force the sign bit set.
+
+ if ! ${TEST_SH} -c ': $(( 0xC0000000 ))' 2>/dev/null
+ then
+ # proobably shell detected overflow and complained
+ # (if it does not support hex, we will discover that later)
+ ARITH_BITS=32
+ return
+ fi
+ if ${TEST_SH} 2>/dev/null \
+ -c 'case $(( 0xC0000000 )); in (-*) exit 0;; esac; exit 1'
+ then
+ ARITH_BITS=32
+ return
+ fi
+ if ${TEST_SH} -c '[ $(( 0xC0000000 )) != 3221225472 ]' 2>/dev/null
+ then
+ ARITH_BITS=32
+ return
+ fi
+
+ if ! ${TEST_SH} -c ': $(( 0xC000000000000000 ))' 2>/dev/null
+ then
+ ARITH_BITS=64
+ return
+ fi
+ if ${TEST_SH} 2>/dev/null \
+ -c 'case $(( 0xC000000000000000 )); in (-*) exit 0;; esac; exit 1'
+ then
+ ARITH_BITS=64
+ return
+ fi
+ if ${TEST_SH} 2>/dev/null \
+ -c '[ $((0xC000000000000000)) != 13835058055282163712 ]'
+ then
+ ARITH_BITS=64
+ return
+ fi
+
+ if ${TEST_SH} 2>/dev/null -c \
+ '[ $((0x123456781234567812345678)) = 5634002657842756053938493048 ]'
+ then
+ # just assume... (for now anyway, revisit when it happens...)
+ ARITH_BITS=96
+ return
+ fi
+}
+
+atf_test_case constants
+constants_head()
+{
+ atf_set "descr" "Tests that arithmetic expansion can handle constants"
+}
+constants_body()
+{
+ atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+ 'echo $(( 1 ))'
+ atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+ 'echo $(( 0 ))'
+ atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+ 'echo $((0x0))'
+
+ # atf_expect_fail "PR bin/50959"
+ atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+ 'echo $((0X0))'
+ # atf_expect_pass
+
+ atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+ 'echo $((000))'
+
+ atf_check -s exit:0 -o inline:'1\n' -e empty \
+ ${TEST_SH} -c 'echo $(( 000000001 ))'
+ atf_check -s exit:0 -o inline:'0\n' -e empty \
+ ${TEST_SH} -c 'echo $(( 0x000000 ))'
+
+ atf_check -s exit:0 -o inline:'99999\n' -e empty \
+ ${TEST_SH} -c 'echo $((99999))'
+
+ [ ${ARITH_BITS} -gt 44 ] &&
+ atf_check -s exit:0 -o inline:'9191919191919\n' -e empty \
+ ${TEST_SH} -c 'echo $((9191919191919))'
+
+ atf_check -s exit:0 -o inline:'13\n' -e empty ${TEST_SH} -c \
+ 'echo $(( 0xD ))'
+ atf_check -s exit:0 -o inline:'11\n' -e empty ${TEST_SH} -c \
+ 'echo $(( 013 ))'
+ atf_check -s exit:0 -o inline:'7\n' -e empty ${TEST_SH} -c \
+ 'x=7;echo $(($x))'
+ atf_check -s exit:0 -o inline:'9\n' -e empty ${TEST_SH} -c \
+ 'x=9;echo $((x))'
+
+ atf_check -s exit:0 -o inline:'11\n' -e empty \
+ ${TEST_SH} -c 'x=0xB; echo $(( $x ))'
+ atf_check -s exit:0 -o inline:'27\n' -e empty \
+ ${TEST_SH} -c 'x=0X1B; echo $(( x ))'
+ atf_check -s exit:0 -o inline:'27\n' -e empty \
+ ${TEST_SH} -c 'X=033; echo $(( $X ))'
+ atf_check -s exit:0 -o inline:'219\n' -e empty \
+ ${TEST_SH} -c 'X=0333; echo $(( X ))'
+ atf_check -s exit:0 -o inline:'0\n' -e empty \
+ ${TEST_SH} -c 'NULL=; echo $(( NULL ))'
+
+ # Not clear if this is 0, nothing, or an error, so omit for now
+ # atf_check -s exit:0 -o inline:'0\n' -e empty \
+ # ${TEST_SH} -c 'echo $(( ))'
+
+ # not clear whether this should return 0 or an error, so omit for now
+ # atf_check -s exit:0 -o inline:'0\n' -e empty \
+ # ${TEST_SH} -c 'echo $(( UNDEFINED_VAR ))'
+}
+
+atf_test_case constants_binary
+constants_binary_head()
+{
+ atf_set "descr" "Optional tests that binary constants work as expected"
+}
+constants_binary_body()
+{
+ if ! ${TEST_SH} -c '[ $(( 0b0101 )) = 5 ]' 2>/dev/null
+ then
+ atf_skip "Binary constants (0b0101) not implemented"
+ fi
+
+ atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+ 'echo $((0b0))'
+ atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+ 'echo $((0b01))'
+ atf_check -s exit:0 -o inline:'3\n' -e empty ${TEST_SH} -c \
+ 'echo $((0b11))'
+ atf_check -s exit:0 -o inline:'7\n' -e empty ${TEST_SH} -c \
+ 'echo $((0b111))'
+ atf_check -s exit:0 -o inline:'1398101\n' -e empty ${TEST_SH} -c \
+ 'echo $(( 0b101010101010101010101 ))'
+ atf_check -s exit:0 -o inline:'119097103\n' -e empty ${TEST_SH} -c \
+ 'echo $(( 0b111000110010100011100001111 ))'
+}
+
+atf_test_case do_unary_plus
+do_unary_plus_head()
+{
+ atf_set "descr" "Tests that unary plus works as expected"
+}
+do_unary_plus_body()
+{
+ atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+ 'echo $(( +0 ))'
+ atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+ 'echo $(( +1 ))'
+ atf_check -s exit:0 -o inline:'6\n' -e empty ${TEST_SH} -c \
+ 'echo $(( + 6 ))'
+ atf_check -s exit:0 -o inline:'4321\n' -e empty ${TEST_SH} -c \
+ 'echo $(( + 4321 ))'
+ atf_check -s exit:0 -o inline:'17185\n' -e empty ${TEST_SH} -c \
+ 'echo $(( + 0x4321 ))'
+}
+
+atf_test_case do_unary_minus
+do_unary_minus_head()
+{
+ atf_set "descr" "Tests that unary minus works as expected"
+}
+do_unary_minus_body()
+{
+ atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
+ 'echo $(( -1 ))'
+ atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+ 'echo $(( - 0 ))'
+ atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
+ 'echo $(( - 1 ))'
+ atf_check -s exit:0 -o inline:'-6\n' -e empty ${TEST_SH} -c \
+ 'echo $(( - 6 ))'
+ atf_check -s exit:0 -o inline:'-4321\n' -e empty ${TEST_SH} -c \
+ 'echo $(( - 4321 ))'
+ atf_check -s exit:0 -o inline:'-2257\n' -e empty ${TEST_SH} -c \
+ 'echo $(( - 04321 ))'
+ atf_check -s exit:0 -o inline:'-7\n' -e empty ${TEST_SH} -c \
+ 'echo $((-7))'
+}
+
+atf_test_case do_unary_not
+do_unary_not_head()
+{
+ atf_set "descr" "Tests that unary not (boolean) works as expected"
+}
+do_unary_not_body()
+{
+ atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+ 'echo $(( ! 1 ))'
+ atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+ 'echo $(( ! 0 ))'
+
+ atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+ 'echo $(( !1234 ))'
+ atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
+ 'echo $(( !0xFFFF ))'
+ atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
+ 'echo $(( ! 000000 ))'
+}
+
+atf_test_case do_unary_tilde
+do_unary_tilde_head()
+{
+ atf_set "descr" "Tests that unary not (bitwise) works as expected"
+}
+do_unary_tilde_body()
+{
Home |
Main Index |
Thread Index |
Old Index