|
| 1 | +"""Starlark tests for `rust_toolchain.strip_level`""" |
| 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") |
| 6 | +load( |
| 7 | + "//test/unit:common.bzl", |
| 8 | + "assert_action_mnemonic", |
| 9 | + "assert_argv_contains", |
| 10 | +) |
| 11 | + |
| 12 | +def _strip_level_test_impl(ctx, expected_level): |
| 13 | + env = analysistest.begin(ctx) |
| 14 | + target = analysistest.target_under_test(env) |
| 15 | + |
| 16 | + action = target.actions[0] |
| 17 | + assert_action_mnemonic(env, action, "Rustc") |
| 18 | + |
| 19 | + assert_argv_contains(env, action, "--codegen=strip={}".format(expected_level)) |
| 20 | + return analysistest.end(env) |
| 21 | + |
| 22 | +def _strip_level_for_dbg_test_impl(ctx): |
| 23 | + return _strip_level_test_impl(ctx, "none") |
| 24 | + |
| 25 | +_strip_level_for_dbg_test = analysistest.make( |
| 26 | + _strip_level_for_dbg_test_impl, |
| 27 | + config_settings = { |
| 28 | + "//command_line_option:compilation_mode": "dbg", |
| 29 | + }, |
| 30 | +) |
| 31 | + |
| 32 | +def _strip_level_for_fastbuild_test_impl(ctx): |
| 33 | + return _strip_level_test_impl(ctx, "none") |
| 34 | + |
| 35 | +_strip_level_for_fastbuild_test = analysistest.make( |
| 36 | + _strip_level_for_fastbuild_test_impl, |
| 37 | + config_settings = { |
| 38 | + "//command_line_option:compilation_mode": "fastbuild", |
| 39 | + }, |
| 40 | +) |
| 41 | + |
| 42 | +def _strip_level_for_opt_test_impl(ctx): |
| 43 | + return _strip_level_test_impl(ctx, "debuginfo") |
| 44 | + |
| 45 | +_strip_level_for_opt_test = analysistest.make( |
| 46 | + _strip_level_for_opt_test_impl, |
| 47 | + config_settings = { |
| 48 | + "//command_line_option:compilation_mode": "opt", |
| 49 | + }, |
| 50 | +) |
| 51 | + |
| 52 | +def strip_level_test_suite(name): |
| 53 | + """Entry-point macro called from the BUILD file. |
| 54 | +
|
| 55 | + Args: |
| 56 | + name (str): The name of the test suite. |
| 57 | + """ |
| 58 | + write_file( |
| 59 | + name = "bin_main", |
| 60 | + out = "main.rs", |
| 61 | + content = [ |
| 62 | + "fn main() {}", |
| 63 | + "", |
| 64 | + ], |
| 65 | + ) |
| 66 | + |
| 67 | + rust_binary( |
| 68 | + name = "bin", |
| 69 | + srcs = [":main.rs"], |
| 70 | + edition = "2021", |
| 71 | + ) |
| 72 | + |
| 73 | + _strip_level_for_dbg_test( |
| 74 | + name = "strip_level_for_dbg_test", |
| 75 | + target_under_test = ":bin", |
| 76 | + ) |
| 77 | + |
| 78 | + _strip_level_for_fastbuild_test( |
| 79 | + name = "strip_level_for_fastbuild_test", |
| 80 | + target_under_test = ":bin", |
| 81 | + ) |
| 82 | + |
| 83 | + _strip_level_for_opt_test( |
| 84 | + name = "strip_level_for_opt_test", |
| 85 | + target_under_test = ":bin", |
| 86 | + ) |
| 87 | + |
| 88 | + native.test_suite( |
| 89 | + name = name, |
| 90 | + tests = [ |
| 91 | + ":strip_level_for_dbg_test", |
| 92 | + ":strip_level_for_fastbuild_test", |
| 93 | + ":strip_level_for_opt_test", |
| 94 | + ], |
| 95 | + ) |
0 commit comments