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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.