Skip to content

Commit

Permalink
cquery inherits from test not build
Browse files Browse the repository at this point in the history
This makes flags like `--test_arg` present in `.bazelrc` files be
factored into the configuration hash for test targets.

See bazelbuild#13428 for extensive
context.
  • Loading branch information
illicitonion committed Jun 29, 2021
1 parent aeec9a8 commit 91a9443
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@
@Command(
name = "cquery",
builds = true,
inherits = {BuildCommand.class},
// We inherit from TestCommand so that we pick up changes like `test --test_arg=foo` in .bazelrc
// files.
// Without doing this, there is no easy way to use the output of cquery to determine whether a
// test has changed between two invocations, because the testrunner action is not easily
// introspectable.
inherits = {TestCommand.class},
options = {CqueryOptions.class},
usesConfigurationOptions = true,
shortDescription = "Loads, analyzes, and queries the specified targets w/ configurations.",
Expand Down
23 changes: 23 additions & 0 deletions src/test/shell/integration/configured_query_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1289,4 +1289,27 @@ EOF
expect_log "@repo//:japanese"
}

function test_test_arg_in_bazelrc() {
local -r pkg=$FUNCNAME
mkdir -p $pkg

cat >$pkg/BUILD <<EOF
sh_test(
name = "test",
srcs = ["test.sh"],
)
EOF

touch $pkg/test.sh
chmod +x $pkg/test.sh

output_before="$(bazel cquery "//$pkg:test")"

add_to_bazelrc "test --test_arg=foo"

output_after="$(bazel cquery "//$pkg:test")"

assert_not_equals "${output_before}" "${output_after}"
}

run_suite "${PRODUCT_NAME} configured query tests"

0 comments on commit 91a9443

Please sign in to comment.