|
2 | 2 |
|
3 | 3 | use std::fs::{self, OpenOptions};
|
4 | 4 | use std::io::prelude::*;
|
| 5 | +use std::path::Path; |
5 | 6 |
|
| 7 | +use cargo_test_support::compare; |
6 | 8 | use cargo_test_support::cross_compile;
|
7 | 9 | use cargo_test_support::git;
|
8 | 10 | use cargo_test_support::registry::{self, registry_path, Package};
|
9 | 11 | use cargo_test_support::{
|
10 | 12 | basic_manifest, cargo_process, no_such_file_err_msg, project, project_in, symlink_supported, t,
|
11 | 13 | };
|
| 14 | +use cargo_util::ProcessError; |
12 | 15 |
|
13 | 16 | use cargo_test_support::install::{
|
14 | 17 | assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
|
@@ -2105,3 +2108,103 @@ fn no_auto_fix_note() {
|
2105 | 2108 | .run();
|
2106 | 2109 | assert_has_not_installed_exe(cargo_home(), "auto_fix");
|
2107 | 2110 | }
|
| 2111 | + |
| 2112 | +#[cargo_test] |
| 2113 | +fn failed_install_retains_temp_directory() { |
| 2114 | + // Verifies that the temporary directory persists after a build failure. |
| 2115 | + Package::new("foo", "0.0.1") |
| 2116 | + .file("src/main.rs", "x") |
| 2117 | + .publish(); |
| 2118 | + let err = cargo_process("install foo").exec_with_output().unwrap_err(); |
| 2119 | + let err = err.downcast::<ProcessError>().unwrap(); |
| 2120 | + let stderr = String::from_utf8(err.stderr.unwrap()).unwrap(); |
| 2121 | + compare::match_contains( |
| 2122 | + "\ |
| 2123 | +[UPDATING] `dummy-registry` index |
| 2124 | +[DOWNLOADING] crates ... |
| 2125 | +[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`) |
| 2126 | +[INSTALLING] foo v0.0.1 |
| 2127 | +[COMPILING] foo v0.0.1 |
| 2128 | +", |
| 2129 | + &stderr, |
| 2130 | + None, |
| 2131 | + ) |
| 2132 | + .unwrap(); |
| 2133 | + compare::match_contains( |
| 2134 | + "error: failed to compile `foo v0.0.1`, intermediate artifacts can be found at `[..]`", |
| 2135 | + &stderr, |
| 2136 | + None, |
| 2137 | + ) |
| 2138 | + .unwrap(); |
| 2139 | + |
| 2140 | + // Find the path in the output. |
| 2141 | + let start = stderr.find("found at `").unwrap() + 10; |
| 2142 | + let end = stderr[start..].find('\n').unwrap() - 1; |
| 2143 | + let path = Path::new(&stderr[start..(end + start)]); |
| 2144 | + assert!(path.exists()); |
| 2145 | + assert!(path.join("release/deps").exists()); |
| 2146 | +} |
| 2147 | + |
| 2148 | +#[cargo_test] |
| 2149 | +fn sparse_install() { |
| 2150 | + // Checks for an issue where uninstalling something corrupted |
| 2151 | + // the SourceIds of sparse registries. |
| 2152 | + // See https://github.com/rust-lang/cargo/issues/11751 |
| 2153 | + let _registry = registry::RegistryBuilder::new().http_index().build(); |
| 2154 | + |
| 2155 | + pkg("foo", "0.0.1"); |
| 2156 | + pkg("bar", "0.0.1"); |
| 2157 | + |
| 2158 | + cargo_process("install foo --registry dummy-registry") |
| 2159 | + .with_stderr( |
| 2160 | + "\ |
| 2161 | +[UPDATING] `dummy-registry` index |
| 2162 | +[DOWNLOADING] crates ... |
| 2163 | +[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`) |
| 2164 | +[INSTALLING] foo v0.0.1 (registry `dummy-registry`) |
| 2165 | +[UPDATING] `dummy-registry` index |
| 2166 | +[COMPILING] foo v0.0.1 (registry `dummy-registry`) |
| 2167 | +[FINISHED] release [optimized] target(s) in [..] |
| 2168 | +[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE] |
| 2169 | +[INSTALLED] package `foo v0.0.1 (registry `dummy-registry`)` (executable `foo[EXE]`) |
| 2170 | +[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries |
| 2171 | +", |
| 2172 | + ) |
| 2173 | + .run(); |
| 2174 | + assert_has_installed_exe(cargo_home(), "foo"); |
| 2175 | + let assert_v1 = |expected| { |
| 2176 | + let v1 = fs::read_to_string(paths::home().join(".cargo/.crates.toml")).unwrap(); |
| 2177 | + compare::assert_match_exact(expected, &v1); |
| 2178 | + }; |
| 2179 | + assert_v1( |
| 2180 | + r#"[v1] |
| 2181 | +"foo 0.0.1 (sparse+http://127.0.0.1:[..]/index/)" = ["foo[EXE]"] |
| 2182 | +"#, |
| 2183 | + ); |
| 2184 | + cargo_process("install bar").run(); |
| 2185 | + assert_has_installed_exe(cargo_home(), "bar"); |
| 2186 | + assert_v1( |
| 2187 | + r#"[v1] |
| 2188 | +"bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = ["bar[EXE]"] |
| 2189 | +"foo 0.0.1 (sparse+http://127.0.0.1:[..]/index/)" = ["foo[EXE]"] |
| 2190 | +"#, |
| 2191 | + ); |
| 2192 | + |
| 2193 | + cargo_process("uninstall bar") |
| 2194 | + .with_stderr("[REMOVING] [CWD]/home/.cargo/bin/bar[EXE]") |
| 2195 | + .run(); |
| 2196 | + assert_has_not_installed_exe(cargo_home(), "bar"); |
| 2197 | + assert_v1( |
| 2198 | + r#"[v1] |
| 2199 | +"foo 0.0.1 (sparse+http://127.0.0.1:[..]/index/)" = ["foo[EXE]"] |
| 2200 | +"#, |
| 2201 | + ); |
| 2202 | + cargo_process("uninstall foo") |
| 2203 | + .with_stderr("[REMOVING] [CWD]/home/.cargo/bin/foo[EXE]") |
| 2204 | + .run(); |
| 2205 | + assert_has_not_installed_exe(cargo_home(), "foo"); |
| 2206 | + assert_v1( |
| 2207 | + r#"[v1] |
| 2208 | +"#, |
| 2209 | + ); |
| 2210 | +} |
0 commit comments