Blame tests/p_abrt-cli/_lib.sh

Matej Habrnal e4efea
#!/bin/bash
Matej Habrnal e4efea
# Author: Matej Habrnal <mhabrnal@redhat.com>
Matej Habrnal e4efea
Matej Habrnal e4efea
LOG_FILE=test.log
Matej Habrnal e4efea
LOG_SEPARATOR='----------------------------------------------------'
Matej Habrnal e4efea
Matej Habrnal e4efea
QUERIES_DIR="."
Matej Habrnal e4efea
Matej Habrnal e4efea
function createSeparator
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    sep="$LOG_SEPARATOR\n"
Matej Habrnal e4efea
    sep+="$1"
Matej Habrnal e4efea
    sep+="\n"
Matej Habrnal e4efea
    sep+="$LOG_SEPARATOR\n"
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function log
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    echo -e "$1"
Matej Habrnal e4efea
    echo -e "$1" >> $LOG_FILE
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function logWithSeparator
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    createSeparator "$1"
Matej Habrnal e4efea
    log "$sep"
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
# logResult returnCode message
Matej Habrnal e4efea
function logResult
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    if [[ $1 == 0 ]]; then
Matej Habrnal e4efea
        log "PASS : $2\n"
Matej Habrnal e4efea
    else
Matej Habrnal e4efea
        log "FAIL : $2\n"
Matej Habrnal e4efea
    fi
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function rlJournalStart
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    return 0
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function rlPhaseStartSetup
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    return 0
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function rlPhaseStartTest
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    logWithSeparator "$1"
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function rlPhaseEnd
Matej Habrnal e4efea
{
Matej Habrnal e4efea
#logWithSeparator "rlPhaseEnd"
Matej Habrnal e4efea
    return 0
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function rlRun
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    local command=$1
Matej Habrnal e4efea
    local expected_orig=${2:-0}
Matej Habrnal e4efea
    local expected=${2:-0}
Matej Habrnal e4efea
    local comment
Matej Habrnal e4efea
    local comment_begin
Matej Habrnal e4efea
    if [[ -z "$3" ]]; then
Matej Habrnal e4efea
      comment_begin="Running '$command'"
Matej Habrnal e4efea
      comment="Command '$command'"
Matej Habrnal e4efea
    else
Matej Habrnal e4efea
      comment_begin="$3 :: actually running '$command'"
Matej Habrnal e4efea
      comment="$3"
Matej Habrnal e4efea
    fi
Matej Habrnal e4efea
Matej Habrnal e4efea
    echo "$comment_begin" "BEGIN"
Matej Habrnal e4efea
Matej Habrnal e4efea
    eval "$command"
Matej Habrnal e4efea
    local exitcode=$?
Matej Habrnal e4efea
Matej Habrnal e4efea
    echo "rlRun: command = '$command'; exitcode = $exitcode; expected = $expected"
Matej Habrnal e4efea
    if [[ $exitcode == $expected ]]; then
Matej Habrnal e4efea
        retval=0
Matej Habrnal e4efea
    else
Matej Habrnal e4efea
        retval=1
Matej Habrnal e4efea
    fi
Matej Habrnal e4efea
Matej Habrnal e4efea
    logResult $retval "$command"
Matej Habrnal e4efea
    return $retval
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function rlAssertGrep
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    if [ ! -e "$2" ] ; then
Matej Habrnal e4efea
        echo "rlAssertGrep: failed to find file $2"
Matej Habrnal e4efea
        return 2
Matej Habrnal e4efea
    fi
Matej Habrnal e4efea
    local options=${3:--q}
Matej Habrnal e4efea
    grep $options "$1" "$2"
Matej Habrnal e4efea
Matej Habrnal e4efea
    local exitcode=$?
Matej Habrnal e4efea
    command="File '$2' should contain '$1'"
Matej Habrnal e4efea
    echo $command
Matej Habrnal e4efea
Matej Habrnal e4efea
    logResult $exitcode "$command"
Matej Habrnal e4efea
    return $exitcode
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function rlAssertNotGrep
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    if [ ! -e "$2" ] ; then
Matej Habrnal e4efea
        echo "rlAssertGrep: failed to find file $2"
Matej Habrnal e4efea
        return 2
Matej Habrnal e4efea
    fi
Matej Habrnal e4efea
    local options=${3:--q}
Matej Habrnal e4efea
    grep $options "$1" "$2"
Matej Habrnal e4efea
Matej Habrnal e4efea
    local exitcode=$?
Matej Habrnal e4efea
    if [ $exitcode == 0 ]; then
Matej Habrnal e4efea
        exitcode=1
Matej Habrnal e4efea
    else
Matej Habrnal e4efea
        exitcode=0
Matej Habrnal e4efea
    fi
Matej Habrnal e4efea
Matej Habrnal e4efea
    command="File '$2' should not contain '$1'"
Matej Habrnal e4efea
    echo $command
Matej Habrnal e4efea
Matej Habrnal e4efea
    logResult $exitcode "$command"
Matej Habrnal e4efea
    return $exitcode
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function rlPhaseStartCleanup
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    logWithSeparator "rlPhaseStartCleanup"
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function rlBundleLogs
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    local pass_count=`grep 'PASS' $LOG_FILE | wc -l`
Matej Habrnal e4efea
    local fail_count=`grep 'FAIL' $LOG_FILE | wc -l`
Matej Habrnal e4efea
Matej Habrnal e4efea
    log $LOG_SEPARATOR
Matej Habrnal e4efea
    log "TEST STATUS"
Matej Habrnal e4efea
    log "PASS: $pass_count"
Matej Habrnal e4efea
    log "FAIL: $fail_count"
Matej Habrnal e4efea
    log "TOTAL: $(( $pass_count + $fail_count))"
Matej Habrnal e4efea
    log $LOG_SEPARATOR
Matej Habrnal e4efea
Matej Habrnal e4efea
    if [[ $fail_count == 0 ]]; then
Matej Habrnal e4efea
        test_return_value=0
Matej Habrnal e4efea
    else
Matej Habrnal e4efea
        test_return_value=1
Matej Habrnal e4efea
    fi
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function rlJournalPrintText
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    return 0
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function rlJournalEnd
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    t_CheckExitStatus $test_return_value
Matej Habrnal e4efea
}