|
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,
|
@@ -2103,3 +2106,39 @@ fn no_auto_fix_note() {
|
2103 | 2106 | .run();
|
2104 | 2107 | assert_has_not_installed_exe(cargo_home(), "auto_fix");
|
2105 | 2108 | }
|
| 2109 | + |
| 2110 | +#[cargo_test] |
| 2111 | +fn failed_install_retains_temp_directory() { |
| 2112 | + // Verifies that the temporary directory persists after a build failure. |
| 2113 | + Package::new("foo", "0.0.1") |
| 2114 | + .file("src/main.rs", "x") |
| 2115 | + .publish(); |
| 2116 | + let err = cargo_process("install foo").exec_with_output().unwrap_err(); |
| 2117 | + let err = err.downcast::<ProcessError>().unwrap(); |
| 2118 | + let stderr = String::from_utf8(err.stderr.unwrap()).unwrap(); |
| 2119 | + compare::match_contains( |
| 2120 | + "\ |
| 2121 | +[UPDATING] `dummy-registry` index |
| 2122 | +[DOWNLOADING] crates ... |
| 2123 | +[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`) |
| 2124 | +[INSTALLING] foo v0.0.1 |
| 2125 | +[COMPILING] foo v0.0.1 |
| 2126 | +", |
| 2127 | + &stderr, |
| 2128 | + None, |
| 2129 | + ) |
| 2130 | + .unwrap(); |
| 2131 | + compare::match_contains( |
| 2132 | + "error: failed to compile `foo v0.0.1`, intermediate artifacts can be found at `[..]`", |
| 2133 | + &stderr, |
| 2134 | + None, |
| 2135 | + ) |
| 2136 | + .unwrap(); |
| 2137 | + |
| 2138 | + // Find the path in the output. |
| 2139 | + let start = stderr.find("found at `").unwrap() + 10; |
| 2140 | + let end = stderr[start..].find('\n').unwrap() - 1; |
| 2141 | + let path = Path::new(&stderr[start..(end + start)]); |
| 2142 | + assert!(path.exists()); |
| 2143 | + assert!(path.join("release/deps").exists()); |
| 2144 | +} |
0 commit comments