diff --git a/CHANGELOG.md b/CHANGELOG.md index 70f1ca0..83467a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # 0.7.1 +* Keep test execution properties, including `test.no-sandbox`, on the outer test + without forwarding them to generated binary launchers. + * Stream stdout/stderr live while capturing JUnit output without losing shared test state. Write provisional active-function reports for interrupted runs, drain capture workers before final results, and fail on capture/report errors. diff --git a/README.md b/README.md index e9e5daf..f1d3bf1 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,9 @@ bashtest( ) ``` +Execution properties such as `exec_properties = {"test.no-sandbox": "1"}` apply +to the test execution only; generated launcher binaries do not inherit them. + ### Checking commands Use `expect_success command args...` or `expect_exit_code status command args...` @@ -146,7 +149,7 @@ Use the latest published version from through the Bazel Central Registry. ``` -bazel_dep(name = "mboworks_bashtest", version = "0.7.0") +bazel_dep(name = "mboworks_bashtest", version = "0.7.1") ``` Executable helpers can be declared with `tools = {"GENERATOR": "//tools:generator"}`. diff --git a/bashtest/bashtest.bzl b/bashtest/bashtest.bzl index 2f3c5db..f09884e 100644 --- a/bashtest/bashtest.bzl +++ b/bashtest/bashtest.bzl @@ -78,7 +78,7 @@ def bashtest( deps: Dependencies which will have bashtest_sh automatically added. env: Environment name that automatically adds `mboworks_bashtest`. tools: Environment variable names mapped to executable targets built for test execution. - **kwargs: All other attributes are passed through as is. + **kwargs: Attributes of the outer test. Test execution properties are not forwarded to binary launchers. """ # Keep configurable srcs working; rlocationpath validates that the selected @@ -99,7 +99,7 @@ def bashtest( # owns both this executable and every execution-platform tool dependency. runner_name = name + "__bashtest_launcher" launcher_kwargs = dict(kwargs) - for attribute in ["args", "env_inherit", "size", "timeout", "flaky", "shard_count", "local", "exec_group_compatible_with"]: + for attribute in ["args", "env_inherit", "size", "timeout", "flaky", "shard_count", "local", "exec_group_compatible_with", "exec_properties"]: launcher_kwargs.pop(attribute, None) launcher_kwargs["testonly"] = True compatibility = kwargs.get("target_compatible_with", []) diff --git a/bashtest/tests/BUILD.bazel b/bashtest/tests/BUILD.bazel index c77a60f..1597c54 100644 --- a/bashtest/tests/BUILD.bazel +++ b/bashtest/tests/BUILD.bazel @@ -16,6 +16,7 @@ load("@rules_shell//shell:sh_binary.bzl", "sh_binary") load("@rules_shell//shell:sh_test.bzl", "sh_test") load("//bashtest:bashtest.bzl", "bashtest") +load(":exec_properties_fixture.bzl", "execution_properties_test") load(":tool_fixture.bzl", "configuration_data", "tool_source") package(default_visibility = ["//visibility:private"]) @@ -141,3 +142,5 @@ filegroup( ], visibility = ["//tools:__pkg__"], ) + +execution_properties_test(name = "exec_properties_test") diff --git a/bashtest/tests/exec_properties_fixture.bzl b/bashtest/tests/exec_properties_fixture.bzl new file mode 100644 index 0000000..70bae06 --- /dev/null +++ b/bashtest/tests/exec_properties_fixture.bzl @@ -0,0 +1,40 @@ +# SPDX-FileCopyrightText: Copyright (c) M. Boerger, the MBO Works authors +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Execution-property regression fixture; not part of the consumer fixtures.""" + +load("//bashtest:bashtest.bzl", "bashtest") + +visibility("private") + +def execution_properties_test(name): + """Verify execution properties belong only to the test, then run its launcher. + + Args: + name: Name of the executable regression test. + """ + + # A neutral property exercises the test exec group in every runfiles mode. + properties = {"test.bashtest-regression": "1"} + bashtest( + name = name, + srcs = ["exec_properties_test.sh"], + exec_properties = properties, + ) + if native.existing_rule(name).get("exec_properties") != properties: + fail("The outer test must retain its execution properties") + for suffix in ["__bashtest_launcher", "__bashtest_launcher_windows"]: + if native.existing_rule(name + suffix).get("exec_properties"): + fail("Binary launchers must not inherit test execution properties") diff --git a/bashtest/tests/exec_properties_test.sh b/bashtest/tests/exec_properties_test.sh new file mode 100644 index 0000000..a83bebf --- /dev/null +++ b/bashtest/tests/exec_properties_test.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# SPDX-FileCopyrightText: Copyright (c) M. Boerger, the MBO Works authors +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -euo pipefail +# shellcheck disable=SC1090,SC1091,SC2154 +source "${mboworks_bashtest}" + +# shellcheck disable=SC2317 # Functions are discovered by test_runner. +test::test_scoped_execution_properties() { + expect_success true +} + +test_runner