Any cquery for any test_suite target always returns Empty query results while plain query works as expected.
Trivial repro: https://github.com/konste/bazel_test_suite_cquery
bazel query hello-world-test-suite returns //:hello-world-test-suite
bazel cquery hello-world-test-suite returns Empty query results
Reproduces on Linux and Windows.
bazel info release?2.2.0
Reproduced. Digging in....
@konste this is due to the Bazel flag --expand_test_suites:
Expand test_suite targets into their constituent tests before analysis. When this flag is turned on (the default), negative target patterns will apply to the tests belonging to the test suite, otherwise they will not. Turning off this flag is useful when top-level aspects are applied at command line: then they can analyze test_suite targets.
This is basically saying that you can write:
$ bazel build -- //:my_test_suite -//:test_i_dont_want_to_run
and Bazel omits //:test_i_dont_want_to_run from the set in //:my_test_suite.
But this only works with --expand_test_suites, which itself works by first replacing //:my_test_suite with the set of tests it contains, then filtering out what you don't want. The consequence being //:my_test_suite no longer exists.
This affects cquery and not query because cquery operates over the analysis phase (when that replacement happened) while query operates over the loading phase (before the replacement).
The easiest fix would be:
$ bazel cquery //:hello-world-test-suite --noexpand_test_suites
That comes at the cost of not being able to exclude tests as above.
Thank you, @gregestren, that explanation makes sense to me! But you must forgive me for the false alarm as the effect of this flag on cquery was not obvious even for yourself.
Actually as cquery does not try to run any tests and negative (exclusion) pattern does not make sense for it, so I feel like it would be logical for cquery to imply --noexpand_test_suites.
That sounds fair to me. I'll try to flip that.