You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
#!/usr/bin/env bash |
|
|
|
# Functions unit tests, to test assertions. The point of an assertion is to crash if it isn't true. |
|
# Usage: |
|
# assert_equal $value1 $value2 |
|
# assert_output "./scriptname" "expected output" |
|
# assert_success $(command) |
|
# assert_failure "./scriptname" |
|
|
|
# Helper function to compare two values |
|
assert_equal() { |
|
if [ "$1" != "$2" ]; then |
|
echo "Assertion failed: $1 != $2" |
|
exit 1 |
|
fi |
|
} |
|
|
|
# Helper function to compare the output of a given command to an expected value |
|
assert_output() { |
|
local command=$1 |
|
local expected_output=$2 |
|
echo com $command |
|
echo exp $expected_output |
|
echo out $($command) |
|
if [ "$($command)" != "$expected_output" ]; then |
|
echo "Test failed: $command" |
|
exit 1 |
|
fi |
|
} |
|
|
|
# Helper function to run a command and check for a non-zero exit status |
|
assert_success() { |
|
local command=$1 |
|
|
|
if ! $command; then |
|
echo "Test failed: $command" |
|
exit 1 |
|
fi |
|
} |
|
|
|
# Helper function to run a command and check for a zero exit status |
|
assert_failure() { |
|
local command=$1 |
|
|
|
if $command; then |
|
echo "Test failed: $command" |
|
exit 1 |
|
fi |
|
}
|
|
|