|
3 | 3 | use std::fs::{self, OpenOptions}; |
4 | 4 | use std::io::prelude::*; |
5 | 5 |
|
6 | | -use cargo_test_support::cross_compile; |
| 6 | +use cargo_test_support::{cross_compile, compare}; |
7 | 7 | use cargo_test_support::git; |
8 | 8 | use cargo_test_support::registry::{self, registry_path, Package}; |
9 | 9 | use cargo_test_support::{ |
@@ -2105,3 +2105,67 @@ fn no_auto_fix_note() { |
2105 | 2105 | .run(); |
2106 | 2106 | assert_has_not_installed_exe(cargo_home(), "auto_fix"); |
2107 | 2107 | } |
| 2108 | + |
| 2109 | +#[cargo_test] |
| 2110 | +fn sparse_install() { |
| 2111 | + // Checks for an issue where uninstalling something corrupted |
| 2112 | + // the SourceIds of sparse registries. |
| 2113 | + // See https://github.com/rust-lang/cargo/issues/11751 |
| 2114 | + let _registry = registry::RegistryBuilder::new().http_index().build(); |
| 2115 | + |
| 2116 | + pkg("foo", "0.0.1"); |
| 2117 | + pkg("bar", "0.0.1"); |
| 2118 | + |
| 2119 | + cargo_process("install foo --registry dummy-registry") |
| 2120 | + .with_stderr( |
| 2121 | + "\ |
| 2122 | +[UPDATING] `dummy-registry` index |
| 2123 | +[DOWNLOADING] crates ... |
| 2124 | +[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`) |
| 2125 | +[INSTALLING] foo v0.0.1 (registry `dummy-registry`) |
| 2126 | +[UPDATING] `dummy-registry` index |
| 2127 | +[COMPILING] foo v0.0.1 (registry `dummy-registry`) |
| 2128 | +[FINISHED] release [optimized] target(s) in [..] |
| 2129 | +[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE] |
| 2130 | +[INSTALLED] package `foo v0.0.1 (registry `dummy-registry`)` (executable `foo[EXE]`) |
| 2131 | +[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries |
| 2132 | +", |
| 2133 | + ) |
| 2134 | + .run(); |
| 2135 | + assert_has_installed_exe(cargo_home(), "foo"); |
| 2136 | + let assert_v1 = |expected| { |
| 2137 | + let v1 = fs::read_to_string(paths::home().join(".cargo/.crates.toml")).unwrap(); |
| 2138 | + compare::assert_match_exact(expected, &v1); |
| 2139 | + }; |
| 2140 | + assert_v1( |
| 2141 | + r#"[v1] |
| 2142 | +"foo 0.0.1 (sparse+http://127.0.0.1:[..]/index/)" = ["foo[EXE]"] |
| 2143 | +"#, |
| 2144 | + ); |
| 2145 | + cargo_process("install bar").run(); |
| 2146 | + assert_has_installed_exe(cargo_home(), "bar"); |
| 2147 | + assert_v1( |
| 2148 | + r#"[v1] |
| 2149 | +"bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = ["bar[EXE]"] |
| 2150 | +"foo 0.0.1 (sparse+http://127.0.0.1:[..]/index/)" = ["foo[EXE]"] |
| 2151 | +"#, |
| 2152 | + ); |
| 2153 | + |
| 2154 | + cargo_process("uninstall bar") |
| 2155 | + .with_stderr("[REMOVING] [CWD]/home/.cargo/bin/bar[EXE]") |
| 2156 | + .run(); |
| 2157 | + assert_has_not_installed_exe(cargo_home(), "bar"); |
| 2158 | + assert_v1( |
| 2159 | + r#"[v1] |
| 2160 | +"foo 0.0.1 (sparse+http://127.0.0.1:[..]/index/)" = ["foo[EXE]"] |
| 2161 | +"#, |
| 2162 | + ); |
| 2163 | + cargo_process("uninstall foo") |
| 2164 | + .with_stderr("[REMOVING] [CWD]/home/.cargo/bin/foo[EXE]") |
| 2165 | + .run(); |
| 2166 | + assert_has_not_installed_exe(cargo_home(), "foo"); |
| 2167 | + assert_v1( |
| 2168 | + r#"[v1] |
| 2169 | +"#, |
| 2170 | + ); |
| 2171 | +} |
0 commit comments