This is liable to change in the future.
sh_test() is a test rule that can pass results to the test runner by invoking a shell script.
The name of the sh_test.
Either the path to the script (relative to the build file), or a build target. This file must be executable in order to be run.
The list of arguments to invoke this script with. These are literal values, and no shell interpolation is done. These can contain string parameter macros, for example, to give the location of a generated binary to the test script.
Environment variable overrides that should be used when running the script. The key is the variable name, and the value is its value. The values can contain string parameter macros such as the location of a generated binary to be used by the test script.
If provided, this will be sent to any configured external runner
List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their
exported_depsattributes. For more information, see visibility.
This sh_test() fails if a string does not match a value.
# $REPO/BUCK sh_test( name = "script_pass", test = "script.sh", args = ["--pass"], ) sh_test( name = "script_fail", test = "script.sh", args = ["--fail"], )
# Create a simple script that prints out the resource $ cat > script.sh #!/bin/sh for arg in $@; do if [ "$arg" == "--pass" ]; then echo "Passed" exit 0; fi done echo "Failed" exit 1 # Make sure the script is executable $ chmod u+x script.sh # Run the script, and see that one test passes, one fails $ buck test //:script_pass //:script_fail FAILURE script.sh sh_test Building: finished in 0.0 sec (100%) 2/2 jobs, 0 updated Total time: 0.0 sec Testing: finished in 0.0 sec (1 PASS/1 FAIL) RESULTS FOR //:script_fail //:script_pass FAIL <100ms 0 Passed 0 Skipped 1 Failed //:script_fail FAILURE script.sh sh_test ====STANDARD OUT==== Failed PASS <100ms 1 Passed 0 Skipped 0 Failed //:script_pass TESTS FAILED: 1 FAILURE Failed target: //:script_fail FAIL //:script_fail