|
| 1 | +"""Analysis tests verifying remap_path_prefix flags.""" |
| 2 | + |
| 3 | +load("@bazel_skylib//lib:unittest.bzl", "analysistest") |
| 4 | +load("@bazel_skylib//rules:write_file.bzl", "write_file") |
| 5 | +load("//rust:defs.bzl", "rust_binary", "rust_library") |
| 6 | +load( |
| 7 | + "//test/unit:common.bzl", |
| 8 | + "assert_action_mnemonic", |
| 9 | + "assert_argv_contains", |
| 10 | + "assert_list_contains_adjacent_elements", |
| 11 | +) |
| 12 | + |
| 13 | +def _remap_path_prefix_test_impl(ctx): |
| 14 | + env = analysistest.begin(ctx) |
| 15 | + target = analysistest.target_under_test(env) |
| 16 | + |
| 17 | + action = target.actions[0] |
| 18 | + assert_action_mnemonic(env, action, "Rustc") |
| 19 | + |
| 20 | + assert_argv_contains(env, action, "--remap-path-prefix=${pwd}=.") |
| 21 | + assert_argv_contains(env, action, "--remap-path-prefix=${exec_root}=.") |
| 22 | + assert_argv_contains(env, action, "--remap-path-prefix=${output_base}=.") |
| 23 | + |
| 24 | + return analysistest.end(env) |
| 25 | + |
| 26 | +_remap_path_prefix_test = analysistest.make(_remap_path_prefix_test_impl) |
| 27 | + |
| 28 | +def _subst_flags_test_impl(ctx): |
| 29 | + """Verify that process wrapper --subst flags are present.""" |
| 30 | + env = analysistest.begin(ctx) |
| 31 | + target = analysistest.target_under_test(env) |
| 32 | + |
| 33 | + action = target.actions[0] |
| 34 | + assert_action_mnemonic(env, action, "Rustc") |
| 35 | + |
| 36 | + assert_list_contains_adjacent_elements(env, action.argv, ["--subst", "pwd=${pwd}"]) |
| 37 | + assert_list_contains_adjacent_elements(env, action.argv, ["--subst", "exec_root=${exec_root}"]) |
| 38 | + assert_list_contains_adjacent_elements(env, action.argv, ["--subst", "output_base=${output_base}"]) |
| 39 | + |
| 40 | + return analysistest.end(env) |
| 41 | + |
| 42 | +_subst_flags_test = analysistest.make(_subst_flags_test_impl) |
| 43 | + |
| 44 | +def remap_path_prefix_test_suite(name): |
| 45 | + """Entry-point macro called from the BUILD file. |
| 46 | +
|
| 47 | + Args: |
| 48 | + name (str): The name of the test suite. |
| 49 | + """ |
| 50 | + write_file( |
| 51 | + name = "remap_lib_src", |
| 52 | + out = "remap_lib.rs", |
| 53 | + content = [ |
| 54 | + "pub fn hello() {}", |
| 55 | + "", |
| 56 | + ], |
| 57 | + ) |
| 58 | + |
| 59 | + rust_library( |
| 60 | + name = "remap_lib", |
| 61 | + srcs = [":remap_lib.rs"], |
| 62 | + edition = "2021", |
| 63 | + ) |
| 64 | + |
| 65 | + write_file( |
| 66 | + name = "remap_bin_src", |
| 67 | + out = "remap_bin.rs", |
| 68 | + content = [ |
| 69 | + "fn main() {}", |
| 70 | + "", |
| 71 | + ], |
| 72 | + ) |
| 73 | + |
| 74 | + rust_binary( |
| 75 | + name = "remap_bin", |
| 76 | + srcs = [":remap_bin.rs"], |
| 77 | + edition = "2021", |
| 78 | + ) |
| 79 | + |
| 80 | + _remap_path_prefix_test( |
| 81 | + name = "remap_path_prefix_lib_test", |
| 82 | + target_under_test = ":remap_lib", |
| 83 | + ) |
| 84 | + |
| 85 | + _remap_path_prefix_test( |
| 86 | + name = "remap_path_prefix_bin_test", |
| 87 | + target_under_test = ":remap_bin", |
| 88 | + ) |
| 89 | + |
| 90 | + _subst_flags_test( |
| 91 | + name = "subst_flags_lib_test", |
| 92 | + target_under_test = ":remap_lib", |
| 93 | + ) |
| 94 | + |
| 95 | + _subst_flags_test( |
| 96 | + name = "subst_flags_bin_test", |
| 97 | + target_under_test = ":remap_bin", |
| 98 | + ) |
| 99 | + |
| 100 | + tests = [ |
| 101 | + ":remap_path_prefix_lib_test", |
| 102 | + ":remap_path_prefix_bin_test", |
| 103 | + ":subst_flags_lib_test", |
| 104 | + ":subst_flags_bin_test", |
| 105 | + ] |
| 106 | + |
| 107 | + native.test_suite( |
| 108 | + name = name, |
| 109 | + tests = tests, |
| 110 | + ) |
0 commit comments