Skip to content

Commit

Permalink
Updates rust_test to use main.rs as the root when use_libtest_harness…
Browse files Browse the repository at this point in the history
… is false (#1518)
  • Loading branch information
csmulhern authored Aug 29, 2022
1 parent cfcaf21 commit f5ed797
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
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 = [
"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

0 comments on commit f5ed797

Please sign in to comment.