Blob Blame History Raw
#!/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/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"
            # Without this there might be some issue when starting background
            echo "unsetopt monitor" >> /etc/zshrc
        else
            ZSH_OPT=""
        fi
    rlPhaseEnd

    rlPhaseStartTest "Test of functions"
        rlRun "${SH_BIN} -c 'true'" 0 "True action"
        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"
        if [ $SH_BIN != "dash" ]; then
            rlRun " ${SH_BIN} -c 'let a=1+1;echo \$a|grep -q 2'" 0 "Checking 'let' arithmetic operation 1+1"
        fi
        rlRun "${SH_BIN} $ZSH_OPT -c 'sleep 100 & jobs > jobs.out; WC=\$(cat jobs.out|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

    rlPhaseStartCleanup "Cleaning up"
        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