-
Notifications
You must be signed in to change notification settings - Fork 57
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
Contributing assert-extras.sh #13
base: master
Are you sure you want to change the base?
Conversation
…and is 1 and not 0. This allows us to check if an assertion has passed or not without having to wrap in a '_clean' and 'assert_end' block like the current tests.sh script does. See the good usage of this new behavior in new file 'test-extras.sh' in a subsequent commit.
@@ -1,7 +1,5 @@ | |||
#!/bin/bash | |||
|
|||
set -e |
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.
We remove this because failed assertions now return an rc of 1 which would stop this test script with set -e
.
…d in quotes. This breaks commands that pass in multiline input such as the following simple examples: assert 'echo "this is a multiline echo" | wc -l | tr -d "[[:space:]]"' "2" assert 'echo -e "this\nis a multiline echo" | wc -l | tr -d "[[:space:]]"' "2" With this commit, the following tests above works.
…s should now work multi-platform.
@@ -60,7 +58,7 @@ assert "_clean; skip_if false; assert_raises true; assert_end;" \ | |||
assert "_clean; skip_if bash -c 'exit 1'; assert_raises false; assert_end;" \ | |||
"all 0 tests passed." | |||
# subshells and pipes can be used in skip as well (albeit escaped) | |||
assert "_clean; skip_if 'cat /etc/passwd | grep \$(echo \$USER)'; | |||
assert "_clean; skip_if 'id | grep \$(echo \$USER)'; |
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 also works on Mac OS X, as the user isn't guaranteed to be in /etc/passwd on Mac OS.
… as: assert_contains, assert_matches, assert_success, assert_failure.
…est run, not just in a test suite.
This totally slipped my inbox. If I ever find the time I'm going to cherry-pick the changes to assert.sh core. Did you ever put the extras somewhere else, so we could distribute this as an add-on? I'd like to keep the core repository relatively small and have helpers etc. somewhere else. |
@lehmannro I'd say that having methods such as I would at least love to have easy access to |
echo "Warning: Cannot find gnu version of command '$cmd' ($gnu_cmd) on path." \ | ||
"Falling back to standard command" >&2 | ||
fi | ||
echo "cmd" |
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 needs to be echo "$cmd"
.
Right now this doesn't work in linux. Because the command it tries to use is cmd
instead of grep
. Tests in test-extras.sh fails with:
test #1 "echo 'foo' | cmd -F 'foo'" failed:
program terminated with code 127 instead of 0
(...)
7 of 11 assert_contains tests failed in 0.111s.
6 of 9 assert_matches tests failed in 0.093s.
Further to my comment in Issue #10 I've created a contender for what assert-extras.sh may look like, at least as a starting point. I've also backed it with a new test-extras.sh file for regression tests.
I think it could be useful to accept so that people could opt into a broader set of assertions by sourcing assert-extras.sh as well as assert.sh. Those not wanting to use these would be unaffected as they wouldn't source this new file.
Also see the commit which updates assert.sh's _assert_fail() function to return an rc of 1 so that all assertions will return an rc 1 if the assertion fails which allows a program to check if an assertion has failed without having to wrap in a '_clean' and 'assert_end' block like the current tests appear to do.