Blob Blame History Raw
#!/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 <mhradile@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   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/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