- tests:import-namespace()
- tests:get-tmp-dir()
- tests:wait-file-matches()
- tests:assert-equals()
- tests:assert-stdout()
- tests:assert-stderr()
- tests:match-re()
- tests:assert-re()
- tests:assert-no-diff()
- tests:get-stdout-file()
- tests:get-stderr-file()
- tests:get-stdout()
- tests:get-stderr()
- tests:get-exitcode-file()
- tests:get-exitcode()
- tests:assert-no-diff-blank()
- tests:assert-test()
- tests:put-string()
- tests:put()
- tests:assert-stdout-empty()
- tests:assert-stderr-empty()
- tests:assert-empty()
- tests:assert-stdout-re()
- tests:assert-stderr-re()
- tests:assert-success()
- tests:assert-fail()
- tests:assert-exitcode()
- tests:not()
- tests:silence()
- tests:fail()
- tests:describe()
- tests:debug()
- tests:cd()
- tests:eval()
- tests:runtime()
- tests:pipe()
- tests:value()
- tests:ensure()
- tests:make-tmp-dir()
- tests:cd-tmp-dir()
- tests:run-background()
- tests:get-background-pid()
- tests:get-background-stdout()
- tests:get-background-stderr()
- tests:stop-background()
- tests:wait-file-changes()
- tests:set-verbose()
- tests:get-verbose()
- tests:clone()
- tests:involve()
- tests:require()
Make all functions from tests.sh available without 'tests:' prefix. Prefix can be also user defined, like 't:'.
- $1 (string): Custom prefix for namespace functions.
Returns temporary directory for current test session.
It can be used as a workspace for the testcase.
ls $(tests:get-tmp-dir)
- Path to temp dir, e.g., /tmp/tests.XXXX
Suspends testcase execution until file contents matches pattern or timeout is reached.
Can be used to check if background-executed command output do not contains any error messages.
stderr=$(tests:get-background-stderr $command_id)
tests:wait-file-not-matches "$stderr" "ERROR" 1 2
- $1 (string): Path to file.
- $2 (regexp): Regexp, same as in
grep -E
. - $3 (int): Interval of time to check changes after.
- $4 (int): Timeout in seconds.
Asserts, that first string arg is equals to second.
tests:assert-equals 1 2 # fails
- $1 (string): Expected string.
- $2 (string): Actual value.
Asserts, that last evaluated command's stdout contains given string.
tests:eval echo 123
tests:assert-stdout 123
- $1 (string): Expected stdout.
Asserts, that last evaluated command's stderr contains given string.
tests:eval echo 123 '1>&2' # note quoting
tests:assert-stderr 123
- $1 (string): Expected stderr.
Compares, that last evaluated command output (stdout, stderr) or file contents matches regexp.
tests:eval echo aaa
tests:match-re stdout a.a
echo $? # 0
tests:match-re stdout a.b
echo $? # 1
- $1 ('stdout'|'stderr'|filename): If 'stdout' or 'stderr' is used, use
- $2 (regexp): Regexp to match, same as in grep.
Same as 'tests:match-re', but abort testing if comparison failed.
tests:eval echo aaa
tests:assert-re stdout a.a
tests:assert-re stdout a.b # test fails there
- tests:match-re
Asserts, that there are no diff on the last command output (stderr or stdout), or on string or on specified file with specified string or file.
tests:eval echo -e '1\n2'
tests:assert-no-diff stdout "$(echo -e '1\n2')" # note quotes
tests:assert-no-diff stdout "$(echo -e '1\n3')" # test will fail
- $1 (string|filename): Expected value.
- $2 ('stdout'|'stderr'|string|filename): Actual value.
- ... (any): Additional arguments for diff.
Returns file containing stdout of last command.
tests:eval echo 123
cat $(tests:get-stdout-file) # will echo 123
- Filename containing stdout.
Returns file containing stderr of last command.
tests:eval echo 123 '1>&2' # note quotes
cat $(tests:get-stderr) # will echo 123
- Filename containing stderr.
Returns contents of the stdout of last command.
tests:eval echo 123
tests:get-stdout # will echo 123
- Stdout for last command.
Returns contents of the stderr of last command.
tests:eval echo 123 '>&2'
tests:get-stderr # will echo 123
- Stderr for last command.
Returns file containing exitcode of last command.
tests:eval exit 220
cat $(tests:get-exitcode-file) # will echo 220
- Filename containing exitcode.
Returns exitcode of last command.
tests:eval exit 220
tests:get-exitcode # will echo 220
- Filename containing exitcode.
Same as 'tests:assert-diff', but ignore changes whose lines are all blank.
tests:eval echo -e '1\n2'
tests:assert-no-diff-blank stdout "$(echo -e '1\n2')" # note quotes
tests:assert-no-diff-blank stdout "$(echo -e '1\n\n2')" # test will pass
- tests:diff
Same as shell 'test' function, but asserts, that exit code is zero.
tests:assert-test 1 -eq 1
tests:assert-test 1 -eq 2 # test will fail
- ... (Arguments): for 'test' function.
Put specified contents into temporary file with given name.
tests:put-string xxx "lala"
- $1 (filename): Temporary file name.
- $2 (string): Contents to put.
Put stdin into temporary file with given name.
tests:put xxx <<EOF
1
2
3
EOF
- $1 (filename): Temporary file name.
Asserts that stdout is empty.
tests:eval echo ""
Function has no arguments.
Asserts that stderr is empty.
tests:eval echo "" '1>&2'
Function has no arguments.
Asserts that target is empty.
tests:eval echo ""
Function has no arguments.
Asserts that stdout of last evaluated command matches given regexp.
tests:eval echo 123
- $1 (regexp): Regexp, same as in grep.
Asserts as 'tests:assert-stdout-re', but stderr used instead of stdout.
tests:eval echo 123 '1>&2' # note quotes
- $1 (regexp): Regexp, same as in grep.
Asserts that last evaluated command exit status is zero.
tests:eval true
tests:assert-success
Function has no arguments.
Asserts that last evaluated command exit status is not zero.
Basically, alias for test:not tests:assert-success
.
tests:eval false
tests:assert-fail
Function has no arguments.
Asserts that exit code of last evaluated command equals to specified value.
tests:eval false
tests:assert-exitcode 1
- $1 (int): Expected exit code.
Negates passed assertion.
tests:eval false
tests:assert-fail
tests:not tests:assert-success
- ... (any): Command to evaluate.
Prevets eval command to print stdout/stderr.
tests:silence tests:eval rm -r blah
- ... (any): Command to evaluate.
Output message and fail current testcase immideately.
- ... (any): String to output.
Same as tests:debug(), but colorize output for better vizibility.
- ... (any): String to output.
Print specified string in the debug log.
tests:debug "hello from debug" # will shown only in verbose mode
- ... (any): String to echo.
Changes working directory to specified directory.
- $1 (directory): Directory to change to.
Evaluates specified string via shell 'eval'.
Redirection syntax differs from what can be found in bash.
Redirection operators will be used as redirection only if they are
passed as separate argumentm, like this: tests:eval echo 1 '>' 2
.
List of redirection operators:
>
<
>&
<&
>&n
, wheren
is a number<&n
, wheren
is a number>>
<<<
<>
|
To redirect output to file use: > filename
(note space).
Also, if only one argument is passed to tests:eval
, the it will
be evaled as is. So, tests:eval "echo 1 > 2"
will create file 2
,
but tests:eval echo "1 > 2"
will only output 1 > 2
to the stdout.
NOTE: you will not get any stdout or stderr from evaluated command.
To obtain stdout or stderr see tests:pipe
.
NOTE: output will be buffered! If you want unbuffered output, use
tests:runtime
.
NOTE: use of that function will not produce any output to stdout
nor stderr. If you want to pipe your result to something, use
tests:pipe
.
tests:eval echo 123 "# i'm comment"
tests:eval echo 123 \# i\'m comment
tests:eval echo 567 '1>&2' # redirect to stderr
tests:eval echo 567 1\>\&2' # same
- ... (string): String to evaluate.
- tests:pipe
- tests:runtime
Same, as tests:pipe
, but produce unbuffered result.
tests:runtime 'echo 1; sleep 10; echo 2' # see 1 immediately
- ... (string): String to evaluate.
- tests:eval
Same, as tests:eval
, but return stdout and stderr
as expected.
lines=$(tests:eval echo 123 | wc -l) # note not escaped pipe
tests:assert-equals $lines 1
- ... (string): String to evaluate.
- tests:eval
Same, as tests:eval
, but writes stdout into given variable and
return stderr as expected.
_x() {
echo "y [$@]"
}
tests:value response _x a b c
tests:assert-equals "$response" "y [a b c]"
- $1 (string): Variable name.
- ... (string): String to evaluate.
- tests:eval
Eval specified command and assert, that it has zero exitcode.
tests:esnure true # will pass
tests:esnure false # will fail
- ... (any): Command to evaluate.
Creates temporary directory.
- ... (any): Same as for mkdir command.
Changes working directory to the specified temporary directory, previously created by 'tests:make-tmp-dir'.
- $1 (string): Directory name.
Runs any command in background, this is very useful if you test some running service.
Processes which are ran by 'tests:background' will be killed on cleanup state, and if test failed, stderr and stdout of all background processes will be printed.
- $1 (variable): Name of variable to store BG process ID.
- ... (string): Command to start.
Returns pid of specified background process.
- $1 (string): Process ID, returned from 'tests:run-background'.
- Pid of background process.
Returns stdout of specified background process.
- $1 (string): Process ID, returned from 'tests:run-background'.
- Stdout from background process.
Returns stderr of specified background process.
- $1 (string): Process ID, returned from 'tests:run-background'.
- Stderr from background process.
Stops background process with 'kill -TERM'.
- $1 (string): Process ID, returned from 'tests:run-background'.
Waits, until specified file will be changed or timeout passed after executing specified command.
- $1 (string): Command to evaluate.
- $2 (filename): Filename to wait changes in.
- $3 (int): Interval of time to check changes after.
- $4 (int): Timeout in seconds.
Sets verbosity of testcase output.
- $1 (int): Verbosity.
Gets current verbosity level.
Function has no arguments.
- Current verbosity.
Copy specified file or directory from the testcases dir to the temporary test directory.
- ... (any): Same args, as for cp commmand.
Copy specified file from testcases to the temporary test directory and then source it.
- $1 (filename): Filename to copy and source.
- $2 (filename): Destination under test dir (not required).
Source file with debug.
- $1 (filename): Filename to source.