-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add more handling for undefined vars #18
base: master
Are you sure you want to change the base?
Conversation
Also ensure tests are run with 'nounset' flag.
I'm not sure why, but the |
Oh, It might be because I'll check out the subshell angle and approve this if that doesn't pan out or update with that change |
It appears that it (
I also verified this by adding set -u
echo ${no_such_var} to the top of run_tests, and then running each of |
Also, each of the four shells supports a |
There's a wrinkle. Invoking a script via |
I wonder if we could add a test to verify the testing environment, something that references an undefined variable and expects itself to fail |
We could change "$SHELL" -c "SHUNIT_PARENT=$test_file $test_runner $test_file" || exit $? to SHUNIT_PARENT=$test_file "$SHELL" -u $test_file || exit $? and to ensure kcov is used, we could put the original version in an if statement. But that's getting too complicated, and I think it would be far simpler to just stick a |
It's also possible to use a here-doc to feed multi-line input to the shell's stdin, which might make it clean and easy to call |
That's another approach that will work but I think it might make the runner ( |
So I made some interesting discoveries poking at an unrelated hunch of mine:
I've gotten a test in place which verifies nounset is set in the test environment, and which also fixes the shells used to run the test. I'd like to keep your undefined variable fixes and the cleanup tests, but I think the rest of your PR is covered by what I'll be putting up soon 🙏 |
OK sounds good! Just to clarify, should I kill this PR? |
I'd say leave it open and I'll add to it. I don't want you to lose your contributions! |
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.
This looks good! I have some changes mostly around testing and removing a few things, which hopefully shouldn't be too bad to make 🙏
@@ -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 comment
The 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
createSpy foo | ||
|
||
# shellcheck disable=SC2154 | ||
assertNotNull "${_shpy_spies_dir}" |
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:
- Stubbing the
mktmp
call to return a known directory and verifying that directory is removed - Do a pattern match for a directory named
shpy.[0-9]+
, keeping in mind thatzsh
doesn't glob like other shells - Stub all the i/o functions to verify a call for a tmp directory was made and a call to rm it was made
It'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 🔍
|
||
set -o nounset | ||
|
||
cleanupSpies || fail "Should exit cleanly" |
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.
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
tearDown() {
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 comment
The 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
codehearts#18 (comment) Co-Authored-By: Katie <codehearts@users.noreply.github.com>
I've had some other priorities come up recently but I'll be returning to this next weekend |
Sounds good! I'll try getting my fixes up, it looks like there were some rather large mistakes I made with testing under different shells and getting coverage reports… |
Also ensure tests are run with 'nounset' flag.
Resolves #17