diff options
Diffstat (limited to 'src/kash/tests')
-rw-r--r-- | src/kash/tests/Makefile.kmk | 75 | ||||
-rwxr-xr-x | src/kash/tests/common-include.sh | 14 | ||||
-rwxr-xr-x | src/kash/tests/netbsd/exit1 | 7 | ||||
-rwxr-xr-x | src/kash/tests/netbsd/var1 | 8 | ||||
-rwxr-xr-x | src/kash/tests/netbsd/waitjob | 8 | ||||
-rw-r--r-- | src/kash/tests/pipe-1 | 18 | ||||
-rw-r--r-- | src/kash/tests/pipe-2 | 30 | ||||
-rwxr-xr-x | src/kash/tests/redirect-1 | 18 | ||||
-rwxr-xr-x | src/kash/tests/redirect-2 | 19 | ||||
-rwxr-xr-x | src/kash/tests/redirect-3 | 20 | ||||
-rwxr-xr-x | src/kash/tests/tick-1 | 10 | ||||
-rwxr-xr-x | src/kash/tests/trap-exit-1 | 7 | ||||
-rwxr-xr-x | src/kash/tests/trap-int-1 | 6 | ||||
-rwxr-xr-x | src/kash/tests/trap-term-1 | 6 |
14 files changed, 246 insertions, 0 deletions
diff --git a/src/kash/tests/Makefile.kmk b/src/kash/tests/Makefile.kmk new file mode 100644 index 0000000..40e081d --- /dev/null +++ b/src/kash/tests/Makefile.kmk @@ -0,0 +1,75 @@ +# $Id: Makefile.kmk 3433 2020-09-02 17:25:31Z bird $ +## @file +# Sub-makefile for kash tests. +# + +# +# Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net> +# +# This file is part of kBuild. +# +# kBuild is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# kBuild is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with kBuild. If not, see <http://www.gnu.org/licenses/> +# +# + +SUB_DEPTH = ../../.. +include $(KBUILD_PATH)/subheader.kmk + +# +# The program. +# + +TESTING += kash_tests + +KASH_TEST_BIN = $(if $(kash_1_TARGET),$(kash_1_TARGET),$(PATH_INS)/$(TEMPLATE_BIN_INST)kmk_ash$(SUFF_EXE)) +KASH_TEST_DIR := $(PATH_SUB_CURRENT) +KASH_TESTCASES := $(addprefix $(KASH_TEST_DIR)/,\ + trap-exit-1 \ + trap-int-1 \ + trap-term-1 \ + tick-1 \ + redirect-1 \ + redirect-2 \ + redirect-3 \ + pipe-1 \ + pipe-2 \ + ) + +# exec-1 - lost + + +kash_tests:: + $(ECHO) "kash tests..." + @export KASH_TEST_DIR=$(KASH_TEST_DIR); \ + KASH_FAILURE=0; \ + $(foreach test,$(KASH_TESTCASES)\ + ,echo " * $(KASH_TEST_BIN) $(test)"; \ + if ! $(KASH_TEST_BIN) $(test); then \ + echo " => FAILURE!"; \ + KASH_FAILURE=`$(EXPR_EXT) $${KASH_FAILURE} + 1`; \ + fi; \ + ) \ + if test $$KASH_FAILURE -eq 0; then \ + echo 'kash tests: All tests succeeded.'; \ + else \ + echo "kash tests: $$KASH_FAILURE tests failed"'!!'; \ + echo ""; \ + exit 1; \ + fi + + + +include $(FILE_KBUILD_SUB_FOOTER) + + diff --git a/src/kash/tests/common-include.sh b/src/kash/tests/common-include.sh new file mode 100755 index 0000000..199f42f --- /dev/null +++ b/src/kash/tests/common-include.sh @@ -0,0 +1,14 @@ +# File to be sourced. Contains pointers to a bunch of shell utilities. + +CMD_PREFIX=kmk_ +CMD_CAT=${CMD_PREFIX}cat +CMD_CP=${CMD_PREFIX}cp +CMD_EXPR=${CMD_PREFIX}expr +CMD_INSTALL=${CMD_PREFIX}install +CMD_LN=${CMD_PREFIX}ln +CMD_MV=${CMD_PREFIX}mv +CMD_RM=${CMD_PREFIX}rm +CMD_SED=${CMD_PREFIX}sed +CMD_SLEEP=${CMD_PREFIX}sleep +CMD_TIME=${CMD_PREFIX}time + diff --git a/src/kash/tests/netbsd/exit1 b/src/kash/tests/netbsd/exit1 new file mode 100755 index 0000000..5139fe3 --- /dev/null +++ b/src/kash/tests/netbsd/exit1 @@ -0,0 +1,7 @@ +#!/bin/sh +x=`( trap 'echo exiting' EXIT; /usr/bin/true )` +if [ -z "$x" ] +then + echo failed + exit 1 +fi diff --git a/src/kash/tests/netbsd/var1 b/src/kash/tests/netbsd/var1 new file mode 100755 index 0000000..68267af --- /dev/null +++ b/src/kash/tests/netbsd/var1 @@ -0,0 +1,8 @@ +#!/bin/sh + +line='/foo/bar/*/baz' +if [ "/foo/bar/" != ${line%%\**}"" ] +then + echo broken + exit 1 +fi diff --git a/src/kash/tests/netbsd/waitjob b/src/kash/tests/netbsd/waitjob new file mode 100755 index 0000000..e2cc333 --- /dev/null +++ b/src/kash/tests/netbsd/waitjob @@ -0,0 +1,8 @@ +#!/bin/sh +sleep 3 & +sleep 1 & + +wait %1 +[ $? = 0 ] || echo fail1 +wait %2 +[ $? = 0 ] || echo fail2 diff --git a/src/kash/tests/pipe-1 b/src/kash/tests/pipe-1 new file mode 100644 index 0000000..fbd6833 --- /dev/null +++ b/src/kash/tests/pipe-1 @@ -0,0 +1,18 @@ +#!/bin/sh + +# Pipes input from an builtin command thru an external one. + +. ${KASH_TEST_DIR}/common-include.sh + +TMPFILE="/tmp/pipe-1.$$.tmp" + +echo piped | $CMD_SED -e 's/piped/1/' > $TMPFILE +VAR=`$CMD_CAT $TMPFILE` +$CMD_RM -f $TMPFILE +if test "$VAR" != "1"; then + echo "pipe-1: FAILURE - VAR=$VAR" + exit 1 +fi +echo "pipe-1: SUCCESS" +exit 0 + diff --git a/src/kash/tests/pipe-2 b/src/kash/tests/pipe-2 new file mode 100644 index 0000000..6ba2637 --- /dev/null +++ b/src/kash/tests/pipe-2 @@ -0,0 +1,30 @@ +#!/bin/sh + +# Pipes input from an builtin command thru an external one. + +. ${KASH_TEST_DIR}/common-include.sh + +TMPFILE1="/tmp/pipe-2a.$$.tmp" +TMPFILE2="/tmp/pipe-2b.$$.tmp" +echo piped > $TMPFILE1 +$CMD_CAT $TMPFILE1 \ + | $CMD_SED -e 's/piped/abc/' \ + | $CMD_SED -e 's/abc/def/' \ + | $CMD_SED -e 's/def/ghi/' \ + | $CMD_SED -e 's/ghi/jkl/' \ + | $CMD_SED -e 's/jkl/mno/' \ + | $CMD_SED -e 's/mno/pqr/' \ + | $CMD_SED -e 's/pqr/stu/' \ + | $CMD_SED -e 's/stu/vwx/' \ + | $CMD_SED -e 's/vwx/yz_/' \ + > $TMPFILE2 + +VAR=`$CMD_CAT $TMPFILE2` +$CMD_RM -f -- $TMPFILE1 $TMPFILE2 +if test "$VAR" != "yz_"; then + echo "pipe-2: FAILURE - VAR=$VAR" + exit 1 +fi +echo "pipe-2: SUCCESS" +exit 0 + diff --git a/src/kash/tests/redirect-1 b/src/kash/tests/redirect-1 new file mode 100755 index 0000000..350e56a --- /dev/null +++ b/src/kash/tests/redirect-1 @@ -0,0 +1,18 @@ +#!/bin/sh + +# Redirect output from a builtin command. + +. ${KASH_TEST_DIR}/common-include.sh + +TMPFILE="/tmp/redirect-1.$$.tmp" + +echo 1 > $TMPFILE +VAR=`$CMD_CAT $TMPFILE` +$CMD_RM -f $TMPFILE +if test "$VAR" != "1"; then + echo "redirect-1: FAILURE - VAR=$VAR" + exit 1 +fi +echo "redirect-1: SUCCESS" +exit 0 + diff --git a/src/kash/tests/redirect-2 b/src/kash/tests/redirect-2 new file mode 100755 index 0000000..09bd905 --- /dev/null +++ b/src/kash/tests/redirect-2 @@ -0,0 +1,19 @@ +#!/bin/sh + +# Redirect output from builtin commands in a subshell. + +. ${KASH_TEST_DIR}/common-include.sh + +TMPFILE="/tmp/redirect-2.$$.tmp" + +(echo -n 1 ; echo -n 2 ; echo -n 3 ) > $TMPFILE +VAR=`$CMD_CAT $TMPFILE` +$CMD_RM -f $TMPFILE +if test "$VAR" != "123"; then + echo "redirect-2: FAILURE - VAR=$VAR" + exit 1 +fi +echo "redirect-2: SUCCESS" +exit 0 + + diff --git a/src/kash/tests/redirect-3 b/src/kash/tests/redirect-3 new file mode 100755 index 0000000..3cb30e4 --- /dev/null +++ b/src/kash/tests/redirect-3 @@ -0,0 +1,20 @@ +#!/bin/sh + +# Redirect input to an external command. + +. ${KASH_TEST_DIR}/common-include.sh + +TMPFILE="/tmp/redirect-3.$$.tmp" + +echo 1 > $TMPFILE +echo 2 >> $TMPFILE +echo 3 >> $TMPFILE +VAR=`$CMD_SED -e '/2/!d' < $TMPFILE` +$CMD_RM -f $TMPFILE +if test "$VAR" != "2"; then + echo "redirect-3: FAILURE - VAR=$VAR." + exit 1 +fi +echo "redirect-3: SUCCESS" +exit 0 + diff --git a/src/kash/tests/tick-1 b/src/kash/tests/tick-1 new file mode 100755 index 0000000..1a64f14 --- /dev/null +++ b/src/kash/tests/tick-1 @@ -0,0 +1,10 @@ +#!/bin/sh + +VAR=`echo "echoed string"` +if test "$VAR" != "echoed string"; then + echo "tick-1: failure: VAR=$VAR" + exit 1 +fi +echo 'tick-1: SUCCESS' +exit 0 + diff --git a/src/kash/tests/trap-exit-1 b/src/kash/tests/trap-exit-1 new file mode 100755 index 0000000..50b805c --- /dev/null +++ b/src/kash/tests/trap-exit-1 @@ -0,0 +1,7 @@ +#!/bin/sh + +trap 'echo "trap-exit-1: overriding exit 1"; exit 0' EXIT +exit 1 +exit 2 + + diff --git a/src/kash/tests/trap-int-1 b/src/kash/tests/trap-int-1 new file mode 100755 index 0000000..79e2dbb --- /dev/null +++ b/src/kash/tests/trap-int-1 @@ -0,0 +1,6 @@ +#!/bin/sh + +trap 'echo "trap-int-1: caught SIGINT"; exit 0' INT +kill -INT $$ +exit 2 + diff --git a/src/kash/tests/trap-term-1 b/src/kash/tests/trap-term-1 new file mode 100755 index 0000000..e9e94d5 --- /dev/null +++ b/src/kash/tests/trap-term-1 @@ -0,0 +1,6 @@ +#!/bin/sh + +trap 'echo "trap-term-1: caught SIGTERM"; exit 0' TERM +kill -TERM $$ +exit 2 + |