2021-12-21 02:44:51 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
testUsageIsShownWhenNoCommandIsSpecified() {
|
|
|
|
echo '
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
' > go
|
2021-12-21 06:48:10 +00:00
|
|
|
echo "source $REPO_ROOT/⚡" >> go
|
2021-12-21 02:44:51 +00:00
|
|
|
chmod +x go
|
|
|
|
|
|
|
|
try ./go
|
|
|
|
assertContains "$STDOUT" "Usage"
|
|
|
|
}
|
|
|
|
|
|
|
|
testHelpSubcommandCannotBeOverridden() {
|
|
|
|
echo '
|
|
|
|
#!/usr/bin/env bash
|
2021-12-21 06:48:10 +00:00
|
|
|
⚡help() { echo "ah hah hah" ; }
|
2021-12-21 02:44:51 +00:00
|
|
|
' > go
|
2021-12-21 06:48:10 +00:00
|
|
|
echo "source $REPO_ROOT/⚡" >> go
|
2021-12-21 02:44:51 +00:00
|
|
|
chmod +x go
|
|
|
|
|
|
|
|
try ./go help
|
|
|
|
assertContains "$STDOUT" "Usage"
|
|
|
|
}
|
|
|
|
|
|
|
|
testHelpIncludesInvocationInstructions() {
|
|
|
|
SCRIPT_NAME="foo-$RANDOM"
|
|
|
|
echo '
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
' > $SCRIPT_NAME
|
2021-12-21 06:48:10 +00:00
|
|
|
echo "source $REPO_ROOT/⚡" >> $SCRIPT_NAME
|
2021-12-21 02:44:51 +00:00
|
|
|
chmod +x $SCRIPT_NAME
|
|
|
|
|
|
|
|
try ./$SCRIPT_NAME help
|
|
|
|
assertContains "$STDOUT" "$SCRIPT_NAME SUBCOMMAND"
|
|
|
|
}
|
|
|
|
|
|
|
|
testHelpListsAllAvailableLightningCommands() {
|
|
|
|
echo '
|
|
|
|
#!/usr/bin/env bash
|
2021-12-21 06:48:10 +00:00
|
|
|
⚡foo() { echo "ah hah hah" ; }
|
|
|
|
⚡bar() { echo "ah hah hah" ; }
|
|
|
|
⚡baz() { echo "ah hah hah" ; }
|
|
|
|
⚡potato() { echo "ah hah hah" ; }
|
2021-12-21 02:44:51 +00:00
|
|
|
' > go
|
2021-12-21 06:48:10 +00:00
|
|
|
echo "source $REPO_ROOT/⚡" >> go
|
2021-12-21 02:44:51 +00:00
|
|
|
chmod +x go
|
|
|
|
|
|
|
|
try ./go help
|
|
|
|
assertContains "$STDOUT" "foo"
|
|
|
|
assertContains "$STDOUT" "bar"
|
|
|
|
assertContains "$STDOUT" "baz"
|
|
|
|
assertContains "$STDOUT" "potato"
|
|
|
|
assertContains "$STDOUT" "help"
|
|
|
|
}
|
|
|
|
|
|
|
|
testHelpLinesFromDefinedCommandsAreShown() {
|
|
|
|
echo '
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-12-21 06:48:10 +00:00
|
|
|
⚡hello() {
|
2021-12-21 19:19:51 +00:00
|
|
|
_help-line "Say Hello"
|
2021-12-21 02:44:51 +00:00
|
|
|
echo "Hello, World!" ;
|
|
|
|
}
|
|
|
|
' > go
|
|
|
|
|
2021-12-21 06:48:10 +00:00
|
|
|
echo "source $REPO_ROOT/⚡" >> go
|
2021-12-21 02:44:51 +00:00
|
|
|
chmod +x go
|
|
|
|
|
|
|
|
try ./go
|
|
|
|
assertContains "$STDOUT" "Say Hello"
|
|
|
|
}
|
|
|
|
|
|
|
|
testHelpDoesNotExecuteFunctionsWithNoHelpLine() {
|
|
|
|
echo '
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-12-21 06:48:10 +00:00
|
|
|
⚡hello() { echo "Hello, World!" ; }
|
2021-12-21 02:44:51 +00:00
|
|
|
' > go
|
|
|
|
|
2021-12-21 06:48:10 +00:00
|
|
|
echo "source $REPO_ROOT/⚡" >> go
|
2021-12-21 02:44:51 +00:00
|
|
|
chmod +x go
|
|
|
|
|
|
|
|
try ./go
|
|
|
|
assertNotContains "$STDOUT" "Hello, World"
|
|
|
|
}
|
|
|
|
|
|
|
|
testLightningShouldNotBeIncludedInSubcommandNames() {
|
|
|
|
echo '
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-12-21 06:48:10 +00:00
|
|
|
⚡hello() { echo "Hello, World!" ; }
|
2021-12-21 02:44:51 +00:00
|
|
|
' > go
|
|
|
|
|
2021-12-21 06:48:10 +00:00
|
|
|
echo "source $REPO_ROOT/⚡" >> go
|
2021-12-21 02:44:51 +00:00
|
|
|
chmod +x go
|
|
|
|
|
|
|
|
try ./go
|
2021-12-21 06:48:10 +00:00
|
|
|
assertNotContains "$STDOUT" "⚡hello"
|
2021-12-21 02:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
source $(dirname $0)/runner
|