2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for workspace member errors.
|
|
|
|
|
2018-11-27 22:05:31 +00:00
|
|
|
use cargo::core::resolver::ResolveError;
|
2019-03-31 02:12:32 +00:00
|
|
|
use cargo::core::{compiler::CompileMode, Shell, Workspace};
|
2018-10-15 18:29:53 +00:00
|
|
|
use cargo::ops::{self, CompileOptions};
|
2018-10-16 14:42:15 +00:00
|
|
|
use cargo::util::{config::Config, errors::ManifestError};
|
2018-10-09 13:05:10 +00:00
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::install::cargo_home;
|
|
|
|
use cargo_test_support::project;
|
|
|
|
use cargo_test_support::registry;
|
2018-10-09 13:05:10 +00:00
|
|
|
|
|
|
|
/// Tests inclusion of a `ManifestError` pointing to a member manifest
|
|
|
|
/// when that manifest fails to deserialize.
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-10-09 13:05:10 +00:00
|
|
|
fn toml_deserialize_manifest_error() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-10-09 13:05:10 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
2018-10-09 13:05:10 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-10-09 13:05:10 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
foobar == "0.55"
|
|
|
|
"#,
|
2018-10-09 13:05:10 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2023-12-14 22:28:05 +00:00
|
|
|
p.cargo("check")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] invalid string
|
|
|
|
expected `\"`, `'`
|
|
|
|
--> bar/Cargo.toml:8:25
|
|
|
|
|
|
|
|
|
8 | foobar == \"0.55\"
|
|
|
|
| ^
|
|
|
|
|
|
|
|
|
[ERROR] failed to load manifest for dependency `bar`
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
2018-10-09 13:05:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Tests inclusion of a `ManifestError` pointing to a member manifest
|
|
|
|
/// when that manifest has an invalid dependency path.
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-10-09 13:05:10 +00:00
|
|
|
fn member_manifest_path_io_error() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-10-09 13:05:10 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
2018-10-09 13:05:10 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-10-09 13:05:10 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
foobar = { path = "nosuch" }
|
|
|
|
"#,
|
2018-10-09 13:05:10 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let root_manifest_path = p.root().join("Cargo.toml");
|
|
|
|
let member_manifest_path = p.root().join("bar").join("Cargo.toml");
|
2018-10-09 20:44:32 +00:00
|
|
|
let missing_manifest_path = p.root().join("bar").join("nosuch").join("Cargo.toml");
|
2018-10-09 13:05:10 +00:00
|
|
|
|
|
|
|
let error = Workspace::new(&root_manifest_path, &Config::default().unwrap()).unwrap_err();
|
|
|
|
eprintln!("{:?}", error);
|
|
|
|
|
2018-10-12 19:54:29 +00:00
|
|
|
let manifest_err: &ManifestError = error.downcast_ref().expect("Not a ManifestError");
|
|
|
|
assert_eq!(manifest_err.manifest_path(), &root_manifest_path);
|
2018-10-09 13:05:10 +00:00
|
|
|
|
2018-10-12 19:54:29 +00:00
|
|
|
let causes: Vec<_> = manifest_err.manifest_causes().collect();
|
|
|
|
assert_eq!(causes.len(), 2, "{:?}", causes);
|
|
|
|
assert_eq!(causes[0].manifest_path(), &member_manifest_path);
|
|
|
|
assert_eq!(causes[1].manifest_path(), &missing_manifest_path);
|
2018-10-09 13:05:10 +00:00
|
|
|
}
|
2018-10-15 18:29:53 +00:00
|
|
|
|
2019-02-03 04:01:23 +00:00
|
|
|
/// Tests dependency version errors provide which package failed via a `ResolveError`.
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-10-15 18:29:53 +00:00
|
|
|
fn member_manifest_version_error() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-10-15 18:29:53 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
2018-10-15 18:29:53 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-10-15 18:29:53 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
i-dont-exist = "0.55"
|
|
|
|
"#,
|
2018-10-15 18:29:53 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2019-03-31 02:12:32 +00:00
|
|
|
// Prevent this test from accessing the network by setting up .cargo/config.
|
|
|
|
registry::init();
|
2019-09-26 18:21:54 +00:00
|
|
|
let config = Config::new(
|
|
|
|
Shell::from_write(Box::new(Vec::new())),
|
|
|
|
cargo_home(),
|
|
|
|
cargo_home(),
|
|
|
|
);
|
2018-10-15 18:29:53 +00:00
|
|
|
let ws = Workspace::new(&p.root().join("Cargo.toml"), &config).unwrap();
|
|
|
|
let compile_options = CompileOptions::new(&config, CompileMode::Build).unwrap();
|
|
|
|
let member_bar = ws.members().find(|m| &*m.name() == "bar").unwrap();
|
|
|
|
|
|
|
|
let error = ops::compile(&ws, &compile_options).map(|_| ()).unwrap_err();
|
|
|
|
eprintln!("{:?}", error);
|
|
|
|
|
2018-10-15 23:42:14 +00:00
|
|
|
let resolve_err: &ResolveError = error.downcast_ref().expect("Not a ResolveError");
|
2018-10-16 07:56:31 +00:00
|
|
|
let package_path = resolve_err.package_path();
|
|
|
|
assert_eq!(package_path.len(), 1, "package_path: {:?}", package_path);
|
2018-11-27 22:05:31 +00:00
|
|
|
assert_eq!(package_path[0], member_bar.package_id());
|
2018-10-15 18:29:53 +00:00
|
|
|
}
|