fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

UebelAndreAvoid uses of shell to improve Windows tests (#2912)16cd457b

cleanup
1.7 KiB59 linesraw
1"""Unittest to verify location expansion in rustc flags"""
2
3load("@bazel_skylib//lib:unittest.bzl", "analysistest")
4load("@bazel_skylib//rules:write_file.bzl", "write_file")
5load("//rust:defs.bzl", "rust_library")
6load("//test/unit:common.bzl", "assert_action_mnemonic", "assert_argv_contains")
7
8def _location_expansion_rustc_flags_test(ctx):
9    env = analysistest.begin(ctx)
10    tut = analysistest.target_under_test(env)
11    action = tut.actions[0]
12    assert_action_mnemonic(env, action, "Rustc")
13    assert_argv_contains(env, action, "test/unit/location_expansion/mylibrary.rs")
14    expected = "@${pwd}/" + ctx.bin_dir.path + "/test/unit/location_expansion/generated_flag.data"
15    assert_argv_contains(env, action, expected)
16    return analysistest.end(env)
17
18location_expansion_rustc_flags_test = analysistest.make(_location_expansion_rustc_flags_test)
19
20def _location_expansion_test():
21    write_file(
22        name = "flag_generator",
23        out = "generated_flag.data",
24        content = [
25            "--cfg=test_flag",
26            "",
27        ],
28        newline = "unix",
29    )
30
31    rust_library(
32        name = "mylibrary",
33        srcs = ["mylibrary.rs"],
34        edition = "2018",
35        rustc_flags = [
36            "@$(location :flag_generator)",
37        ],
38        compile_data = [":flag_generator"],
39    )
40
41    location_expansion_rustc_flags_test(
42        name = "location_expansion_rustc_flags_test",
43        target_under_test = ":mylibrary",
44    )
45
46def location_expansion_test_suite(name):
47    """Entry-point macro called from the BUILD file.
48
49    Args:
50        name: Name of the macro.
51    """
52    _location_expansion_test()
53
54    native.test_suite(
55        name = name,
56        tests = [
57            ":location_expansion_rustc_flags_test",
58        ],
59    )