unittest
unittest
¶
Testing library
Simple unittesting library that does simple comparison. Testing library for testing if variables are commands are returning as expected.
Note
rather stable
Example
L_unittest_eq 1 1
$L_unittest_fails
¶
Integer that increases with every failed test.
$L_unittest_exit_on_error
¶
Set this variable to 1 to exit immediately when a test fails.
$L_unittest_unset_x
¶
Set this varaible to 1 to disable set -x inside L_unittest functions, Set to 0 to don't.
L_unittest_main
¶
Get all functions that start with a prefix specified with -P and execute them one by one.
Options:
-
-hhelp -
-P <prefix>Get functions with this prefix to test -
-r <regex>filter tests with regex -
-Eexit on error -
-pRun in parallel.
L_unittest_checkexit
¶
Check if command exits with specified exitcode.
Arguments:
-
$1exit code the command should exit with -
$@command to execute
Shellcheck disable= SC2035
L_unittest_success
¶
Check if command exits with 0
Argument:
$@
command to execute
L_unittest_failure
¶
Check if command exits with non zero
Argument:
$@
command to execute
L_unittest_failure_capture
¶
capture stdout and stderr into variables of a failed command
Arguments:
-
$1var stdout and stderr output -
$@command to execute
L_unittest_cmd
¶
Test execution of a command and capture and test it's stdout and/or stderr output.
Local variables used by this function start with _L_u. Options with L_uopt. This function optionally runs the command in the current shell or not depending on options.
Example
echo Hello world /tmp/1
L_unittest_cmd -r 'world' grep world /tmp/1
L_unittest_cmd -r 'No such file or directory' ! grep something not_existing_file
Options:
-
-hPrint this help and return 0. -
-cRun in current execution environment, instead of using a subshell. -
-iInvert exit status. You can also use!orL_notin front of the command. -
-IDo not close stdin <&1 . By default it is closed. -
-fExpect the command to fail. Equal to-i -j -N. -
-NRedirect stdout of the command to >/dev/null. -
-jRedirect stderr to stdout of the command. 2>&1 -
-xRun the command inside set -x -
-XDo not modify set -x -
-v <var>Store the output in variable instead of printing it. -
-r <regex>Compare output of the command with this regex. -
-o <str>Compare output of the command with this string. -
-e <int>Command should exit with this exit status (default: 0) -
-s <int>Stack up
Argument:
$@
Command to execute.
If a command starts with !, this implies -i and, if one of -v -r -o option is used, it implies -j.
L_unittest_vareq
¶
Test if a variable has specific value.
Arguments:
-
$1variable nameref -
$2value
L_unittest_eq
¶
Test if two strings are equal.
Arguments:
-
$1one string -
$2second string
L_unittest_arreq
¶
Test if array is equal to elements.
Arguments:
-
$1array variable -
$@values
L_unittest_ne
¶
Test two strings are not equal.
Arguments:
-
$1one string -
$2second string
L_unittest_regex
¶
test if a string matches regex
Arguments:
-
$1string -
$2regex
L_unittest_contains
¶
Test if a string contains other string.
Arguments:
-
$1string -
$2needle