rules_xcodeproj icon indicating copy to clipboard operation
rules_xcodeproj copied to clipboard

Bug: `cc_test` can't be used in `test_action`

Open jpsim opened this issue 2 years ago • 4 comments

Describe the bug

Envoy Mobile's C++ tests fail to generate due to this internal assertion failure:

ERROR: Internal precondition failure:
An `XCSchemeInfo.TestActionInfo` should only contain testable `XCSchemeInfo.TargetInfo` values.

Reproduction steps

git clone https://github.com/jpsim/envoy.git
cd envoy
git checkout jp-rules_xcodeproj-cpp
cd mobile
./bazelw run xcodeproj

Expected behavior

According to https://github.com/buildbuddy-io/rules_xcodeproj/issues/84 it appears that cc_test should be supported, so I expected to be able to set //test/cc/unit:envoy_config_test as the test action.

Versions

  • Bazel: 6.0.0
  • rules_xcodeproj: 1.0.0rc2
  • rules_apple: a0f8748ce89698a599149d984999eaefd834c004
  • rules_swift: e769f8d6a4adae93c244f244480a3ae740f24384

Additional context

  • //test/cc/unit:envoy_config_test is defined here: https://github.com/envoyproxy/envoy/blob/51b4927d215df821bff04d35969eb54cd53d3b31/mobile/test/cc/unit/BUILD#L7-L16
  • It's an envoy_cc_test, which is defined here: https://github.com/envoyproxy/envoy/blob/51b4927d215df821bff04d35969eb54cd53d3b31/bazel/envoy_test.bzl#L146-L193
  • It defines a native.cc_test here: https://github.com/envoyproxy/envoy/blob/51b4927d215df821bff04d35969eb54cd53d3b31/bazel/envoy_test.bzl#L167-L193

jpsim avatar Feb 03 '23 03:02 jpsim

I knew when I closed that issue I would get a bug report 😄. Yes, it should be supported. I'll get this fixed up soon.

brentleyjones avatar Feb 03 '23 03:02 brentleyjones

So we support cc_test, just as an executable instead of a test 😅.

swift_test has logic to bundle the tests in xctest, cc_test does not. I think we could support this by bundling the test ourselves in Starlark (similar to how we codesign binaries). Or maybe better yet we write a rule (maybe put it in rules_apple) to allow one to wrap a cc_test in an ios_unit_test or something... though at that point you can probably just declare a ios_unit_test. Thinking more about this, I think we might run into issues of the test runner needing some special stuff to support these "plain tests".

So for now, not going to block 1.0 like I thought. Also, I'm personally not going to work on this, but I'm open to contributions!

brentleyjones avatar Feb 03 '23 16:02 brentleyjones

Ah of course I should have thought to try setting the test target as a launch action instead of a test action.

This works just fine:

xcodeproj(
    name = "xcodeproj",
    project_name = "Envoy",
    schemes = [
        xcode_schemes.scheme(
            name = "Config Test",
            launch_action = xcode_schemes.launch_action("//test/cc/unit:envoy_config_test"),
            build_action = xcode_schemes.build_action(["//library/cc:engine_builder_lib"]),
        ),
    ],
    top_level_targets = [
        "//test/cc/unit:envoy_config_test",
    ],
)

jpsim avatar Feb 03 '23 16:02 jpsim

Feel free to close this issue, maybe all this needs really is documentation for how to run non-XCTest based test targets.

jpsim avatar Feb 03 '23 17:02 jpsim