Run each test in a clean directory
This commit is contained in:
parent
4f70443bda
commit
f679a866f1
23
test/runner
23
test/runner
@ -12,15 +12,38 @@ try() {
|
||||
|
||||
setUp() {
|
||||
export TMPDIR="$PWD/.generated"
|
||||
export-repo-root
|
||||
move-to-working-directory
|
||||
}
|
||||
|
||||
tearDown() {
|
||||
[ "${_shunit_test_:=}" = '' ] && return 0
|
||||
|
||||
clean-up-working-directory
|
||||
|
||||
if [ "${__shunit_testSuccess:?}" != 0 ]; then
|
||||
output-outputs
|
||||
fi
|
||||
}
|
||||
|
||||
export-repo-root() {
|
||||
export REPO_ROOT="$PWD"
|
||||
while ! [[ -d $REPO_ROOT/.git ]]; do
|
||||
export REPO_ROOT=$(dirname $REPO_ROOT)
|
||||
done
|
||||
}
|
||||
|
||||
move-to-working-directory() {
|
||||
original_dir="$PWD"
|
||||
working_dir=$(mktemp -d)
|
||||
cd $working_dir
|
||||
}
|
||||
|
||||
clean-up-working-directory() {
|
||||
cd $original_dir
|
||||
rm -rf $working_dir
|
||||
}
|
||||
|
||||
output-outputs() {
|
||||
(
|
||||
bold '*******Test failed********'
|
||||
|
@ -4,7 +4,7 @@ testUsageIsShownWhenNoCommandIsSpecified() {
|
||||
echo '
|
||||
#!/usr/bin/env bash
|
||||
' > go
|
||||
echo "source $(dirname $BASH_SOURCE)/../⚡️" >> go
|
||||
echo "source $REPO_ROOT/⚡️" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go
|
||||
@ -16,7 +16,7 @@ testHelpSubcommandCannotBeOverridden() {
|
||||
#!/usr/bin/env bash
|
||||
⚡️help() { echo "ah hah hah" ; }
|
||||
' > go
|
||||
echo "source $(dirname $BASH_SOURCE)/../⚡️" >> go
|
||||
echo "source $REPO_ROOT/⚡️" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go help
|
||||
@ -28,7 +28,7 @@ testHelpIncludesInvocationInstructions() {
|
||||
echo '
|
||||
#!/usr/bin/env bash
|
||||
' > $SCRIPT_NAME
|
||||
echo "source $(dirname $BASH_SOURCE)/../⚡️" >> $SCRIPT_NAME
|
||||
echo "source $REPO_ROOT/⚡️" >> $SCRIPT_NAME
|
||||
chmod +x $SCRIPT_NAME
|
||||
|
||||
try ./$SCRIPT_NAME help
|
||||
@ -43,7 +43,7 @@ testHelpListsAllAvailableLightningCommands() {
|
||||
⚡️baz() { echo "ah hah hah" ; }
|
||||
⚡️potato() { echo "ah hah hah" ; }
|
||||
' > go
|
||||
echo "source $(dirname $BASH_SOURCE)/../⚡️" >> go
|
||||
echo "source $REPO_ROOT/⚡️" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go help
|
||||
@ -64,7 +64,7 @@ testHelpLinesFromDefinedCommandsAreShown() {
|
||||
}
|
||||
' > go
|
||||
|
||||
echo "source $(dirname $BASH_SOURCE)/../⚡️" >> go
|
||||
echo "source $REPO_ROOT/⚡️" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go
|
||||
@ -78,7 +78,7 @@ testHelpDoesNotExecuteFunctionsWithNoHelpLine() {
|
||||
⚡️hello() { echo "Hello, World!" ; }
|
||||
' > go
|
||||
|
||||
echo "source $(dirname $BASH_SOURCE)/../⚡️" >> go
|
||||
echo "source $REPO_ROOT/⚡️" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go
|
||||
@ -92,7 +92,7 @@ testLightningShouldNotBeIncludedInSubcommandNames() {
|
||||
⚡️hello() { echo "Hello, World!" ; }
|
||||
' > go
|
||||
|
||||
echo "source $(dirname $BASH_SOURCE)/../⚡️" >> go
|
||||
echo "source $REPO_ROOT/⚡️" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go
|
||||
|
@ -7,7 +7,7 @@ testDefiningALightningFunctionWorks() {
|
||||
⚡️hello() { echo "Hello, World!" ; }
|
||||
' > go
|
||||
|
||||
echo "source $(dirname $BASH_SOURCE)/../⚡️" >> go
|
||||
echo "source $REPO_ROOT/⚡️" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go hello
|
||||
|
Loading…
Reference in New Issue
Block a user