Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...`
Expand Down Expand Up @@ -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"}`.
Expand Down
4 changes: 2 additions & 2 deletions bashtest/bashtest.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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", [])
Expand Down
3 changes: 3 additions & 0 deletions bashtest/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -141,3 +142,5 @@ filegroup(
],
visibility = ["//tools:__pkg__"],
)

execution_properties_test(name = "exec_properties_test")
40 changes: 40 additions & 0 deletions bashtest/tests/exec_properties_fixture.bzl
Original file line number Diff line number Diff line change
@@ -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")
27 changes: 27 additions & 0 deletions bashtest/tests/exec_properties_test.sh
Original file line number Diff line number Diff line change
@@ -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
Loading