Make wrapper work for simple usecase

This commit is contained in:
2021-12-21 02:00:48 -08:00
parent c7e09adba2
commit bb695de69f
5 changed files with 294 additions and 3 deletions

View File

@@ -2,7 +2,7 @@
try() {
output=$(mktemp -d)
"$@" > "$output/stdout" 2> "$output/stderr"
PATH="$fake_path:$PATH" "$@" > "$output/stdout" 2> "$output/stderr"
EXIT_CODE=$?
STDOUT=$(<"$output/stdout")
STDERR=$(<"$output/stderr")
@@ -14,12 +14,14 @@ setUp() {
export TMPDIR="$PWD/.generated"
export-repo-root
move-to-working-directory
create-fake-path
}
tearDown() {
[ "${_shunit_test_:=}" = '' ] && return 0
clean-up-working-directory
clean-up-fake-path
if [ "${__shunit_testSuccess:?}" != 0 ]; then
output-outputs
@@ -39,11 +41,20 @@ move-to-working-directory() {
cd $working_dir
}
create-fake-path() {
fake_path=$(mktemp -d)
invokations=$(mktemp -d)
}
clean-up-working-directory() {
cd $original_dir
rm -rf $working_dir
}
clean-up-fake-path() {
rm -rf $fake_path $invokations
}
output-outputs() {
(
bold '*******Test failed********'
@@ -61,6 +72,39 @@ bold() {
echo -e "\033[0m"
}
mock() {
command="$1"; shift
[[ -n "$1" ]] && output="$1"; shift
if ! [[ -f $fake_path/$command ]]; then
echo 'echo "$@" >> '$invokations/$command > $fake_path/$command
chmod +x $fake_path/$command
fi
if [[ -n "$output" ]]; then
echo "echo '$output'" >> $fake_path/$command
fi
}
assertCalledWithArguments() {
if ! [[ -f $invokations/$1 ]]; then
fail "$1 never invoked"
return 1
fi
if ! assertContains "$1 not invoked with expected arguments:" "$(<$invokations/$1)" "$2"; then
bold Actual invokations:
cat "$invokations/$1"
return 1
fi
}
assertNotCalled() {
if [[ -f $invokations/$1 ]]; then
fail "$1 has been invoked"
return 1
fi
}
SHUNIT_PATH=./.generated/shunit2-2.1.8/shunit2
if [ ! -f $SHUNIT_PATH ]; then (
mkdir -p .generated