Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Apr 18, 2022
1 parent 6872fd2 commit 89f1519
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/test/shell/bazel/bazel_sandboxing_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

Expand Down

0 comments on commit 89f1519

Please sign in to comment.