Skip to content

Commit

Permalink
start on some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
marcmengel committed Dec 13, 2024
1 parent 240d3e6 commit e42cec3
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/test_bootstrap.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

. ./unittest.bash

setup_1() {
case "x$0" in
x/*) export testdir=$(dirname $0)
;;
x./*) export testdir=$(dirname $(dirname $PWD/$0))
;;
*) export testdir=$(dirname $PWD/$0)
;;
esac
export prefix=$(dirname $testdir)
export workdir=${TMPDIR:-/tmp}/$USER/work$$
mkdir -p $workdir
export PATH=$prefix/bin:$PATH
echo "setup_1: set workdir=$workdir, PATH=$PATH"
}


test_bootstrap_help() {
bootstrap --help > $workdir/out_help 2>&1

# match the options in the output, should get all 6
chk_re='[-]-(query-packages|with_padding|fermi_spack_tools_release|fermi_spack_tools_repo|fermi_spack_tools_release|spack_release|spack_repo)'
test $(egrep "$chk_re" $workdir/out_help | wc -l) = 6
}

test_bootstrap_std() {
bootstrap \
--with_padding \
$workdir/sp_tst_std

test -r $workdir/sp_tst_std/setup-env.sh
}

test_bootstrap_xmastree() {
bootstrap \
--query-packages \
--with_padding \
--fermi_spack_tools_release main \
--fermi_spack_tools_repo https://github.com/FNALssi/fermi-spack-tools.git \
--spack_release HEAD \
--spack_repo https://github.com/FNALssi/spack.git \
$workdir/sp_tst_xmas

test -r $workdir/sp_tst_xmas/setup-env.sh
}

testsuite boot_tst -s setup_1 test_bootstrap_help test_bootstrap_std test_bootstrap_xmastree

boot_tst "$@"
104 changes: 104 additions & 0 deletions tests/unittest.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@


testsuite() {
exec 3>&1 # so tests can put ouput to &3
local suitename
suitename=$1
shift

eval ${suitename}_test_list=""
while [ $# -gt 0 ]
do
case "x$1" in
x-s) eval ${suitename}_test_setup=$2; shift; shift;;
x-t) eval ${suitename}_test_teardown=$2; shift; shift;;
x*) eval ${suitename}_test_list=\"\$${suitename}_test_list $1\"; shift;;
esac
done

local def
def="
${suitename}() {
local siglist=\"RETURN 0 1 2 3 4 5 6 7 8 10 11\"
local verbose=\$1
local n_tests
local n_fails
echo 'in $suitename verbose: \$verbose'
if [ x\$verbose = "x--only" ]
then
${suitename}_test_list=\"\$2\"
verbose=\$3
fi
trap wrapup \$siglist
: > ${TMPDIR:-/tmp}/test_out_$$
n_tests=0
n_fails=0
for _t in \$${suitename}_test_list
do
n_tests=\$(( n_tests + 1 ))
if [ x\$verbose = "x-v" -o x\$verbose = "x-vv" ]
then
printf '%s \t...' \$_t
fi
\$${suitename}_test_setup > ${TMPDIR:-/tmp}/setup_out\$n_tests 2>&1
if \$_t > ${TMPDIR:-/tmp}/test_case_out_\$\$ 2>&1
then
if [ x\$verbose = "x-v" -o x\$verbose = "x-vv" ]
then
echo ok
else
printf .
fi
if [ x\$verbose = "x-vv" ]
then
echo ============================== >> ${TMPDIR:-/tmp}/test_out_$$
echo PASS: \$_t >> ${TMPDIR:-/tmp}/test_out_$$
echo ---------------- >> ${TMPDIR:-/tmp}/test_out_$$
cat ${TMPDIR:-/tmp}/test_case_out_\$\$ >> ${TMPDIR:-/tmp}/test_out_$$
echo ---------------- >> ${TMPDIR:-/tmp}/test_out_$$
fi
else
n_fails=\$(( n_fails + 1 ))
if [ x\$verbose = "x-v" -o x\$verbose = "x-vv" ]
then
echo FAIL
else
printf F
fi
echo ============================== >> ${TMPDIR:-/tmp}/test_out_$$
echo FAIL: \$_t >> ${TMPDIR:-/tmp}/test_out_$$
echo ---------------- >> ${TMPDIR:-/tmp}/test_out_$$
cat ${TMPDIR:-/tmp}/test_case_out_\$\$ >> ${TMPDIR:-/tmp}/test_out_$$
echo ---------------- >> ${TMPDIR:-/tmp}/test_out_$$
fi
\$${suitename}_test_teardown > /dev/null 2>&1
done
echo
}
"
#echo "def is $def"
eval "$def"
}

wrapup() {
echo
echo ==================================
cat /tmp/test_out_$$
echo ==================================
echo Ran $n_tests tests with $n_fails failures
if [ $n_fails = 0 ]
then
echo "ok"
else
echo "FAILED"
false
fi
rm -f ${TMPDIR:-/tmp}/test_out_$$ ${TMPDIR:-/tmp}/test_case_out$$
trap "" $siglist
echo 'return trap'
}

0 comments on commit e42cec3

Please sign in to comment.