1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#!/bin/bash
#
# Copyright (C) 2012-2015 SUSE Linux GmbH
#
# Author:
# Frank Sundermeyer <fsundermeyer at opensuse dot org>
#
# Testing DAPS: Common functions
#
# ---------
# Usage
#
function usage () {
echo "Something useful"
}
# --------
# Clean up the build directory
# Arguments:
# all: completely removes the build directory (${_DOC_DIR}/build)
# fo: remove FO files (${_DOC_DIR}/build/.tmp/*.fo)
# images: remove the images directory (${_DOC_DIR}/build/.images)
# profiles: remove profiling directories (${_DOC_DIR}/build/.profiled)
# results: remove build results (${_DOC_DIR}/build/$_BOOKNAME)
# tmp: remove temp directory (${_DOC_DIR}/build/.tmp)
#
function clean_build_dir () {
[[ -d "${_DOC_DIR}" ]] || (echo "Attempting to delete an empty directory" && exit 1)
[[ -z $1 ]] && (echo "You must specify a parameter for the clean buildir function" && exit 1)
case $1 in
all)
rm -rf "${_DOC_DIR}/build"
;;
fo)
rm -f "${_DOC_DIR}/build/.tmp/"*.fo
;;
images)
rm -rf "${_DOC_DIR}/build/.images"
;;
profiles)
rm -rf "${_DOC_DIR}/build/.profiled"
;;
results)
rm -rf "${_DOC_DIR}/build/$_BOOKNAME"
;;
tmp)
rm -rf "${_DOC_DIR}/build/.tmp"
;;
*)
exit_on_error "Wrong parameter for function cleandir"
;;
esac
}
# ---------
# Verbose error handling
#
function exit_on_error () {
echo -e "ERROR: ${1}" >&2
clean_build_dir all
exit 1;
}
# ---------
# Print Test Header
#
function header () {
echo
echo "Test: $1"
echo "=================================================="
}
# ---------
# Create tempdir
#
function make_tempdir () {
# Expects variable name and sets it to the path of the generated temp dir
local _TMPDIR
[[ -z $1 ]] && exit_on_error "${FUNCNAME[0]} was called with a empty parameter"
_TMPDIR=$(mktemp -d -q ${SHUNIT_TMPDIR}/XXXXXXXXXX)
if [ $? -eq 0 ]; then
eval "$1='$_TMPDIR'"
else
exit_on_error " Creating a temporary directory failed. Skipping tests"
fi
}
# --------
# Collect overall stats
#
function stats () {
_FAILED=$(cat ${_TEMPDIR}/failed)
_SKIPPED=$(cat ${_TEMPDIR}/skipped)
_TOTAL=$(cat ${_TEMPDIR}/total)
echo "$(( _FAILED + __shunit_assertsFailed ))" > ${_TEMPDIR}/failed
echo "$(( _SKIPPED + __shunit_assertsSkipped ))" > ${_TEMPDIR}/skipped
echo "$(( _TOTAL + __shunit_testsTotal ))" > ${_TEMPDIR}/total
}
|