From 89f15193cfe01edac40894fce38d8db589ca8aed Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Mon, 18 Apr 2022 13:56:15 +0200 Subject: [PATCH] Add tests --- src/test/shell/bazel/bazel_sandboxing_test.sh | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/test/shell/bazel/bazel_sandboxing_test.sh b/src/test/shell/bazel/bazel_sandboxing_test.sh index ef84ca980a0017..c099843f6e522d 100755 --- a/src/test/shell/bazel/bazel_sandboxing_test.sh +++ b/src/test/shell/bazel/bazel_sandboxing_test.sh @@ -794,7 +794,7 @@ EOF } # regression test for https://github.com/bazelbuild/bazel/issues/6262 -function test_create_tree_artifact_inputs() { +function test_create_tree_artifact_outputs() { create_workspace_with_default_repos WORKSPACE cat > def.bzl <<'EOF' @@ -818,6 +818,62 @@ EOF bazel build --test_output=streamed :a &>$TEST_log || fail "expected build to succeed" } +function test_create_tree_artifact_inputs() { + create_workspace_with_default_repos WORKSPACE + + cat > def.bzl <<'EOF' +def _r(ctx): + empty_d = ctx.actions.declare_directory("%s_empty_dir" % ctx.label.name) + ctx.actions.run_shell( + outputs = [empty_d], + command = "mkdir -p %s" % empty_d.path, + ) + f = ctx.actions.declare_file("%s" % ctx.label.name) + ctx.actions.run_shell( + inputs = [empty_d], + outputs = [f], + command = "cd %s && pwd > %s" % (empty_d.path, f.path), + ) + return [DefaultInfo(files = depset([f]))] + +r = rule(implementation = _r) +EOF + +cat > BUILD <<'EOF' +load(":def.bzl", "r") + +r(name = "a") +EOF + + bazel build :a &>$TEST_log || fail "expected build to succeed" +} + +function test_create_tree_artifact_runfiles() { + create_workspace_with_default_repos WORKSPACE + + cat > def.bzl <<'EOF' +def _r(ctx): + empty_d = ctx.actions.declare_directory("%s_empty_dir" % ctx.label.name) + ctx.actions.run_shell( + outputs = [empty_d], + command = "mkdir -p %s" % empty_d.path, + ) + script = ctx.actions.declare_file("%s.sh" % ctx.label.name) + ctx.actions.write(script, "cd %s && pwd" % empty_d.short_path, is_executable = True) + return [DefaultInfo(executable = script, runfiles = ctx.runfiles([empty_d]))] + +r_test = rule(implementation = _r, test = True) +EOF + +cat > BUILD <<'EOF' +load(":def.bzl", "r_test") + +r_test(name = "a") +EOF + + bazel test --test_output=streamed :a &>$TEST_log || fail "expected test to pass" +} + # The test shouldn't fail if the environment doesn't support running it. check_sandbox_allowed || exit 0