Assertion library for shell scripting.
#!/usr/bin/env import
import [email protected]
assert_equal foo bar
# assertion error: foo = bar
message
- Optional message to print for the assertion failure. Prints the actual test if not specified.
Tests the given expression using bracket notation. This is very similar to the
built in test
command, except that the an "assertion failed" message is printed
to stderr upon failure.
Returns 0 if the test passes, or 1 if the test fails.
#!/usr/bin/env import
import [email protected]
assert 1 -eq 2
# assertion error: 1 -eq 2
message="one does not equal two" assert 1 -eq 2
# assertion error: one does not equal two
Tests that the the actual value is equal to the expected value. Strings or
numbers may be used interchangeably, since the =
operator is used under the
hood.
#!/usr/bin/env import
import [email protected]
assert_equal foo bar
# assertion error: foo = bar
Tests that the given command
exits with the specified exit_code
.
#!/usr/bin/env import
import [email protected]
# Passes
assert_exit 0 true
# This will fail
assert_exit 6 sh -c "exit 7"
# assertion failed: `sh -c exit 7` exited with 0, not 6