fork/rules_rust

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

UebelAndreUpdate clippy and rustfmt aspects to require CrateInfo providers (#1772)49906eb2

rust-analyzer
2.6 KiB96 linesraw
1"""Test definitions for rustfmt test rules"""
2
3load(
4    "@rules_rust//rust:defs.bzl",
5    "rust_binary",
6    "rust_library",
7    "rust_shared_library",
8    "rust_static_library",
9    "rustfmt_test",
10)
11
12_VARIANTS = {
13    "rust_binary": rust_binary,
14    "rust_library": rust_library,
15    "rust_shared_library": rust_shared_library,
16    "rust_static_library": rust_static_library,
17}
18
19def rustfmt_integration_test_suite(name, **kwargs):
20    """Generate a test suite for rustfmt integration tests.
21
22    Targets generated are expected to be executed using a target
23    named: `{name}.test_runner`
24
25    Args:
26        name (str): The name of the test suite
27        **kwargs (dict): Additional keyword arguments for the underlying test_suite.
28    """
29
30    tests = []
31    for variant, rust_rule in _VARIANTS.items():
32        rust_rule(
33            name = "{}_formatted_2018".format(variant),
34            srcs = ["srcs/2018/formatted.rs"],
35            edition = "2018",
36        )
37
38        rustfmt_test(
39            name = "{}_formatted_2018_test".format(variant),
40            targets = [":{}_formatted_2018".format(variant)],
41        )
42
43        rust_rule(
44            name = "{}_unformatted_2018".format(variant),
45            srcs = ["srcs/2018/unformatted.rs"],
46            edition = "2018",
47            tags = ["norustfmt"],
48        )
49
50        rustfmt_test(
51            name = "{}_unformatted_2018_test".format(variant),
52            tags = ["manual"],
53            targets = [":{}_unformatted_2018".format(variant)],
54        )
55
56        rust_rule(
57            name = "{}_formatted_2015".format(variant),
58            srcs = ["srcs/2015/formatted.rs"],
59            edition = "2015",
60        )
61
62        rustfmt_test(
63            name = "{}_formatted_2015_test".format(variant),
64            targets = [":{}_formatted_2015".format(variant)],
65        )
66
67        rust_rule(
68            name = "{}_unformatted_2015".format(variant),
69            srcs = ["srcs/2015/unformatted.rs"],
70            edition = "2015",
71            tags = ["norustfmt"],
72        )
73
74        rustfmt_test(
75            name = "{}_unformatted_2015_test".format(variant),
76            tags = ["manual"],
77            targets = [":{}_unformatted_2015".format(variant)],
78        )
79
80        tests.extend([
81            "{}_formatted_2015_test".format(variant),
82            "{}_formatted_2018_test".format(variant),
83            "{}_unformatted_2015_test".format(variant),
84            "{}_unformatted_2018_test".format(variant),
85        ])
86
87    native.test_suite(
88        name = name,
89        tests = tests,
90        **kwargs
91    )
92
93    native.sh_binary(
94        name = "{}.test_runner".format(name),
95        srcs = ["rustfmt_failure_test.sh"],
96    )