Add more handling for undefined vars - #18
Conversation
Also ensure tests are run with 'nounset' flag.
I'm not sure why, but the |
codehearts
commented
Jul 26, 2019
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 |
yeeplusplus
commented
Jul 26, 2019
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 |
yeeplusplus
commented
Jul 26, 2019
Also, each of the four shells supports a |
yeeplusplus
commented
Jul 26, 2019
There's a wrinkle. Invoking a script via |
codehearts
commented
Jul 26, 2019
I wonder if we could add a test to verify the testing environment, something that references an undefined variable and expects itself to fail |
yeeplusplus
commented
Jul 26, 2019
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 |
codehearts
commented
Jul 27, 2019
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 |
yeeplusplus
commented
Jul 27, 2019
That's another approach that will work but I think it might make the runner ( |
codehearts
commented
Aug 3, 2019
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 🙏 |
yeeplusplus
commented
Aug 3, 2019
OK sounds good! Just to clarify, should I kill this PR? |
codehearts
commented
Aug 3, 2019
I'd say leave it open and I'll add to it. I don't want you to lose your contributions! |
codehearts
left a comment
There was a problem hiding this comment.
This looks good! I have some changes mostly around testing and removing a few things, which hopefully shouldn't be too bad to make 🙏
| readonly TEST_DIR="$(dirname "$0")" | ||
| set -o nounset |
There was a problem hiding this comment.
This should be removed, I set it globally for all tests in my upcoming PR
Uh oh!
There was an error while loading. Please reload this page.
| createSpy foo | ||
| # shellcheck disable=SC2154 | ||
| assertNotNull "${_shpy_spies_dir}" |
There was a problem hiding this comment.
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
mktmpcall 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 thatzshdoesn'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.
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.
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>
yeeplusplus
commented
Aug 8, 2019
I've had some other priorities come up recently but I'll be returning to this next weekend |
codehearts
commented
Aug 9, 2019
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