From 7f89380569a4e599362e0792e79450c4990ec44e Mon Sep 17 00:00:00 2001 From: Petr Šplíchal Date: Jan 11 2018 10:18:23 +0000 Subject: Add tests from the upstream first repo Adding an initial set of tests from the upstream first repository: https://upstreamfirst.fedorainfracloud.org/bash --- diff --git a/func/Makefile b/func/Makefile new file mode 100644 index 0000000..6acb07d --- /dev/null +++ b/func/Makefile @@ -0,0 +1,64 @@ +# Makefile +# Author: Jan Scotka +# Location: + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2008 Red Hat, Inc. +# +# This program 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 2 of +# the License, or (at your option) any later version. +# +# This program 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 this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +TOPLEVEL_NAMESPACE=/CoreOS +PACKAGE_NAME=bash +RELATIVE_PATH=sanity/func + +export TEST=$(TOPLEVEL_NAMESPACE)/$(PACKAGE_NAME)/$(RELATIVE_PATH) +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + chmod a+x ./runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + + +$(METADATA): Makefile + @touch $(METADATA) + @echo "Owner: Jan Scotka " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Description: Try shell basic functionality" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 2h" >> $(METADATA) + @echo "RunFor: $(PACKAGE_NAME)" >> $(METADATA) + @echo "Requires: $(PACKAGE_NAME)" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/func/PURPOSE b/func/PURPOSE new file mode 100644 index 0000000..d641633 --- /dev/null +++ b/func/PURPOSE @@ -0,0 +1 @@ +Basic test of functions in Bourne-Again SHell, testing purpose for Test Container Project diff --git a/func/runtest.sh b/func/runtest.sh new file mode 100644 index 0000000..9a7b93b --- /dev/null +++ b/func/runtest.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2008 Red Hat, Inc. +# +# This program 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 2 of +# the License, or (at your option) any later version. +# +# This program 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 this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Include rhts and rhtslib environment +. /usr/bin/rhts-environment.sh +. /usr/share/beakerlib/beakerlib.sh + +PACKAGES=${PACKAGES:-bash} +SH_BIN=${SH_BIN:-bash} + +rlJournalStart + + rlPhaseStartSetup "Init phase" + rlAssertRpm --all + if [ $SH_BIN == "zsh" ]; then + ZSH_OPT="-i" + else + ZSH_OPT="" + fi + rlPhaseEnd + + + rlPhaseStartTest "Test of functions" + rlRun "${SH_BIN} -c pwd" 0 "Checking if ${SH_BIN} do pwd command" + rlRun "${SH_BIN} -c unexistcommand3241" 127 "Checking if ${SH_BIN} return 127 if command doesnt exist" + rm /tmp/unexistfile &>/dev/null + rlRun "${SH_BIN} -c 'ls /tmp/unexistfile'" 2 "Checking if ${SH_BIN} return 2 if none file" + rlRun "${SH_BIN} -c 'echo aba| sed s/a/b/g |grep -q bbb'" 0 "Checking pipes" + TT=`mktemp` + TEXT=sometihngverylong + rlRun "${SH_BIN} -c 'echo $TEXT > $TT; cat $TT |grep -q $TEXT'" 0 "Checking redirecting to file" + rlRun " ${SH_BIN} -c 'let a=1+1;echo \$a|grep -q 2'" 0 "Checking 'let' arithmetic operation 1+1" +# rlRun "${SH_BIN} -c 'sleep 100&; WC=\`jobs|wc -l\`; [[ \$WC -ge 1 ]]'" 0 "Checking process at background is running" + rlRun "${SH_BIN} $ZSH_OPT -c 'sleep 100& WC=\$(jobs|wc -l) ; [[ \$WC -ge 1 ]]'" 0 "Checking process at background is running" + + USER=${SH_BIN}user + rlRun "adduser -s /bin/${SH_BIN} $USER" 0,9 "Created user with ${SH_BIN} as default shell" + rlRun "su -l $USER -c 'echo \$PATH'" 0 "Logged as previous created user and run echo PATH" + rlPhaseEnd + + # cleanup + rlPhaseStartCleanup "Cleaning up" + rlRun "true" 0 "True action" + rlRun "rm $TT" 0 "Checking delete of $TT" + sleep 10 + rlRun "userdel $USER" 0 "Deleted user with ${SH_BIN} as default shell" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/login/Makefile b/login/Makefile new file mode 100644 index 0000000..a8bca8f --- /dev/null +++ b/login/Makefile @@ -0,0 +1,66 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/bash/Sanity/login-shell +# Description: the test creates user with bash as login shell and verified the user can log in and get th +# Author: Martin Kyral +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2016 Red Hat, Inc. +# +# This program 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 2 of +# the License, or (at your option) any later version. +# +# This program 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 this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/bash/Sanity/login-shell +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE script.exp ssh.exp tst.sh + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + test -x runtest.sh || chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Martin Kyral " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: the test creates user with bash as login shell and verified the user can log in and get th" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: ksh zsh bash dash mksh pdksh" >> $(METADATA) + @echo "Requires: bash" >> $(METADATA) + @echo "Requires: expect" >> $(METADATA) + @echo "Requires: procps-ng" >> $(METADATA) + @echo "Requires: passwd" >> $(METADATA) + @echo "Requires: openssh-clients openssh-server" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/login/PURPOSE b/login/PURPOSE new file mode 100644 index 0000000..bac1cd2 --- /dev/null +++ b/login/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/bash/Sanity/login-shell +Description: the test creates user with bash as login shell and verified the user can log in and get th +Author: Your Name diff --git a/login/runtest.sh b/login/runtest.sh new file mode 100644 index 0000000..d14b366 --- /dev/null +++ b/login/runtest.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/bash/Sanity/login-shell +# Description: the test creates user with bash as login shell and verified the user can log in and get th +# Author: Martin Kyral +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2016 Red Hat, Inc. +# +# This program 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 2 of +# the License, or (at your option) any later version. +# +# This program 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 this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGES=${PACKAGES:-"bash"} +SH_BIN=${SH_BIN:-"bash"} + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm --all + rlAssertBinaryOrigin $SH_BIN + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "cp script.exp ssh.exp tst.sh $TmpDir" + rlRun "pushd $TmpDir" + #USER=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1) + USER="user${RANDOM}" + rlRun "useradd -s /bin/${SH_BIN} -d /home/${USER} ${USER}" + rlRun "echo krava | passwd --stdin ${USER}" + rlRun "sed -i 's/shelluser/${USER}/g' script.exp" + rlRun "sed -i 's/shelluser/${USER}/g' ssh.exp" + rlRun "sed -i 's/shelluser/${USER}/g' tst.sh" + rlRun "sed -i 's/shellbin/${SH_BIN}/g' script.exp" + rlRun "sed -i 's/shellbin/${SH_BIN}/g' ssh.exp" + rlRun "sed -i 's/shellbin/${SH_BIN}/g' tst.sh" + rlRun "cp tst.sh /home/${USER}/" + rlRun "chown ${USER} /home/${USER}/tst.sh" + rlRun "mv /etc/profile.d/tps-cd.sh /root/tps-cd.sh" 0,1 "Backing tps-cd.sh up" + rlPhaseEnd + + rlPhaseStartTest + rlLog "::::: 'su -c' test :::::" + rlRun "su ${USER} -c 'echo something' | tee test1.log" 0 "echo something test" + rlLog "test1.log: $(cat test1.log)" + rlAssertGrep "something" "test1.log" + rlRun "su ${USER} -c 'echo \$0 | tee /home/${USER}/ps1.log'" 0 "shell detection test" + rlLog "ps1.log: $(cat /home/${USER}/ps1.log)" + rlAssertGrep "$SH_BIN" "/home/${USER}/ps1.log" + # the following does not work with pdksh for some reason + # not a big deal, ssh test can substitute this + [ "$SH_BIN" != "pdksh" ] && { + rlLog "::::: 'su -l' test :::::" + expect script.exp & + sleep 20 + pgrep expect && pkill expect + rlLog "test2.log: $(cat /home/${USER}/test2.log)" + rlAssertGrep "something" "/home/${USER}/test2.log" + rlLog "ps2.log: $(cat /home/${USER}/ps2.log)" + rlAssertGrep "$SH_BIN" "/home/${USER}/ps2.log" + } + rlLog "::::: ssh login test :::::" + expect ssh.exp & + sleep 20 + pgrep expect && pkill expect + rlLog "ps3.log: $(cat /home/${USER}/ps3.log)" + rlAssertGrep "$SH_BIN" "/home/${USER}/ps3.log" + rlAssertExists "/home/${USER}/tst.dat" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "mv /root/tps-cd.sh /etc/profile.d/tps-cd.sh" 0,1 "Restoring tps-cd.sh" + rlRun "su -c 'kill -9 -1' ${USER}" 0 "Killing all processes of ${USER}" + rlRun "userdel -r ${USER}" + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/login/script.exp b/login/script.exp new file mode 100644 index 0000000..127e8e0 --- /dev/null +++ b/login/script.exp @@ -0,0 +1,57 @@ +#!/usr/bin/expect -f +# +# This Expect script was generated by autoexpect on Wed Jan 13 12:41:15 2016 +# Expect and autoexpect were both written by Don Libes, NIST. +# +# Note that autoexpect does not guarantee a working script. It +# necessarily has to guess about certain things. Two reasons a script +# might fail are: +# +# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, +# etc.) and devices discard or ignore keystrokes that arrive "too +# quickly" after prompts. If you find your new script hanging up at +# one spot, try adding a short sleep just before the previous send. +# Setting "force_conservative" to 1 (see below) makes Expect do this +# automatically - pausing briefly before sending each character. This +# pacifies every program I know of. The -c flag makes the script do +# this in the first place. The -C flag allows you to define a +# character to toggle this mode off and on. + +set force_conservative 0 ;# set to 1 to force conservative mode even if + ;# script wasn't run conservatively originally +if {$force_conservative} { + set send_slow {1 .1} + proc send {ignore arg} { + sleep .1 + exp_send -s -- $arg + } +} + +# +# 2) differing output - Some programs produce different output each time +# they run. The "date" command is an obvious example. Another is +# ftp, if it produces throughput statistics at the end of a file +# transfer. If this causes a problem, delete these patterns or replace +# them with wildcards. An alternative is to use the -p flag (for +# "prompt") which makes Expect only look for the last line of output +# (i.e., the prompt). The -P flag allows you to define a character to +# toggle this mode off and on. +# +# Read the man page for more info. +# +# -Don + + +set timeout -1 +spawn "/bin/shellbin" +match_max 100000 +send -- "su -l shelluser\r" +sleep 3 +send -- "cd\r" +send -- "echo something\r" +send -- "echo something > test2.log\r" +send -- "pwd\r" +send -- "echo \$0 | tee ps2.log\r" +send -- "exit\r" +send -- "exit\r" +expect eof diff --git a/login/ssh.exp b/login/ssh.exp new file mode 100644 index 0000000..8807f79 --- /dev/null +++ b/login/ssh.exp @@ -0,0 +1,67 @@ +#!/usr/bin/expect -f +# +# This Expect script was generated by autoexpect on Mon Jan 18 05:25:00 2016 +# Expect and autoexpect were both written by Don Libes, NIST. +# +# Note that autoexpect does not guarantee a working script. It +# necessarily has to guess about certain things. Two reasons a script +# might fail are: +# +# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, +# etc.) and devices discard or ignore keystrokes that arrive "too +# quickly" after prompts. If you find your new script hanging up at +# one spot, try adding a short sleep just before the previous send. +# Setting "force_conservative" to 1 (see below) makes Expect do this +# automatically - pausing briefly before sending each character. This +# pacifies every program I know of. The -c flag makes the script do +# this in the first place. The -C flag allows you to define a +# character to toggle this mode off and on. + +set force_conservative 0 ;# set to 1 to force conservative mode even if + ;# script wasn't run conservatively originally +if {$force_conservative} { + set send_slow {1 .1} + proc send {ignore arg} { + sleep .1 + exp_send -s -- $arg + } +} + +# +# 2) differing output - Some programs produce different output each time +# they run. The "date" command is an obvious example. Another is +# ftp, if it produces throughput statistics at the end of a file +# transfer. If this causes a problem, delete these patterns or replace +# them with wildcards. An alternative is to use the -p flag (for +# "prompt") which makes Expect only look for the last line of output +# (i.e., the prompt). The -P flag allows you to define a character to +# toggle this mode off and on. +# +# Read the man page for more info. +# +# -Don + +set timeout -1 +spawn "/bin/shellbin" +match_max 100000 +expect "# " +send -- "ssh -o 'StrictHostKeyChecking no' shelluser@localhost\r" +expect "password: " +send -- "krava\r" +sleep 1 +send -- "echo \$0 | tee ps3.log\r" +send -- "\r" +send -- "(bash /home/shelluser/tst.sh &)" +expect -exact "(bash /home/shelluser/tst.sh &)" +send -- "\r" +send -- "\r" +send -- "\r" +send -- "fg\r" +send -- "\r" +send -- "\r" +send -- "\r" +send -- "ls\r" +send -- "^D" +expect "# " +send -- "^D" +expect eof diff --git a/login/tst.sh b/login/tst.sh new file mode 100644 index 0000000..b52ff72 --- /dev/null +++ b/login/tst.sh @@ -0,0 +1,4 @@ +#!/bin/shellbin + +D=$(date) +echo $D > /home/shelluser//tst.dat diff --git a/smoke/Makefile b/smoke/Makefile new file mode 100644 index 0000000..1e29977 --- /dev/null +++ b/smoke/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/bash/Sanity/smoke +# Description: Basic sanity smoke test +# Author: Miroslav Hradilek +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2012 Red Hat, Inc. +# +# This program 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 2 of +# the License, or (at your option) any later version. +# +# This program 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 this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/bash/Sanity/smoke +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE t_alias t_conditionals t_variables + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + test -x runtest.sh || chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Miroslav Hradilek " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Basic sanity smoke test" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: bash" >> $(METADATA) + @echo "Requires: bash" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/smoke/PURPOSE b/smoke/PURPOSE new file mode 100644 index 0000000..f393cb4 --- /dev/null +++ b/smoke/PURPOSE @@ -0,0 +1,8 @@ +PURPOSE of /CoreOS/bash/Sanity/smoke +Description: Basic sanity smoke test +Author: Miroslav Hradilek + +Performs basic sanity smoke test. Tries to supply commands on a +command line, variable assignment and substitution, file +expansion, "test" builtin, redirection, pipeline and some control +structures. diff --git a/smoke/runtest.sh b/smoke/runtest.sh new file mode 100644 index 0000000..28b3425 --- /dev/null +++ b/smoke/runtest.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/bash/Sanity/smoke +# Description: Basic sanity smoke test +# Author: Miroslav Hradilek +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2012 Red Hat, Inc. +# +# This program 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 2 of +# the License, or (at your option) any later version. +# +# This program 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 this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGES=${PACKAGES:-"bash"} +SH_BIN=${SH_BIN:-"bash"} + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm --all + rlAssertBinaryOrigin $SH_BIN + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "cp t_* $TmpDir/." 0 "Copying additional test files" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest + rlLog "Commandline options" + rlRun "$SH_BIN -c 'echo OK' | grep OK" 0 "Testing -c option" + + rlLog "Assorted tests" + rlRun "$SH_BIN -c 'echo \`echo OK\`' | grep OK" 0 "Testing command substitution" + [ "$SH_BIN" == "bash" ] && EXTRAPARAM="-i" + rlRun "$SH_BIN $EXTRAPARAM t_alias | grep OK" 0 "Testing alias" + rlRun "$SH_BIN -c 'echo \$((1+1))' | grep 2" 0 "Arithmetic expansion" + rlRun "$SH_BIN -c 'writedown(){ echo \$1; }; writedown OK' | grep OK" 0 "Testing function" + + rlLog "Variables" + rlRun "$SH_BIN -c 'testvar1=\"OK\"; echo \"\$testvar1\"' | grep OK" 0 "Testing variable assignment" + rlRun "$SH_BIN t_variables | grep 'default,OK'" 0 "Testing variable substitution" + rlRun "$SH_BIN -c \"cat nonexistent; echo \$?\" | grep 1" 0 "Testing predefined variable \$?" + + rlLog "File expansion" + rlRun "touch testfile" 0 "Creating test file" + rlRun "$SH_BIN -c 'echo test*' | grep testfile" 0 "Testing expansion to the test file name" + + rlLog "Builtins" + rlRun "$SH_BIN -c 'test -e testfile'" 0 "Testing test builtin" + + rlLog "Redirection and pipeline" + rlRun "$SH_BIN -c \"echo 'aBc' | grep B >redirection_out\"" 0 "Testing pipeline" + rlRun "grep 'aBc' redirection_out" 0 "Testing redirection" + + rlLog "Control structures" + rlRun "$SH_BIN -c 'for i in 1 2 3; do echo -n \$i; done' | grep 123" 0 "Testing cycle for" + rlRun "$SH_BIN t_conditionals | grep 'operator,if,else,test'" 0 "Testing if and it's && operator shorthand" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/smoke/t_alias b/smoke/t_alias new file mode 100644 index 0000000..3018bde --- /dev/null +++ b/smoke/t_alias @@ -0,0 +1,2 @@ +alias writedown='echo' +writedown OK diff --git a/smoke/t_conditionals b/smoke/t_conditionals new file mode 100644 index 0000000..a25dbec --- /dev/null +++ b/smoke/t_conditionals @@ -0,0 +1,6 @@ +true && echo -n 'operator,' +if true; then echo -n 'if,'; fi +if ! true; then echo -n 'if,'; else echo -n 'else,'; fi +if [ 'notnul' ]; then echo -n 'test'; fi + + diff --git a/smoke/t_variables b/smoke/t_variables new file mode 100644 index 0000000..91d0ec9 --- /dev/null +++ b/smoke/t_variables @@ -0,0 +1,4 @@ +testvar2=${testvar1:-default} +testvar3='OK' +testvar4=${testvar3:-default} +echo "$testvar2,$testvar4"