-
Notifications
You must be signed in to change notification settings - Fork 3
Add more handling for undefined vars #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/sh | ||
|
||
readonly TEST_DIR="$(dirname "$0")" | ||
|
||
# shellcheck source=/dev/null | ||
. "$TEST_DIR/../shpy" | ||
# shellcheck source=/dev/null | ||
. "$TEST_DIR/../shpy-shunit2" | ||
|
||
testCleanupSpies_RemovesTmpDirectory() { | ||
createSpy foo | ||
|
||
# shellcheck disable=SC2154 | ||
assertNotNull "${_shpy_spies_dir}" | ||
[ -d "${_shpy_spies_dir}" ] || fail "Temporary directory does not exist" | ||
|
||
cleanupSpies | ||
|
||
[ ! -d "${_shpy_spies_dir}" ] || fail "Temporary directory should have been removed" | ||
} | ||
|
||
testWorksUnderNoUnsetOption() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed, my upcoming PR runs all tests with nounset to ensure shpy runs under those stricter conditions |
||
[ -d "${_shpy_spies_dir}" ] && shpy_remove_dir_tree "${_shpy_spies_dir}" | ||
|
||
unset -v _shpy_spies_dir | ||
unset -v _shpy_inited | ||
|
||
set -o nounset | ||
|
||
createSpy foo | ||
|
||
cleanupSpies || fail "Should exit cleanly" | ||
} | ||
|
||
testDoesNotFailIfNoSpiesCreated() { | ||
[ -d "${_shpy_spies_dir}" ] && shpy_remove_dir_tree "${_shpy_spies_dir}" | ||
|
||
unset -v _shpy_spies_dir | ||
unset -v _shpy_inited | ||
|
||
set -o nounset | ||
|
||
cleanupSpies || fail "Should exit cleanly" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is good, but you should remove the nounset and private variable references. You shouldn't have to remove the dir tree every time, if you add a teardown function you can more-or-less ensure the test slate is clean
|
||
} | ||
|
||
|
||
# shellcheck source=/dev/null | ||
. "$TEST_DIR/shunit2" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
readonly TEST_DIR="$(dirname "$0")" | ||
|
||
set -o nounset | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be removed, I set it globally for all tests in my upcoming PR |
||
|
||
# shellcheck source=/dev/null | ||
. "$TEST_DIR/../shpy" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Private variables (those starting with an underscore, which also isn't documented anywhere…) shouldn't be used directly in testing. Instead, you could try:
mktmp
call to return a known directory and verifying that directory is removedshpy.[0-9]+
, keeping in mind thatzsh
doesn't glob like other shellsIt's likely that
$_shpy_spies_dir
reflects the directory on disk, but it's best to check for the directory itself because that's what the end user would see 🔍