Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
hlopko committed Jun 21, 2021
1 parent aaf4d47 commit 6b8ca5d
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 1 deletion.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
37 changes: 37 additions & 0 deletions test/rust_analyzer/merging_crates_test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
1 change: 1 addition & 0 deletions test/rust_analyzer/merging_crates_test/extra_test_dep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions test/rust_analyzer/merging_crates_test/lib_dep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions test/rust_analyzer/merging_crates_test/mylib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

21 changes: 21 additions & 0 deletions test/rust_analyzer/merging_crates_test/rust_project_json_test.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}

0 comments on commit 6b8ca5d

Please sign in to comment.