From 6b8ca5d7bee8765df3bb13f526bdd760a0b73b16 Mon Sep 17 00:00:00 2001 From: Marcel Hlopko Date: Mon, 21 Jun 2021 22:20:59 +0200 Subject: [PATCH] Add a test --- .../{ => aspect_traversal_test}/BUILD.bazel | 0 .../extra_proc_macro_dep.rs | 0 .../extra_test_dep.rs | 0 .../{ => aspect_traversal_test}/lib_dep.rs | 0 .../{ => aspect_traversal_test}/mylib.rs | 0 .../proc_macro_dep.rs | 0 .../rust_project_json_test.rs | 2 +- .../merging_crates_test/BUILD.bazel | 37 +++++++++++++++++++ .../merging_crates_test/extra_test_dep.rs | 1 + .../merging_crates_test/lib_dep.rs | 1 + .../merging_crates_test/mylib.rs | 1 + .../rust_project_json_test.rs | 21 +++++++++++ 12 files changed, 62 insertions(+), 1 deletion(-) rename test/rust_analyzer/{ => aspect_traversal_test}/BUILD.bazel (100%) rename test/rust_analyzer/{ => aspect_traversal_test}/extra_proc_macro_dep.rs (100%) rename test/rust_analyzer/{ => aspect_traversal_test}/extra_test_dep.rs (100%) rename test/rust_analyzer/{ => aspect_traversal_test}/lib_dep.rs (100%) rename test/rust_analyzer/{ => aspect_traversal_test}/mylib.rs (100%) rename test/rust_analyzer/{ => aspect_traversal_test}/proc_macro_dep.rs (100%) rename test/rust_analyzer/{ => aspect_traversal_test}/rust_project_json_test.rs (91%) create mode 100644 test/rust_analyzer/merging_crates_test/BUILD.bazel create mode 100644 test/rust_analyzer/merging_crates_test/extra_test_dep.rs create mode 100644 test/rust_analyzer/merging_crates_test/lib_dep.rs create mode 100644 test/rust_analyzer/merging_crates_test/mylib.rs create mode 100644 test/rust_analyzer/merging_crates_test/rust_project_json_test.rs diff --git a/test/rust_analyzer/BUILD.bazel b/test/rust_analyzer/aspect_traversal_test/BUILD.bazel similarity index 100% rename from test/rust_analyzer/BUILD.bazel rename to test/rust_analyzer/aspect_traversal_test/BUILD.bazel diff --git a/test/rust_analyzer/extra_proc_macro_dep.rs b/test/rust_analyzer/aspect_traversal_test/extra_proc_macro_dep.rs similarity index 100% rename from test/rust_analyzer/extra_proc_macro_dep.rs rename to test/rust_analyzer/aspect_traversal_test/extra_proc_macro_dep.rs diff --git a/test/rust_analyzer/extra_test_dep.rs b/test/rust_analyzer/aspect_traversal_test/extra_test_dep.rs similarity index 100% rename from test/rust_analyzer/extra_test_dep.rs rename to test/rust_analyzer/aspect_traversal_test/extra_test_dep.rs diff --git a/test/rust_analyzer/lib_dep.rs b/test/rust_analyzer/aspect_traversal_test/lib_dep.rs similarity index 100% rename from test/rust_analyzer/lib_dep.rs rename to test/rust_analyzer/aspect_traversal_test/lib_dep.rs diff --git a/test/rust_analyzer/mylib.rs b/test/rust_analyzer/aspect_traversal_test/mylib.rs similarity index 100% rename from test/rust_analyzer/mylib.rs rename to test/rust_analyzer/aspect_traversal_test/mylib.rs diff --git a/test/rust_analyzer/proc_macro_dep.rs b/test/rust_analyzer/aspect_traversal_test/proc_macro_dep.rs similarity index 100% rename from test/rust_analyzer/proc_macro_dep.rs rename to test/rust_analyzer/aspect_traversal_test/proc_macro_dep.rs diff --git a/test/rust_analyzer/rust_project_json_test.rs b/test/rust_analyzer/aspect_traversal_test/rust_project_json_test.rs similarity index 91% rename from test/rust_analyzer/rust_project_json_test.rs rename to test/rust_analyzer/aspect_traversal_test/rust_project_json_test.rs index 758adee4b1..2dbe59a2d4 100644 --- a/test/rust_analyzer/rust_project_json_test.rs +++ b/test/rust_analyzer/aspect_traversal_test/rust_project_json_test.rs @@ -2,7 +2,7 @@ use runfiles::Runfiles; fn main() { let r = Runfiles::create().unwrap(); - let rust_project_path = r.rlocation("rules_rust/test/rust_analyzer/rust-project.json"); + let rust_project_path = r.rlocation("rules_rust/test/rust_analyzer/aspect_traversal_test/rust-project.json"); let content = std::fs::read_to_string(&rust_project_path) .expect(&format!("couldn't open {:?}", &rust_project_path)); diff --git a/test/rust_analyzer/merging_crates_test/BUILD.bazel b/test/rust_analyzer/merging_crates_test/BUILD.bazel new file mode 100644 index 0000000000..2f93da81ec --- /dev/null +++ b/test/rust_analyzer/merging_crates_test/BUILD.bazel @@ -0,0 +1,37 @@ +load("//rust:defs.bzl", "rust_analyzer", "rust_library", "rust_proc_macro", "rust_test") + +rust_library( + name = "mylib", + srcs = ["mylib.rs"], + deps = [":lib_dep"], +) + +rust_library( + name = "lib_dep", + srcs = ["lib_dep.rs"], +) + +rust_test( + name = "mylib_test", + crate = ":mylib", + deps = [":extra_test_dep"], +) + +rust_library( + name = "extra_test_dep", + srcs = ["extra_test_dep.rs"], +) + +rust_analyzer( + name = "rust_analyzer", + testonly = True, + targets = [":mylib_test", ":mylib", ], +) + +rust_test( + name = "rust_project_json_test", + srcs = ["rust_project_json_test.rs"], + data = [":rust-project.json"], + edition = "2018", + deps = ["//tools/runfiles"], +) diff --git a/test/rust_analyzer/merging_crates_test/extra_test_dep.rs b/test/rust_analyzer/merging_crates_test/extra_test_dep.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/test/rust_analyzer/merging_crates_test/extra_test_dep.rs @@ -0,0 +1 @@ + diff --git a/test/rust_analyzer/merging_crates_test/lib_dep.rs b/test/rust_analyzer/merging_crates_test/lib_dep.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/test/rust_analyzer/merging_crates_test/lib_dep.rs @@ -0,0 +1 @@ + diff --git a/test/rust_analyzer/merging_crates_test/mylib.rs b/test/rust_analyzer/merging_crates_test/mylib.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/test/rust_analyzer/merging_crates_test/mylib.rs @@ -0,0 +1 @@ + diff --git a/test/rust_analyzer/merging_crates_test/rust_project_json_test.rs b/test/rust_analyzer/merging_crates_test/rust_project_json_test.rs new file mode 100644 index 0000000000..c57e01c7ab --- /dev/null +++ b/test/rust_analyzer/merging_crates_test/rust_project_json_test.rs @@ -0,0 +1,21 @@ +use runfiles::Runfiles; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_deps_of_crate_and_its_test_are_merged() { + let r = Runfiles::create().unwrap(); + let rust_project_path = r.rlocation("rules_rust/test/rust_analyzer/merging_crates_test/rust-project.json"); + + let content = std::fs::read_to_string(&rust_project_path) + .expect(&format!("couldn't open {:?}", &rust_project_path)); + + for dep in &["lib_dep","", "extra_test_dep"] { + if !content.contains(dep) { + panic!("expected rust-project.json to contain {}.", dep); + } + } + } +}