|
| 1 | +use cargo::core::Workspace; |
| 2 | +use cargo::util::{config::Config, errors::ManifestError}; |
| 3 | + |
| 4 | +use support::project; |
| 5 | + |
| 6 | +/// Tests inclusion of a `ManifestError` pointing to a member manifest |
| 7 | +/// when that manifest fails to deserialize. |
| 8 | +#[test] |
| 9 | +fn toml_deserialize_manifest_error() { |
| 10 | + let p = project() |
| 11 | + .file( |
| 12 | + "Cargo.toml", |
| 13 | + r#" |
| 14 | + [project] |
| 15 | + name = "foo" |
| 16 | + version = "0.1.0" |
| 17 | + authors = [] |
| 18 | +
|
| 19 | + [dependencies] |
| 20 | + bar = { path = "bar" } |
| 21 | +
|
| 22 | + [workspace] |
| 23 | + "#, |
| 24 | + ) |
| 25 | + .file("src/main.rs", "fn main() {}") |
| 26 | + .file( |
| 27 | + "bar/Cargo.toml", |
| 28 | + r#" |
| 29 | + [project] |
| 30 | + name = "bar" |
| 31 | + version = "0.1.0" |
| 32 | + authors = [] |
| 33 | +
|
| 34 | + [dependencies] |
| 35 | + foobar == "0.55" |
| 36 | + "#, |
| 37 | + ) |
| 38 | + .file("bar/src/main.rs", "fn main() {}") |
| 39 | + .build(); |
| 40 | + |
| 41 | + let root_manifest_path = p.root().join("Cargo.toml"); |
| 42 | + let member_manifest_path = p.root().join("bar").join("Cargo.toml"); |
| 43 | + |
| 44 | + let error = Workspace::new(&root_manifest_path, &Config::default().unwrap()).unwrap_err(); |
| 45 | + eprintln!("{:?}", error); |
| 46 | + |
| 47 | + let manifest_err: &ManifestError = error.downcast_ref().expect("Not a ManifestError"); |
| 48 | + assert_eq!(manifest_err.manifest_path(), &root_manifest_path); |
| 49 | + |
| 50 | + let causes: Vec<_> = manifest_err.manifest_causes().collect(); |
| 51 | + assert_eq!(causes.len(), 1, "{:?}", causes); |
| 52 | + assert_eq!(causes[0].manifest_path(), &member_manifest_path); |
| 53 | +} |
| 54 | + |
| 55 | +/// Tests inclusion of a `ManifestError` pointing to a member manifest |
| 56 | +/// when that manifest has an invalid dependency path. |
| 57 | +#[test] |
| 58 | +fn member_manifest_path_io_error() { |
| 59 | + let p = project() |
| 60 | + .file( |
| 61 | + "Cargo.toml", |
| 62 | + r#" |
| 63 | + [project] |
| 64 | + name = "foo" |
| 65 | + version = "0.1.0" |
| 66 | + authors = [] |
| 67 | +
|
| 68 | + [dependencies] |
| 69 | + bar = { path = "bar" } |
| 70 | +
|
| 71 | + [workspace] |
| 72 | + "#, |
| 73 | + ) |
| 74 | + .file("src/main.rs", "fn main() {}") |
| 75 | + .file( |
| 76 | + "bar/Cargo.toml", |
| 77 | + r#" |
| 78 | + [project] |
| 79 | + name = "bar" |
| 80 | + version = "0.1.0" |
| 81 | + authors = [] |
| 82 | +
|
| 83 | + [dependencies] |
| 84 | + foobar = { path = "nosuch" } |
| 85 | + "#, |
| 86 | + ) |
| 87 | + .file("bar/src/main.rs", "fn main() {}") |
| 88 | + .build(); |
| 89 | + |
| 90 | + let root_manifest_path = p.root().join("Cargo.toml"); |
| 91 | + let member_manifest_path = p.root().join("bar").join("Cargo.toml"); |
| 92 | + let missing_manifest_path = p.root().join("bar").join("nosuch").join("Cargo.toml"); |
| 93 | + |
| 94 | + let error = Workspace::new(&root_manifest_path, &Config::default().unwrap()).unwrap_err(); |
| 95 | + eprintln!("{:?}", error); |
| 96 | + |
| 97 | + let manifest_err: &ManifestError = error.downcast_ref().expect("Not a ManifestError"); |
| 98 | + assert_eq!(manifest_err.manifest_path(), &root_manifest_path); |
| 99 | + |
| 100 | + let causes: Vec<_> = manifest_err.manifest_causes().collect(); |
| 101 | + assert_eq!(causes.len(), 2, "{:?}", causes); |
| 102 | + assert_eq!(causes[0].manifest_path(), &member_manifest_path); |
| 103 | + assert_eq!(causes[1].manifest_path(), &missing_manifest_path); |
| 104 | +} |
0 commit comments