diff options
author | Googler <noreply@google.com> | 2017-09-19 21:36:12 +0200 |
---|---|---|
committer | László Csomor <laszlocsomor@google.com> | 2017-09-20 09:03:32 +0200 |
commit | 36d2363f5a9cfd95c96c1af5303de2380e57d14e (patch) | |
tree | 5d0b92fd1adc2e77ca9a25dc1de126209114b516 /src/test/shell | |
parent | 446f0ba6749cee2a086a7ab0606b8ac3b1fd80d6 (diff) |
Add support for writing undeclared outputs to TEST_UNDECLARED_OUTPUTS_DIR and TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR to Bazel.
After this change:
- Any files written to the TEST_UNDECLARED_OUTPUTS_DIR directory will be zipped up and added to an outputs.zip file under bazel-testlogs.
- Files will be listed in a MANIFEST file under bazel-testlogs.
- Any files written to TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR will be concatenated together into an ANNOTATIONS file under bazel-testlogs.
This provides a channel for tests to provide extra information outside of the test output itself. This is useful for things like verbose server logs.
Note: The //src/test/shell/bazel:bazel_test_test target has a pre-existing breakage (see https://github.com/bazelbuild/bazel/issues/3727). But the new tests pass.
RELNOTES: Tests can now write files to TEST_UNDECLARED_OUTPUTS_DIR and TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR and these will be reflected under bazel-testlogs.
PiperOrigin-RevId: 169282528
Diffstat (limited to 'src/test/shell')
-rwxr-xr-x | src/test/shell/bazel/bazel_test_test.sh | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/test/shell/bazel/bazel_test_test.sh b/src/test/shell/bazel/bazel_test_test.sh index 31dfa87da5..0cf9154594 100755 --- a/src/test/shell/bazel/bazel_test_test.sh +++ b/src/test/shell/bazel/bazel_test_test.sh @@ -513,4 +513,91 @@ EOF assert_equals "fail" "$(sed -n '3p' < bazel-testlogs/fail/test.log)" } +function test_undeclared_outputs_are_zipped_and_manifest_exists() { + mkdir -p dir + + cat <<'EOF' > dir/test.sh +#!/bin/sh +echo "some text" > "$TEST_UNDECLARED_OUTPUTS_DIR/text.txt" +echo "<!DOCTYPE html>" > "$TEST_UNDECLARED_OUTPUTS_DIR/fake.html" +echo "pass" +exit 0 +EOF + + chmod +x dir/test.sh + + cat <<'EOF' > dir/BUILD + sh_test( + name = "test", + srcs = [ "test.sh" ], + ) +EOF + + bazel test -s //dir:test &> $TEST_log || fail "expected success" + + # Newlines are useful around diffs. This helps us get them in bash strings. + N=$'\n' + + # Check that the undeclared outputs zip file exists. + outputs_zip=bazel-testlogs/dir/test/test.outputs/outputs.zip + [ -s $outputs_zip ] || fail "$outputs_zip was not present after test" + + # Check the contents of the zip file. + unzip -q "$outputs_zip" -d unzipped_outputs || fail "failed to unzip $outputs_zip" + cat > expected_text <<EOF +some text +EOF +diff "unzipped_outputs/text.txt" expected_text > d || fail "unzipped_outputs/text.txt differs from expected:$N$(cat d)$N" + cat > expected_html <<EOF +<!DOCTYPE html> +EOF +diff expected_html "unzipped_outputs/fake.html" > d || fail "unzipped_outputs/fake.html differs from expected:$N$(cat d)$N" + + # Check that the undeclared outputs manifest exists and that it has the + # correct contents. + outputs_manifest=bazel-testlogs/dir/test/test.outputs_manifest/MANIFEST + [ -s $outputs_manifest ] || fail "$outputs_manifest was not present after test" + cat > expected_manifest <<EOF +fake.html 16 text/html +text.txt 10 text/plain +EOF +diff expected_manifest "$outputs_manifest" > d || fail "$outputs_manifest differs from expected:$N$(cat d)$N" +} + +function test_undeclared_outputs_annotations_are_added() { + mkdir -p dir + + cat <<'EOF' > dir/test.sh +#!/bin/sh +echo "an annotation" > "$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR/1.part" +echo "another annotation" > "$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR/2.part" +echo "pass" +exit 0 +EOF + + chmod +x dir/test.sh + + cat <<'EOF' > dir/BUILD + sh_test( + name = "test", + srcs = [ "test.sh" ], + ) +EOF + + bazel test -s //dir:test &> $TEST_log || fail "expected success" + + # Newlines are useful around diffs. This helps us get them in bash strings. + N=$'\n' + + # Check that the undeclared outputs manifest exists and that it has the + # correct contents. + annotations=bazel-testlogs/dir/test/test.outputs_manifest/ANNOTATIONS + [ -s $annotations ] || fail "$annotations was not present after test" + cat > expected_annotations <<EOF +an annotation +another annotation +EOF +diff expected_annotations "$annotations" > d || fail "$annotations differs from expected:$N$(cat d)$N" +} + run_suite "bazel test tests" |