Skip to content

Commit 94008ee

Browse files
committed
test: add test for install without dry-run option
1 parent b8a4f1b commit 94008ee

1 file changed

Lines changed: 183 additions & 0 deletions

File tree

tests/testsuite/install.rs

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,3 +2734,186 @@ fn uninstall_running_binary() {
27342734
27352735
"#]]).run();
27362736
}
2737+
2738+
#[cargo_test]
2739+
fn dry_run() {
2740+
pkg("foo", "0.0.1");
2741+
2742+
cargo_process("install foo")
2743+
.with_stderr_data(str![[r#"
2744+
[UPDATING] `dummy-registry` index
2745+
[DOWNLOADING] crates ...
2746+
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
2747+
[INSTALLING] foo v0.0.1
2748+
[COMPILING] foo v0.0.1
2749+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
2750+
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
2751+
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
2752+
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
2753+
2754+
"#]])
2755+
.run();
2756+
assert_has_installed_exe(paths::cargo_home(), "foo");
2757+
}
2758+
2759+
#[cargo_test]
2760+
fn dry_run_incompatible_package() {
2761+
Package::new("some-package-from-the-distant-future", "0.0.1")
2762+
.rust_version("1.2345.0")
2763+
.file("src/lib.rs", "")
2764+
.file(
2765+
"src/main.rs",
2766+
&format!(
2767+
"extern crate {}; fn main() {{}}",
2768+
"some-package-from-the-distant-future"
2769+
),
2770+
)
2771+
.publish();
2772+
2773+
cargo_process("install some-package-from-the-distant-future")
2774+
.with_status(101)
2775+
.with_stderr_data(str![[r#"
2776+
[UPDATING] `dummy-registry` index
2777+
[ERROR] cannot install package `some-package-from-the-distant-future 0.0.1`, it requires rustc 1.2345.0 or newer, while the currently active rustc version is [..]
2778+
2779+
"#]])
2780+
.run();
2781+
assert_has_not_installed_exe(paths::cargo_home(), "some-package-from-the-distant-future");
2782+
}
2783+
2784+
#[cargo_test]
2785+
fn dry_run_incompatible_package_dependecy() {
2786+
let p = project()
2787+
.file(
2788+
"Cargo.toml",
2789+
r#"
2790+
[package]
2791+
name = "foo"
2792+
version = "0.1.0"
2793+
authors = []
2794+
2795+
[dependencies]
2796+
some-package-from-the-distant-future = { path = "a" }
2797+
"#,
2798+
)
2799+
.file(
2800+
"src/main.rs",
2801+
&format!(
2802+
"extern crate {}; fn main() {{}}",
2803+
"some_package_from_the_distant_future"
2804+
),
2805+
)
2806+
.file(
2807+
"a/Cargo.toml",
2808+
r#"
2809+
[package]
2810+
name = "some-package-from-the-distant-future"
2811+
version = "0.1.0"
2812+
authors = []
2813+
rust-version = "1.2345.0"
2814+
"#,
2815+
)
2816+
.file("a/src/lib.rs", "")
2817+
.build();
2818+
2819+
cargo_process("install --path")
2820+
.arg(p.root())
2821+
.arg("foo")
2822+
.with_status(101)
2823+
.with_stderr_data(str![[r#"
2824+
[INSTALLING] foo v0.1.0 ([ROOT]/foo)
2825+
[LOCKING] 1 package to latest compatible version
2826+
[ERROR] failed to compile `foo v0.1.0 ([ROOT]/foo)`, intermediate artifacts can be found at `[ROOT]/foo/target`.
2827+
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
2828+
2829+
Caused by:
2830+
rustc 1.80.0 is not supported by the following package:
2831+
some-package-from-the-distant-future@0.1.0 requires rustc 1.2345.0
2832+
2833+
"#]])
2834+
.run();
2835+
assert_has_not_installed_exe(paths::cargo_home(), "foo");
2836+
}
2837+
2838+
#[cargo_test]
2839+
fn dry_run_upgrade() {
2840+
pkg("foo", "0.0.1");
2841+
cargo_process("install foo").run();
2842+
assert_has_installed_exe(paths::cargo_home(), "foo");
2843+
2844+
pkg("foo", "0.0.2");
2845+
cargo_process("install foo")
2846+
.with_stderr_data(str![[r#"
2847+
[UPDATING] `dummy-registry` index
2848+
[DOWNLOADING] crates ...
2849+
[DOWNLOADED] foo v0.0.2 (registry `dummy-registry`)
2850+
[INSTALLING] foo v0.0.2
2851+
[COMPILING] foo v0.0.2
2852+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
2853+
[REPLACING] [ROOT]/home/.cargo/bin/foo[EXE]
2854+
[REPLACED] package `foo v0.0.1` with `foo v0.0.2` (executable `foo[EXE]`)
2855+
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
2856+
2857+
"#]])
2858+
.run();
2859+
assert_has_installed_exe(paths::cargo_home(), "foo");
2860+
}
2861+
2862+
#[cargo_test]
2863+
fn dry_run_remove_orphan() {
2864+
Package::new("bar", "1.0.0")
2865+
.file("src/lib.rs", "")
2866+
.file(
2867+
"src/bin/client.rs",
2868+
&format!("extern crate {}; fn main() {{}}", "bar"),
2869+
)
2870+
.file(
2871+
"src/bin/server.rs",
2872+
&format!("extern crate {}; fn main() {{}}", "bar"),
2873+
)
2874+
.publish();
2875+
2876+
cargo_process("install bar")
2877+
.with_stderr_data(str![[r#"
2878+
[UPDATING] `dummy-registry` index
2879+
[DOWNLOADING] crates ...
2880+
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
2881+
[INSTALLING] bar v1.0.0
2882+
[COMPILING] bar v1.0.0
2883+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
2884+
[INSTALLING] [ROOT]/home/.cargo/bin/client[EXE]
2885+
[INSTALLING] [ROOT]/home/.cargo/bin/server[EXE]
2886+
[INSTALLED] package `bar v1.0.0` (executables `client[EXE]`, `server[EXE]`)
2887+
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
2888+
2889+
"#]])
2890+
.run();
2891+
assert_has_installed_exe(paths::cargo_home(), "client");
2892+
assert_has_installed_exe(paths::cargo_home(), "server");
2893+
2894+
Package::new("bar", "2.0.0")
2895+
.file("src/lib.rs", "")
2896+
.file(
2897+
"src/bin/client.rs",
2898+
&format!("extern crate {}; fn main() {{}}", "bar"),
2899+
)
2900+
.publish();
2901+
2902+
cargo_process("install bar")
2903+
.with_stderr_data(str![[r#"
2904+
[UPDATING] `dummy-registry` index
2905+
[DOWNLOADING] crates ...
2906+
[DOWNLOADED] bar v2.0.0 (registry `dummy-registry`)
2907+
[INSTALLING] bar v2.0.0
2908+
[COMPILING] bar v2.0.0
2909+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
2910+
[REPLACING] [ROOT]/home/.cargo/bin/client[EXE]
2911+
[REMOVING] executable `[ROOT]/home/.cargo/bin/server[EXE]` from previous version bar v1.0.0
2912+
[REPLACED] package `bar v1.0.0` with `bar v2.0.0` (executable `client[EXE]`)
2913+
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
2914+
2915+
"#]])
2916+
.run();
2917+
assert_has_installed_exe(paths::cargo_home(), "client");
2918+
assert_has_not_installed_exe(paths::cargo_home(), "server");
2919+
}

0 commit comments

Comments
 (0)