2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for `[alias]` config command aliases.
|
|
|
|
|
2021-08-06 00:21:13 +00:00
|
|
|
use std::env;
|
|
|
|
|
|
|
|
use cargo_test_support::tools::echo_subcommand;
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::{basic_bin_manifest, project};
|
2016-05-12 16:30:57 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-12 16:30:57 +00:00
|
|
|
fn alias_incorrect_config_type() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2016-05-12 16:30:57 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[alias]
|
|
|
|
b-cargo-test = 5
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2016-05-12 16:30:57 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("b-cargo-test -v")
|
|
|
|
.with_status(101)
|
2022-09-21 21:15:13 +00:00
|
|
|
.with_stderr(
|
2018-05-03 10:50:05 +00:00
|
|
|
"\
|
|
|
|
[ERROR] invalid configuration for key `alias.b-cargo-test`
|
2018-03-14 15:17:44 +00:00
|
|
|
expected a list, but found a integer for [..]",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-12 16:30:57 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 11:19:31 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn alias_malformed_config_string() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
|
|
|
[alias]
|
|
|
|
b-cargo-test = `
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("b-cargo-test -v")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2022-09-21 21:15:13 +00:00
|
|
|
[ERROR] could not load Cargo configuration
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
could not parse TOML configuration in `[..]/config`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
TOML parse error at line [..]
|
|
|
|
|
|
|
|
|
3 | b-cargo-test = `
|
|
|
|
| ^
|
2023-01-19 21:26:28 +00:00
|
|
|
invalid string
|
|
|
|
expected `\"`, `'`
|
2022-09-14 11:19:31 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn alias_malformed_config_list() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
|
|
|
[alias]
|
|
|
|
b-cargo-test = [1, 2]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("b-cargo-test -v")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2022-09-21 21:15:13 +00:00
|
|
|
[ERROR] could not load Cargo configuration
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
failed to load TOML configuration from `[..]/config`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
[..] `alias`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
[..] `b-cargo-test`
|
2022-09-14 11:19:31 +00:00
|
|
|
|
2022-09-21 21:15:13 +00:00
|
|
|
Caused by:
|
|
|
|
expected string but found integer in list
|
2022-09-14 11:19:31 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-12 16:30:57 +00:00
|
|
|
fn alias_config() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2016-05-12 16:30:57 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[alias]
|
|
|
|
b-cargo-test = "build"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2016-05-12 16:30:57 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("b-cargo-test -v")
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
2018-05-03 10:50:05 +00:00
|
|
|
[COMPILING] foo v0.5.0 [..]
|
|
|
|
[RUNNING] `rustc --crate-name foo [..]",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-05-03 10:50:05 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2021-08-06 00:21:13 +00:00
|
|
|
fn dependent_alias() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-05-03 10:50:05 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2020-09-27 00:59:58 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-05-03 10:50:05 +00:00
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[alias]
|
|
|
|
b-cargo-test = "build"
|
|
|
|
a-cargo-test = ["b-cargo-test", "-v"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-05-03 10:50:05 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("a-cargo-test")
|
|
|
|
.with_stderr_contains(
|
2018-05-03 10:50:05 +00:00
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.5.0 [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] `rustc --crate-name foo [..]",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-12 16:30:57 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 20:04:31 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn builtin_alias_shadowing_external_subcommand() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.executable("cargo-t", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
|
|
|
|
paths.push(p.root());
|
|
|
|
let path = env::join_paths(paths).unwrap();
|
|
|
|
|
|
|
|
p.cargo("t")
|
|
|
|
.env("PATH", &path)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.5.0 [..]
|
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[RUNNING] unittests src/main.rs [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-11-17 08:23:06 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn alias_shadowing_external_subcommand() {
|
|
|
|
let echo = echo_subcommand();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
|
|
|
[alias]
|
|
|
|
echo = "build"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
|
|
|
|
paths.push(echo.target_debug_dir());
|
|
|
|
let path = env::join_paths(paths).unwrap();
|
|
|
|
|
|
|
|
p.cargo("echo")
|
|
|
|
.env("PATH", &path)
|
|
|
|
.with_stderr("\
|
|
|
|
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
|
|
|
|
This was previously accepted but is being phased out; it will become a hard error in a future release.
|
|
|
|
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
|
|
|
|
[COMPILING] foo v0.5.0 [..]
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-08-06 00:21:13 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn default_args_alias() {
|
|
|
|
let echo = echo_subcommand();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
|
|
|
[alias]
|
|
|
|
echo = "echo --flag1 --flag2"
|
|
|
|
test-1 = "echo"
|
|
|
|
build = "build --verbose"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
|
|
|
|
paths.push(echo.target_debug_dir());
|
|
|
|
let path = env::join_paths(paths).unwrap();
|
|
|
|
|
|
|
|
p.cargo("echo")
|
|
|
|
.env("PATH", &path)
|
|
|
|
.with_status(101)
|
2021-11-14 19:38:40 +00:00
|
|
|
.with_stderr("\
|
2021-11-17 08:22:08 +00:00
|
|
|
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
|
|
|
|
This was previously accepted but is being phased out; it will become a hard error in a future release.
|
|
|
|
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
|
2021-11-14 19:38:40 +00:00
|
|
|
error: alias echo has unresolvable recursive definition: echo -> echo
|
|
|
|
",
|
|
|
|
)
|
2021-08-06 00:21:13 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test-1")
|
|
|
|
.env("PATH", &path)
|
|
|
|
.with_status(101)
|
2021-11-14 19:38:40 +00:00
|
|
|
.with_stderr("\
|
2021-11-17 08:22:08 +00:00
|
|
|
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
|
|
|
|
This was previously accepted but is being phased out; it will become a hard error in a future release.
|
|
|
|
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
|
2021-11-14 19:38:40 +00:00
|
|
|
error: alias test-1 has unresolvable recursive definition: test-1 -> echo -> echo
|
|
|
|
",
|
2021-08-06 00:21:13 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
// Builtins are not expanded by rule
|
|
|
|
p.cargo("build")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[WARNING] user-defined alias `build` is ignored, because it is shadowed by a built-in command
|
|
|
|
[COMPILING] foo v0.5.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn corecursive_alias() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
|
|
|
[alias]
|
|
|
|
test-1 = "test-2 --flag1"
|
|
|
|
test-2 = "test-3 --flag2"
|
|
|
|
test-3 = "test-1 --flag3"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test-1")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"error: alias test-1 has unresolvable recursive definition: test-1 -> test-2 -> test-3 -> test-1",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test-2")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"error: alias test-2 has unresolvable recursive definition: test-2 -> test-3 -> test-1 -> test-2",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-12 16:30:57 +00:00
|
|
|
fn alias_list_test() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2016-05-12 16:30:57 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[alias]
|
|
|
|
b-cargo-test = ["build", "--release"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2016-05-12 16:30:57 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("b-cargo-test -v")
|
|
|
|
.with_stderr_contains("[COMPILING] foo v0.5.0 [..]")
|
|
|
|
.with_stderr_contains("[RUNNING] `rustc --crate-name [..]")
|
|
|
|
.run();
|
2016-05-12 16:30:57 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-12 16:30:57 +00:00
|
|
|
fn alias_with_flags_config() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2016-05-12 16:30:57 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[alias]
|
|
|
|
b-cargo-test = "build --release"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2016-05-12 16:30:57 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("b-cargo-test -v")
|
|
|
|
.with_stderr_contains("[COMPILING] foo v0.5.0 [..]")
|
|
|
|
.with_stderr_contains("[RUNNING] `rustc --crate-name foo [..]")
|
|
|
|
.run();
|
2016-05-12 16:30:57 +00:00
|
|
|
}
|
2016-07-22 17:58:25 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-11-04 08:27:18 +00:00
|
|
|
fn alias_cannot_shadow_builtin_command() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2016-07-22 17:58:25 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[alias]
|
|
|
|
build = "fetch"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2016-07-22 17:58:25 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build")
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-11-04 08:27:18 +00:00
|
|
|
[WARNING] user-defined alias `build` is ignored, because it is shadowed by a built-in command
|
|
|
|
[COMPILING] foo v0.5.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-11-04 08:27:18 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-11-04 08:27:18 +00:00
|
|
|
fn alias_override_builtin_alias() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[alias]
|
|
|
|
b = "run"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-11-04 08:27:18 +00:00
|
|
|
|
|
|
|
p.cargo("b")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-07-22 17:58:25 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-11-04 08:27:18 +00:00
|
|
|
[RUNNING] `target/debug/foo[EXE]`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-07-22 17:58:25 +00:00
|
|
|
}
|
2018-12-05 17:29:10 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-12-05 17:29:10 +00:00
|
|
|
fn builtin_alias_takes_options() {
|
|
|
|
// #6381
|
|
|
|
let p = project()
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(
|
|
|
|
"examples/ex1.rs",
|
|
|
|
r#"fn main() { println!("{}", std::env::args().skip(1).next().unwrap()) }"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("r --example ex1 -- asdf").with_stdout("asdf").run();
|
|
|
|
}
|
2020-01-26 23:02:37 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn global_options_with_alias() {
|
|
|
|
// Check that global options are passed through.
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
|
|
|
|
|
|
|
p.cargo("-v c")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[CHECKING] foo [..]
|
|
|
|
[RUNNING] `rustc [..]
|
|
|
|
[FINISHED] dev [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2021-06-09 14:41:46 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn weird_check() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("-- check --invalid_argument -some-other-argument")
|
2022-09-20 21:53:59 +00:00
|
|
|
.with_status(101)
|
2021-06-09 14:41:46 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
2022-09-20 21:53:59 +00:00
|
|
|
[ERROR] trailing arguments after built-in command `check` are unsupported: `--invalid_argument -some-other-argument`
|
|
|
|
|
|
|
|
To pass the arguments to the subcommand, remove `--`
|
2021-06-09 14:41:46 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|