Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates rust_test to use main.rs as the root when use_libtest_harness is false #1518

Merged
merged 1 commit into from
Aug 29, 2022
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: 2 additions & 1 deletion rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ def _rust_test_impl(ctx):
)
else:
if not crate_root:
crate_root = crate_root_src(ctx.attr.name, ctx.files.srcs, "lib")
crate_root_type = "lib" if ctx.attr.use_libtest_harness else "bin"
crate_root = crate_root_src(ctx.attr.name, ctx.files.srcs, crate_root_type)

output_hash = determine_output_hash(crate_root, ctx.label)
output = ctx.actions.declare_file(
Expand Down
1 change: 1 addition & 0 deletions test/unit/use_libtest_harness/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
26 changes: 26 additions & 0 deletions test/unit/use_libtest_harness/use_libtest_harness_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@ def _use_libtest_harness_rustc_noharness_flags_test_impl(ctx):
assert_list_contains_adjacent_elements(env, action.argv, ["--cfg", "test"])
return analysistest.end(env)

def _use_libtest_harness_rustc_noharness_main_flags_test_impl(ctx):
env = analysistest.begin(ctx)
tut = analysistest.target_under_test(env)
action = tut.actions[0]
assert_action_mnemonic(env, action, "Rustc")
assert_argv_contains(env, action, "test/unit/use_libtest_harness/main.rs")
assert_argv_contains_not(env, action, "--test")
assert_list_contains_adjacent_elements(env, action.argv, ["--cfg", "test"])
return analysistest.end(env)

use_libtest_harness_rustc_flags_test = analysistest.make(_use_libtest_harness_rustc_flags_test_impl)
use_libtest_harness_rustc_noharness_flags_test = analysistest.make(_use_libtest_harness_rustc_noharness_flags_test_impl)
use_libtest_harness_rustc_noharness_main_flags_test = analysistest.make(_use_libtest_harness_rustc_noharness_main_flags_test_impl)

def _use_libtest_harness_test():
rust_test(
Expand All @@ -41,6 +52,16 @@ def _use_libtest_harness_test():
use_libtest_harness = False,
)

rust_test(
name = "mytest_noharness_main",
srcs = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this PR a breaking change? Do test targets with a single source file not using the test harness now require a main.rs or will they be able to function just as they did before?

"main.rs",
"mytest.rs",
],
edition = "2018",
use_libtest_harness = False,
)

use_libtest_harness_rustc_flags_test(
name = "use_libtest_harness_rustc_flags_test",
target_under_test = ":mytest",
Expand All @@ -51,6 +72,11 @@ def _use_libtest_harness_test():
target_under_test = ":mytest_noharness",
)

use_libtest_harness_rustc_noharness_main_flags_test(
name = "use_libtest_harness_rustc_noharness_main_flags_test",
target_under_test = ":mytest_noharness_main",
)

def use_libtest_harness_test_suite(name):
"""Entry-point macro called from the BUILD file.

Expand Down