2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-11-27 17:43:27 +00:00
bazel-lib/lib/tests/run_binary/BUILD.bazel

80 lines
1.6 KiB
Python

"tests for run_binary"
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//lib:copy_to_directory.bzl", "copy_to_directory")
load("//lib:diff_test.bzl", "diff_test")
load("//lib:run_binary.bzl", "run_binary")
load("//lib:testing.bzl", "assert_contains")
write_file(
name = "make_dir_a_sh",
out = "make_dir_a.sh",
content = [
"#!/usr/bin/env bash",
"set -o errexit -o nounset -o pipefail",
"sleep 3",
"outdir=$1",
"echo 'foo' > \"$outdir/foo\"",
"echo 'bar' > \"$outdir/bar\"",
],
is_executable = True,
)
sh_binary(
name = "make_dir_a",
srcs = [":make_dir_a.sh"],
)
# target-under-test
run_binary(
name = "dir_a",
args = ["$(@D)"],
execution_requirements = {
"no-cache": "1",
},
mnemonic = "SomeAction",
out_dirs = ["dir_a_out"],
progress_message = "doing some work to make %{output}",
tool = ":make_dir_a",
)
genrule(
name = "make_foo",
outs = ["foo"],
cmd = "echo 'foo' > $@",
)
genrule(
name = "make_bar",
outs = ["bar"],
cmd = "echo 'bar' > $@",
)
copy_to_directory(
name = "dir_b",
srcs = [
":make_bar",
":make_foo",
],
)
diff_test(
name = "dir_test",
file1 = ":dir_a",
file2 = ":dir_b",
)
# test that rootpath can be used on the out_dir of a run_binary
genrule(
name = "dir_a_rootpath",
srcs = [":dir_a"],
outs = ["dir_a_rootpath"],
cmd = "echo $(rootpath :dir_a) > $@",
)
assert_contains(
name = "dir_a_rootpath_test",
actual = ":dir_a_rootpath",
expected = "lib/tests/run_binary/dir_a_out",
)