2019-12-10 00:18:12 +00:00
|
|
|
//! Tests for the `cargo locate-project` command.
|
|
|
|
|
|
|
|
use cargo_test_support::project;
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn simple() {
|
|
|
|
let p = project().build();
|
|
|
|
|
|
|
|
p.cargo("locate-project")
|
2021-06-16 16:41:38 +00:00
|
|
|
.with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#)
|
2019-12-10 00:18:12 +00:00
|
|
|
.run();
|
|
|
|
}
|
2020-09-16 05:50:15 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn message_format() {
|
|
|
|
let p = project().build();
|
|
|
|
|
|
|
|
p.cargo("locate-project --message-format plain")
|
2021-06-16 16:41:38 +00:00
|
|
|
.with_stdout("[ROOT]/foo/Cargo.toml")
|
2020-09-16 05:50:15 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("locate-project --message-format json")
|
2021-06-16 16:41:38 +00:00
|
|
|
.with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#)
|
2020-09-16 05:50:15 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("locate-project --message-format cryptic")
|
|
|
|
.with_stderr("error: invalid message format specifier: `cryptic`")
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
2020-09-18 03:38:54 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn workspace() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "outer"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
members = ["inner"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"inner/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "inner"
|
|
|
|
version = "0.0.0"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("inner/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2021-06-16 16:41:38 +00:00
|
|
|
let outer_manifest = r#"{"root": "[ROOT]/foo/Cargo.toml"}"#;
|
|
|
|
let inner_manifest = r#"{"root": "[ROOT]/foo/inner/Cargo.toml"}"#;
|
2020-09-18 03:38:54 +00:00
|
|
|
|
2021-06-16 16:41:38 +00:00
|
|
|
p.cargo("locate-project").with_json(outer_manifest).run();
|
2020-09-18 03:38:54 +00:00
|
|
|
|
|
|
|
p.cargo("locate-project")
|
|
|
|
.cwd("inner")
|
2021-06-16 16:41:38 +00:00
|
|
|
.with_json(inner_manifest)
|
2020-09-18 03:38:54 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("locate-project --workspace")
|
2021-06-16 16:41:38 +00:00
|
|
|
.with_json(outer_manifest)
|
2020-09-18 03:38:54 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("locate-project --workspace")
|
|
|
|
.cwd("inner")
|
2021-06-16 16:41:38 +00:00
|
|
|
.with_json(outer_manifest)
|
2020-09-18 03:38:54 +00:00
|
|
|
.run();
|
|
|
|
}
|