Skip to content

Commit ee34d54

Browse files
committed
add sanity check
1 parent 2ccfee3 commit ee34d54

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

tests/buildtest/crates/missing-deps-git/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "missing-deps"
2+
name = "missing-deps-git"
33
version = "0.1.0"
44
authors = ["Pietro Albini <pietro@pietroalbini.org>"]
55
edition = "2018"

tests/buildtest/mod.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,51 @@ use rustwide::cmd::{ProcessLinesActions, SandboxBuilder};
55
mod runner;
66
mod inside_docker;
77

8+
#[test]
9+
fn buildtest_crate_name_matches_folder_name() {
10+
for result in std::fs::read_dir(concat!(
11+
env!("CARGO_MANIFEST_DIR"),
12+
"/tests/buildtest/crates"
13+
))
14+
.unwrap()
15+
{
16+
let dir_entry = result.unwrap();
17+
if dir_entry.file_type().unwrap().is_dir() {
18+
let dir_name = dir_entry.file_name();
19+
20+
if [
21+
"cargo-workspace".as_ref(),
22+
"invalid-cargotoml-syntax".as_ref(),
23+
]
24+
.contains(&dir_name.as_os_str())
25+
{
26+
continue;
27+
}
28+
29+
let expected_crate_name = if dir_name != "invalid-cargotoml-content" {
30+
dir_name.clone()
31+
} else {
32+
"!".into()
33+
};
34+
35+
let cargo_toml_path = dir_entry.path().join("Cargo.toml");
36+
37+
if !cargo_toml_path.exists() {
38+
continue;
39+
}
40+
41+
let cargo_toml_content = std::fs::read_to_string(&cargo_toml_path).unwrap();
42+
43+
assert!(
44+
cargo_toml_content.contains(&format!("name = {expected_crate_name:?}")),
45+
"directory {:?} does not contain a crate with the expected name {:?}",
46+
dir_name,
47+
expected_crate_name
48+
)
49+
}
50+
}
51+
}
52+
853
#[test]
954
fn test_hello_world() {
1055
runner::run("hello-world", |run| {
@@ -199,7 +244,7 @@ test_prepare_error_stderr!(
199244
test_missing_deps_git,
200245
"missing-deps-git",
201246
MissingDependencies,
202-
"failed to get `not-a-git-repo` as a dependency of package `missing-deps v0.1.0"
247+
"failed to get `not-a-git-repo` as a dependency of package `missing-deps-git v0.1.0"
203248
);
204249

205250
test_prepare_error_stderr!(

0 commit comments

Comments
 (0)