Bats Operations: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 29: | Line 29: | ||
For more details, see: {{Internal|Bats_Concepts#Libraries_being_Tested_and_Helpers|Libraries being Tested and Helpers}} | For more details, see: {{Internal|Bats_Concepts#Libraries_being_Tested_and_Helpers|Libraries being Tested and Helpers}} | ||
=Handling stdout and stderr= | |||
<font color=darkgray>This is a proposed solution, I need to do more research:</font> | |||
<syntaxhighlight lang='bash'> | |||
@test "test all outputl" { | |||
local stdoutPath="${BATS_TMPDIR}/${BATS_TEST_NAME}.stdout" | |||
local stderrPath="${BATS_TMPDIR}/${BATS_TEST_NAME}.stderr" | |||
myCommandOrFunction 1>${stdoutPath} 2>${stderrPath} | |||
grep "What Im looking for in stdout" ${stdoutPath} | |||
! grep "something it cannot appear in stdout" ${stdoutPath} | |||
grep "What I'm looking for in stderr" ${stderrPath} | |||
! grep "Something it cannot appear in stderr" ${stderrPath} | |||
} | |||
</syntaxhighlight> |
Revision as of 17:13, 3 October 2019
Internal
Script to Run all .bats Tests from a Directory
#!/usr/bin/env bash
for i in $(dirname $0)/*.bats; do
echo "running $(basename ${i}) tests ..."
bats $i
done
Loading a Library to be Tested into a .bats Test
Assuming that the library you want to test is called 'blue.shlib', create a 'blue-library.bash' file in the directory that contain the .bats tests. If the library is located at a fixed relative location to the .bats test files, use this arrangement:
source ${BATS_TEST_DIRNAME}/[...]/blue.shlib
Otherwise, you can use an absolute path, but that is more fragile.
From each .bats test that wants to test functionality from that library:
load blue-library
For more details, see:
Handling stdout and stderr
This is a proposed solution, I need to do more research:
@test "test all outputl" {
local stdoutPath="${BATS_TMPDIR}/${BATS_TEST_NAME}.stdout"
local stderrPath="${BATS_TMPDIR}/${BATS_TEST_NAME}.stderr"
myCommandOrFunction 1>${stdoutPath} 2>${stderrPath}
grep "What Im looking for in stdout" ${stdoutPath}
! grep "something it cannot appear in stdout" ${stdoutPath}
grep "What I'm looking for in stderr" ${stderrPath}
! grep "Something it cannot appear in stderr" ${stderrPath}
}