|
1 | 1 | """Unit tests for crate names."""
|
2 | 2 |
|
3 | 3 | load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
|
4 |
| -load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test") |
5 |
| -load("//test/unit:common.bzl", "assert_argv_contains") |
| 4 | +load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_shared_library", "rust_static_library", "rust_test") |
| 5 | +load("//test/unit:common.bzl", "assert_argv_contains", "assert_argv_contains_prefix_not") |
6 | 6 |
|
7 | 7 | def _default_crate_name_library_test_impl(ctx):
|
8 | 8 | env = analysistest.begin(ctx)
|
@@ -68,9 +68,22 @@ def _slib_library_name_test_impl(ctx):
|
68 | 68 | """
|
69 | 69 | env = analysistest.begin(ctx)
|
70 | 70 | tut = analysistest.target_under_test(env)
|
| 71 | + assert_argv_contains(env, tut.actions[0], "--codegen=metadata=-2102077805") |
71 | 72 | assert_argv_contains(env, tut.actions[0], "--codegen=extra-filename=-2102077805")
|
72 | 73 | return analysistest.end(env)
|
73 | 74 |
|
| 75 | +def _no_extra_filename_test_impl(ctx): |
| 76 | + """Check that no extra filename is used. |
| 77 | +
|
| 78 | + Args: |
| 79 | + ctx: rule context. |
| 80 | + """ |
| 81 | + env = analysistest.begin(ctx) |
| 82 | + tut = analysistest.target_under_test(env) |
| 83 | + assert_argv_contains_prefix_not(env, tut.actions[0], "--codegen=metadata=") |
| 84 | + assert_argv_contains_prefix_not(env, tut.actions[0], "--codegen=extra-filename=") |
| 85 | + return analysistest.end(env) |
| 86 | + |
74 | 87 | default_crate_name_library_test = analysistest.make(
|
75 | 88 | _default_crate_name_library_test_impl,
|
76 | 89 | )
|
@@ -100,6 +113,9 @@ invalid_custom_crate_name_test = analysistest.make(
|
100 | 113 | slib_library_name_test = analysistest.make(
|
101 | 114 | _slib_library_name_test_impl,
|
102 | 115 | )
|
| 116 | +no_extra_filename_test = analysistest.make( |
| 117 | + _no_extra_filename_test_impl, |
| 118 | +) |
103 | 119 |
|
104 | 120 | def _crate_name_test():
|
105 | 121 | rust_library(
|
@@ -153,6 +169,16 @@ def _crate_name_test():
|
153 | 169 | srcs = ["slib.rs"],
|
154 | 170 | )
|
155 | 171 |
|
| 172 | + rust_shared_library( |
| 173 | + name = "shared_lib", |
| 174 | + srcs = ["lib.rs"], |
| 175 | + ) |
| 176 | + |
| 177 | + rust_static_library( |
| 178 | + name = "static_lib", |
| 179 | + srcs = ["lib.rs"], |
| 180 | + ) |
| 181 | + |
156 | 182 | slib_library_name_test(
|
157 | 183 | name = "slib_library_name_test",
|
158 | 184 | target_under_test = ":slib",
|
@@ -198,6 +224,16 @@ def _crate_name_test():
|
198 | 224 | target_under_test = ":invalid-custom-crate-name",
|
199 | 225 | )
|
200 | 226 |
|
| 227 | + no_extra_filename_test( |
| 228 | + name = "no_extra_filename_for_shared_library_test", |
| 229 | + target_under_test = ":shared_lib", |
| 230 | + ) |
| 231 | + |
| 232 | + no_extra_filename_test( |
| 233 | + name = "no_extra_filename_for_static_library_test", |
| 234 | + target_under_test = ":static_lib", |
| 235 | + ) |
| 236 | + |
201 | 237 | def crate_name_test_suite(name):
|
202 | 238 | """Entry-point macro called from the BUILD file.
|
203 | 239 |
|
|
0 commit comments