diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-24 19:27:53 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-24 19:27:53 +0000 |
commit | f106017751732e4baaf3e71170ef4f2bb337848d (patch) | |
tree | 3c15c050ced2749753c4d6f1cf9d3a9b9bd94085 /tests | |
parent | 76be740a2ab63f21bb42ee3590792fd39edc6a59 (diff) | |
parent | f1fb8167b4ed64feb494fd1ea6a8a619bbb549de (diff) | |
download | bazel-skylib-android-gs-tangorpro-5.10-u-beta5.2.tar.gz |
Snap for 8765624 from f1fb8167b4ed64feb494fd1ea6a8a619bbb549de to android13-gs-pixel-5.10-releaseandroid-u-beta-5_r0.7android-u-beta-5_r0.5android-u-beta-5_r0.4android-u-beta-5_r0.3android-u-beta-5_r0.2android-u-beta-5_r0.1android-u-beta-5.2_r0.7android-u-beta-5.2_r0.6android-u-beta-5.2_r0.5android-u-beta-5.2_r0.3android-u-beta-5.2_r0.1android-u-beta-3_r0.5android-u-beta-3_r0.4android-t-qpr2-beta-3.2_r0.4android-14.0.0_r0.24android-13.0.0_r0.94android-13.0.0_r0.65android-13.0.0_r0.63android-gs-tangorpro-5.10-u-beta5.2android-gs-tangorpro-5.10-u-beta5android-gs-raviole-5.10-u-beta5.2android-gs-raviole-5.10-u-beta5android-gs-raviole-5.10-t-qpr2-beta-3.2android-gs-pantah-5.10-u-beta5android-gs-pantah-5.10-u-beta3android-gs-lynx-5.10-u-beta5.2android-gs-lynx-5.10-u-beta5android-gs-lynx-5.10-u-beta3android-gs-felix-5.10-u-beta5.2android-gs-felix-5.10-u-beta5android-gs-bluejay-5.10-u-beta5.2android-gs-bluejay-5.10-u-beta5
Change-Id: Ia0ce9f969778c682312310ecbc9ab7eaa4ada766
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/analysis_test_test.sh | 2 | ||||
-rwxr-xr-x | tests/common_settings_test.sh | 2 | ||||
-rw-r--r-- | tests/copy_file/BUILD | 8 | ||||
-rw-r--r-- | tests/copy_file/a.txt | 2 | ||||
-rwxr-xr-x | tests/copy_file/a_with_exec_bit.txt | 2 | ||||
-rwxr-xr-x | tests/copy_file/copy_file_tests.sh | 10 | ||||
-rwxr-xr-x | tests/diff_test/diff_test_tests.sh | 2 | ||||
-rw-r--r-- | tests/partial_tests.bzl | 18 | ||||
-rw-r--r-- | tests/run_binary/BUILD | 2 | ||||
-rw-r--r-- | tests/selects_tests.bzl | 8 | ||||
-rw-r--r-- | tests/shell_tests.bzl | 2 | ||||
-rwxr-xr-x | tests/unittest.bash | 4 | ||||
-rwxr-xr-x | tests/unittest_test.sh | 52 | ||||
-rw-r--r-- | tests/unittest_tests.bzl | 119 | ||||
-rw-r--r-- | tests/write_file/BUILD | 2 | ||||
-rwxr-xr-x | tests/write_file/write_file_tests.sh | 8 |
16 files changed, 211 insertions, 32 deletions
diff --git a/tests/analysis_test_test.sh b/tests/analysis_test_test.sh index db9bbac..2edae15 100755 --- a/tests/analysis_test_test.sh +++ b/tests/analysis_test_test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2019 The Bazel Authors. All rights reserved. # diff --git a/tests/common_settings_test.sh b/tests/common_settings_test.sh index 531e830..1e3d03d 100755 --- a/tests/common_settings_test.sh +++ b/tests/common_settings_test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2019 The Bazel Authors. All rights reserved. # diff --git a/tests/copy_file/BUILD b/tests/copy_file/BUILD index 79ab7ba..2e6914c 100644 --- a/tests/copy_file/BUILD +++ b/tests/copy_file/BUILD @@ -80,8 +80,8 @@ genrule( output_to_bindir = 1, tools = [ ":bin_gen", - ":bin_src", ":bin_gen_symlink", + ":bin_src", ":bin_src_symlink", ], ) @@ -147,8 +147,8 @@ copy_file( name = "copy_xsrc_symlink", src = "a_with_exec_bit.txt", out = "xout/a-out-symlink.sh", - is_executable = True, allow_symlink = True, + is_executable = True, ) copy_file( @@ -162,12 +162,12 @@ copy_file( name = "copy_xgen_symlink", src = ":gen", out = "xout/gen-out-symlink.sh", - is_executable = True, allow_symlink = True, + is_executable = True, ) genrule( name = "gen", outs = ["b.txt"], - cmd = "echo -e '#!/bin/bash\necho potato' > $@", + cmd = "echo -e '#!/usr/bin/env bash\necho potato' > $@", ) diff --git a/tests/copy_file/a.txt b/tests/copy_file/a.txt index acd332a..37b2322 100644 --- a/tests/copy_file/a.txt +++ b/tests/copy_file/a.txt @@ -1,2 +1,2 @@ -#!/bin/bash +#!/usr/bin/env bash echo aaa diff --git a/tests/copy_file/a_with_exec_bit.txt b/tests/copy_file/a_with_exec_bit.txt index acd332a..37b2322 100755 --- a/tests/copy_file/a_with_exec_bit.txt +++ b/tests/copy_file/a_with_exec_bit.txt @@ -1,2 +1,2 @@ -#!/bin/bash +#!/usr/bin/env bash echo aaa diff --git a/tests/copy_file/copy_file_tests.sh b/tests/copy_file/copy_file_tests.sh index dfee635..737afd7 100755 --- a/tests/copy_file/copy_file_tests.sh +++ b/tests/copy_file/copy_file_tests.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # Copyright 2019 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,25 +42,25 @@ source "$(rlocation bazel_skylib/tests/unittest.bash)" \ function test_copy_src() { cat "$(rlocation bazel_skylib/tests/copy_file/out/a-out.txt)" >"$TEST_log" - expect_log '^#!/bin/bash$' + expect_log '^#!/usr/bin/env bash$' expect_log '^echo aaa$' } function test_copy_src_symlink() { cat "$(rlocation bazel_skylib/tests/copy_file/out/a-out-symlink.txt)" >"$TEST_log" - expect_log '^#!/bin/bash$' + expect_log '^#!/usr/bin/env bash$' expect_log '^echo aaa$' } function test_copy_gen() { cat "$(rlocation bazel_skylib/tests/copy_file/out/gen-out.txt)" >"$TEST_log" - expect_log '^#!/bin/bash$' + expect_log '^#!/usr/bin/env bash$' expect_log '^echo potato$' } function test_copy_gen_symlink() { cat "$(rlocation bazel_skylib/tests/copy_file/out/gen-out-symlink.txt)" >"$TEST_log" - expect_log '^#!/bin/bash$' + expect_log '^#!/usr/bin/env bash$' expect_log '^echo potato$' } diff --git a/tests/diff_test/diff_test_tests.sh b/tests/diff_test/diff_test_tests.sh index ed894c2..4b58e6c 100755 --- a/tests/diff_test/diff_test_tests.sh +++ b/tests/diff_test/diff_test_tests.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # Copyright 2019 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/partial_tests.bzl b/tests/partial_tests.bzl index 6d778c3..73a579b 100644 --- a/tests/partial_tests.bzl +++ b/tests/partial_tests.bzl @@ -76,9 +76,27 @@ def _make_call_test(ctx): make_call_test = unittest.make(_make_call_test) +def _is_instance_test(ctx): + """Unit test for partial.is_instance.""" + env = unittest.begin(ctx) + + # We happen to use make_call_test here, but it could be any valid test rule. + asserts.true(env, partial.is_instance(partial.make(make_call_test))) + asserts.true(env, partial.is_instance(partial.make(make_call_test, timeout = "short"))) + asserts.true(env, partial.is_instance(partial.make(make_call_test, timeout = "short", tags = ["foo"]))) + asserts.false(env, partial.is_instance(None)) + asserts.false(env, partial.is_instance({})) + asserts.false(env, partial.is_instance(struct(foo = 1))) + asserts.false(env, partial.is_instance(struct(function = "not really function"))) + + return unittest.end(env) + +is_instance_test = unittest.make(_is_instance_test) + def partial_test_suite(): """Creates the test targets and test suite for partial.bzl tests.""" unittest.suite( "partial_tests", make_call_test, + is_instance_test, ) diff --git a/tests/run_binary/BUILD b/tests/run_binary/BUILD index f511c03..85c10f3 100644 --- a/tests/run_binary/BUILD +++ b/tests/run_binary/BUILD @@ -82,7 +82,7 @@ write_file( "@echo>>%OUT% ENV_PATH_CMD=(%ENV_PATH_CMD%)", ], "//conditions:default": [ - "#!/bin/bash", + "#!/usr/bin/env bash", "echo > \"$OUT\" \"arg1=($1)\"", "echo >> \"$OUT\" \"arg2=($2)\"", "echo >> \"$OUT\" \"ENV_LOCATION=($ENV_LOCATION)\"", diff --git a/tests/selects_tests.bzl b/tests/selects_tests.bzl index 28f3ac4..a7697f2 100644 --- a/tests/selects_tests.bzl +++ b/tests/selects_tests.bzl @@ -129,7 +129,10 @@ def _set_conditions(condition_list): ans["//command_line_option:features"] = ["notmyfeature"] return ans -_BooleanInfo = provider() +_BooleanInfo = provider( + doc = "value for boolean tests", + fields = ["value"], +) def _boolean_attr_impl(ctx): return [_BooleanInfo(value = ctx.attr.myboolean)] @@ -153,9 +156,6 @@ def _expect_doesnt_match(ctx): asserts.equals(env, False, attrval) return analysistest.end(env) -def _config_setting_group_test(name, config_settings): - return analysistest.make() - ################################################### # and_config_setting_group_matches_test ################################################### diff --git a/tests/shell_tests.bzl b/tests/shell_tests.bzl index 32d517f..5b83f9f 100644 --- a/tests/shell_tests.bzl +++ b/tests/shell_tests.bzl @@ -69,7 +69,7 @@ def _shell_args_test_gen_impl(ctx): "back`echo q`uote", ] script_content = "\n".join([ - "#!/bin/bash", + "#!/usr/bin/env bash", "myarray=" + shell.array_literal(args), 'output=$(echo "${myarray[@]}")', # For logging: diff --git a/tests/unittest.bash b/tests/unittest.bash index 3bd07c7..a43678d 100755 --- a/tests/unittest.bash +++ b/tests/unittest.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 The Bazel Authors. All rights reserved. # @@ -21,7 +21,7 @@ # A typical test suite looks like so: # # ------------------------------------------------------------------------ -# #!/bin/bash +# #!/usr/bin/env bash # # source path/to/unittest.bash || exit 1 # diff --git a/tests/unittest_test.sh b/tests/unittest_test.sh index baed490..4795b7e 100755 --- a/tests/unittest_test.sh +++ b/tests/unittest_test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2019 The Bazel Authors. All rights reserved. # @@ -73,6 +73,7 @@ exports_files(["*.bzl"]) EOF ln -sf "$(rlocation bazel_skylib/lib/dicts.bzl)" lib/dicts.bzl ln -sf "$(rlocation bazel_skylib/lib/new_sets.bzl)" lib/new_sets.bzl + ln -sf "$(rlocation bazel_skylib/lib/partial.bzl)" lib/partial.bzl ln -sf "$(rlocation bazel_skylib/lib/sets.bzl)" lib/sets.bzl ln -sf "$(rlocation bazel_skylib/lib/types.bzl)" lib/types.bzl ln -sf "$(rlocation bazel_skylib/lib/unittest.bzl)" lib/unittest.bzl @@ -82,10 +83,11 @@ EOF # Create test files. mkdir -p testdir - cat > testdir/BUILD <<EOF + cat > testdir/BUILD <<'EOF' load("//tests:unittest_tests.bzl", "basic_passing_test", "basic_failing_test", + "failure_message_test", "fail_unexpected_passing_test", "fail_unexpected_passing_fake_rule") @@ -93,10 +95,26 @@ basic_passing_test(name = "basic_passing_test") basic_failing_test(name = "basic_failing_test") +failure_message_test( + name = "shell_escape_failure_message_test", + message = "Contains $FOO", +) + +failure_message_test( + name = "cmd_escape_failure_message_test", + message = "Contains %FOO%", +) + +failure_message_test( + name = "eof_failure_message_test", + message = "\nEOF\n more after EOF", +) + fail_unexpected_passing_test( name = "fail_unexpected_passing_test", target_under_test = ":fail_unexpected_passing_fake_target", ) + fail_unexpected_passing_fake_rule( name = "fail_unexpected_passing_fake_target", tags = ["manual"]) @@ -122,6 +140,36 @@ function test_basic_failing_test() { expect_log "In test _basic_failing_test from //tests:unittest_tests.bzl: Expected \"1\", but got \"2\"" } +function test_shell_escape_failure_message_test() { + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:shell_escape_failure_message_test --test_output=all --verbose_failures \ + >"$TEST_log" 2>&1 && fail "Expected test to fail" || true + + expect_log 'In test _failure_message_test from //tests:unittest_tests.bzl: Expected "", but got "Contains $FOO"' +} + +function test_cmd_escape_failure_message_test() { + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:cmd_escape_failure_message_test --test_output=all --verbose_failures \ + >"$TEST_log" 2>&1 && fail "Expected test to fail" || true + + expect_log 'In test _failure_message_test from //tests:unittest_tests.bzl: Expected "", but got "Contains %FOO%"' +} + +function test_eof_failure_message_test() { + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:eof_failure_message_test --test_output=all --verbose_failures \ + >"$TEST_log" 2>&1 && fail "Expected test to fail" || true + + expect_log '^ more after EOF' +} + function test_fail_unexpected_passing_test() { local -r pkg="${FUNCNAME[0]}" create_pkg "$pkg" diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl index 3d5a198..2f326a0 100644 --- a/tests/unittest_tests.bzl +++ b/tests/unittest_tests.bzl @@ -14,11 +14,13 @@ """Unit tests for unittest.bzl.""" -load("//lib:unittest.bzl", "analysistest", "asserts", "unittest") +load("//lib:partial.bzl", "partial") +load("//lib:unittest.bzl", "analysistest", "asserts", "loadingtest", "unittest") ################################### -####### fail_basic_test ########### +####### basic_failing_test ######## ################################### + def _basic_failing_test(ctx): """Unit tests for a basic library verification test that fails.""" env = unittest.begin(ctx) @@ -30,6 +32,27 @@ def _basic_failing_test(ctx): basic_failing_test = unittest.make(_basic_failing_test) ################################### +####### failure_message_test ###### +################################### + +def _failure_message_test(ctx): + """Failing unit test with arbitrary content in the message.""" + env = unittest.begin(ctx) + + if not ctx.attr.message: + unittest.fail(env, "Message must be non-empty.") + asserts.equals(env, "", ctx.attr.message) + + return unittest.end(env) + +failure_message_test = unittest.make( + _failure_message_test, + attrs = { + "message": attr.string(), + }, +) + +################################### ####### basic_passing_test ######## ################################### def _basic_passing_test(ctx): @@ -42,6 +65,19 @@ def _basic_passing_test(ctx): basic_passing_test = unittest.make(_basic_passing_test) +################################################# +####### basic_passing_short_timeout_test ######## +################################################# +def _basic_passing_short_timeout_test(ctx): + """Unit tests for a basic library verification test.""" + env = unittest.begin(ctx) + + asserts.equals(env, ctx.attr.timeout, "short") + + return unittest.end(env) + +basic_passing_short_timeout_test = unittest.make(_basic_passing_short_timeout_test) + ################################### ####### change_setting_test ####### ################################### @@ -54,7 +90,10 @@ def _change_setting_test(ctx): return analysistest.end(env) -_ChangeSettingInfo = provider() +_ChangeSettingInfo = provider( + doc = "min_os_version for change_setting_test", + fields = ["min_os_version"], +) def _change_setting_fake_rule(ctx): return [_ChangeSettingInfo(min_os_version = ctx.fragments.cpp.minimum_os_version())] @@ -83,7 +122,7 @@ def _failure_testing_test(ctx): return analysistest.end(env) def _failure_testing_fake_rule(ctx): - ignore = [ctx] + _ignore = [ctx] # @unused fail("This rule should never work") failure_testing_fake_rule = rule( @@ -107,7 +146,7 @@ def _fail_unexpected_passing_test(ctx): return analysistest.end(env) def _fail_unexpected_passing_fake_rule(ctx): - _ignore = [ctx] + _ignore = [ctx] # @unused return [] fail_unexpected_passing_fake_rule = rule( @@ -177,10 +216,58 @@ inspect_actions_test = analysistest.make( _inspect_actions_test, ) +#################################### +####### inspect_aspect_test ####### +#################################### +_AddedByAspectInfo = provider( + doc = "Example provider added by example aspect", + fields = { + "value": "(str)", + }, +) + +def _example_aspect_impl(target, ctx): + _ignore = [target, ctx] # @unused + return [ + _AddedByAspectInfo(value = "attached by aspect"), + ] + +example_aspect = aspect( + implementation = _example_aspect_impl, +) + +def _inspect_aspect_test(ctx): + """Test verifying aspect run on a target.""" + env = analysistest.begin(ctx) + + tut = env.ctx.attr.target_under_test + asserts.equals(env, "attached by aspect", tut[_AddedByAspectInfo].value) + return analysistest.end(env) + +def _inspect_aspect_fake_rule(ctx): + out_file = ctx.actions.declare_file("out.txt") + ctx.actions.run_shell( + command = "echo 'hello' > %s" % out_file.basename, + outputs = [out_file], + ) + return [DefaultInfo(files = depset([out_file]))] + +inspect_aspect_fake_rule = rule( + implementation = _inspect_aspect_fake_rule, +) + +inspect_aspect_test = analysistest.make( + _inspect_aspect_test, + extra_target_under_test_aspects = [example_aspect], +) + ######################################## ####### inspect_output_dirs_test ####### ######################################## -_OutputDirInfo = provider(fields = ["bin_path"]) +_OutputDirInfo = provider( + doc = "bin_path for inspect_output_dirs_test", + fields = ["bin_path"], +) def _inspect_output_dirs_test(ctx): """Test verifying output directories used by a test.""" @@ -221,6 +308,13 @@ inspect_output_dirs_test = analysistest.make( }, ) +def _loading_phase_test(env): + loadingtest.equals(env, "self_glob", ["unittest_tests.bzl"], native.glob(["unittest_tests.bzl"])) + + # now use our own calls to assert we created a test case rule and test_suite for it. + loadingtest.equals(env, "test_exists", True, native.existing_rule(env.name + "_self_glob") != None) + loadingtest.equals(env, "suite_exists", True, native.existing_rule(env.name + "_tests") != None) + ######################################### # buildifier: disable=unnamed-macro @@ -234,6 +328,7 @@ def unittest_passing_tests_suite(): unittest.suite( "unittest_tests", basic_passing_test, + partial.make(basic_passing_short_timeout_test, timeout = "short"), ) change_setting_test( @@ -272,6 +367,15 @@ def unittest_passing_tests_suite(): tags = ["manual"], ) + inspect_aspect_test( + name = "inspect_aspect_test", + target_under_test = ":inspect_aspect_fake_target", + ) + inspect_aspect_fake_rule( + name = "inspect_aspect_fake_target", + tags = ["manual"], + ) + inspect_output_dirs_test( name = "inspect_output_dirs_test", target_under_test = ":inspect_output_dirs_fake_target", @@ -280,3 +384,6 @@ def unittest_passing_tests_suite(): name = "inspect_output_dirs_fake_target", tags = ["manual"], ) + + loading_env = loadingtest.make("selftest") + _loading_phase_test(loading_env) diff --git a/tests/write_file/BUILD b/tests/write_file/BUILD index 9ea3609..e4f2a94 100644 --- a/tests/write_file/BUILD +++ b/tests/write_file/BUILD @@ -113,7 +113,7 @@ write_file( name = "write_nonempty_bin", out = "out/nonempty.sh", content = [ - "#!/bin/bash", + "#!/usr/bin/env bash", "echo potato", ], is_executable = True, diff --git a/tests/write_file/write_file_tests.sh b/tests/write_file/write_file_tests.sh index 2464230..e7039d0 100755 --- a/tests/write_file/write_file_tests.sh +++ b/tests/write_file/write_file_tests.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # Copyright 2019 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -50,8 +52,8 @@ function test_write_empty_text() { function test_write_nonempty_text() { cat "$(rlocation bazel_skylib/tests/write_file/out/nonempty.txt)" >"$TEST_log" - expect_log '^aaa$' - expect_log '^bbb$' + expect_log '^aaa' + expect_log '^bbb' } function test_write_empty_bin() { @@ -60,7 +62,7 @@ function test_write_empty_bin() { function test_write_nonempty_bin() { cat "$(rlocation bazel_skylib/tests/write_file/nonempty-bin-out.txt)" >"$TEST_log" - expect_log '^potato$' + expect_log '^potato' } run_suite "write_file_tests test suite" |