Skip to content

Commit d7f413d

Browse files
committed
Auto merge of #9893 - ehuss:windows-echo, r=alexcrichton
Enable some tests on windows. This enables some more tests on windows that were disabled because `echo` is not always available. It's pretty easy to make a custom `echo`, so that's what this does. I'm generally not comfortable with disabling tests just because there is an inconvenience like this.
2 parents 4168727 + 422d5b0 commit d7f413d

File tree

2 files changed

+55
-17
lines changed

2 files changed

+55
-17
lines changed

crates/cargo-test-support/src/tools.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
33
use crate::{basic_manifest, paths, project, Project};
44
use lazy_static::lazy_static;
5-
use std::path::PathBuf;
5+
use std::path::{Path, PathBuf};
66
use std::sync::Mutex;
77

88
lazy_static! {
99
static ref ECHO_WRAPPER: Mutex<Option<PathBuf>> = Mutex::new(None);
10+
static ref ECHO: Mutex<Option<PathBuf>> = Mutex::new(None);
1011
}
1112

1213
/// Returns the path to an executable that works as a wrapper around rustc.
@@ -39,6 +40,45 @@ pub fn echo_wrapper() -> PathBuf {
3940
path
4041
}
4142

43+
/// Returns the path to an executable that prints its arguments.
44+
///
45+
/// Do not expect this to be anything fancy.
46+
pub fn echo() -> PathBuf {
47+
let mut lock = ECHO.lock().unwrap();
48+
if let Some(path) = &*lock {
49+
return path.clone();
50+
}
51+
if let Ok(path) = cargo_util::paths::resolve_executable(Path::new("echo")) {
52+
*lock = Some(path.clone());
53+
return path;
54+
}
55+
// Often on Windows, `echo` is not available.
56+
let p = project()
57+
.at(paths::global_root().join("basic-echo"))
58+
.file("Cargo.toml", &basic_manifest("basic-echo", "1.0.0"))
59+
.file(
60+
"src/main.rs",
61+
r#"
62+
fn main() {
63+
let mut s = String::new();
64+
let mut it = std::env::args().skip(1).peekable();
65+
while let Some(n) = it.next() {
66+
s.push_str(&n);
67+
if it.peek().is_some() {
68+
s.push(' ');
69+
}
70+
}
71+
println!("{}", s);
72+
}
73+
"#,
74+
)
75+
.build();
76+
p.cargo("build").run();
77+
let path = p.bin("basic-echo");
78+
*lock = Some(path.clone());
79+
path
80+
}
81+
4282
/// Returns a project which builds a cargo-echo simple subcommand
4383
pub fn echo_subcommand() -> Project {
4484
let p = project()

tests/testsuite/doc.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use cargo::core::compiler::RustDocFingerprint;
44
use cargo_test_support::paths::CargoPathExt;
55
use cargo_test_support::registry::Package;
66
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, project};
7-
use cargo_test_support::{is_nightly, rustc_host, symlink_supported};
7+
use cargo_test_support::{is_nightly, rustc_host, symlink_supported, tools};
88
use std::fs;
99
use std::str;
1010

@@ -1250,7 +1250,6 @@ fn doc_all_member_dependency_same_name() {
12501250
}
12511251

12521252
#[cargo_test]
1253-
#[cfg(not(windows))] // `echo` may not be available
12541253
fn doc_workspace_open_help_message() {
12551254
let p = project()
12561255
.file(
@@ -1268,15 +1267,14 @@ fn doc_workspace_open_help_message() {
12681267

12691268
// The order in which bar is compiled or documented is not deterministic
12701269
p.cargo("doc --workspace --open")
1271-
.env("BROWSER", "echo")
1270+
.env("BROWSER", tools::echo())
12721271
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
12731272
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
12741273
.with_stderr_contains("[..] Opening [..]/bar/index.html")
12751274
.run();
12761275
}
12771276

12781277
#[cargo_test]
1279-
#[cfg(not(windows))] // `echo` may not be available
12801278
fn doc_extern_map_local() {
12811279
if !is_nightly() {
12821280
// -Zextern-html-root-url is unstable
@@ -1297,7 +1295,7 @@ fn doc_extern_map_local() {
12971295
.build();
12981296

12991297
p.cargo("doc -v --no-deps -Zrustdoc-map --open")
1300-
.env("BROWSER", "echo")
1298+
.env("BROWSER", tools::echo())
13011299
.masquerade_as_nightly_cargo()
13021300
.with_stderr(
13031301
"\
@@ -1311,7 +1309,6 @@ fn doc_extern_map_local() {
13111309
}
13121310

13131311
#[cargo_test]
1314-
#[cfg(not(windows))] // `echo` may not be available
13151312
fn doc_workspace_open_different_library_and_package_names() {
13161313
let p = project()
13171314
.file(
@@ -1335,29 +1332,31 @@ fn doc_workspace_open_different_library_and_package_names() {
13351332
.build();
13361333

13371334
p.cargo("doc --open")
1338-
.env("BROWSER", "echo")
1335+
.env("BROWSER", tools::echo())
13391336
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
13401337
.with_stderr_contains("[..] [CWD]/target/doc/foolib/index.html")
13411338
.with_stdout_contains("[CWD]/target/doc/foolib/index.html")
13421339
.run();
13431340

13441341
p.change_file(
13451342
".cargo/config.toml",
1346-
r#"
1347-
[doc]
1348-
browser = ["echo", "a"]
1349-
"#,
1343+
&format!(
1344+
r#"
1345+
[doc]
1346+
browser = ["{}", "a"]
1347+
"#,
1348+
tools::echo().display().to_string().replace('\\', "\\\\")
1349+
),
13501350
);
13511351

13521352
// check that the cargo config overrides the browser env var
13531353
p.cargo("doc --open")
1354-
.env("BROWSER", "true")
1354+
.env("BROWSER", "do_not_run_me")
13551355
.with_stdout_contains("a [CWD]/target/doc/foolib/index.html")
13561356
.run();
13571357
}
13581358

13591359
#[cargo_test]
1360-
#[cfg(not(windows))] // `echo` may not be available
13611360
fn doc_workspace_open_binary() {
13621361
let p = project()
13631362
.file(
@@ -1382,14 +1381,13 @@ fn doc_workspace_open_binary() {
13821381
.build();
13831382

13841383
p.cargo("doc --open")
1385-
.env("BROWSER", "echo")
1384+
.env("BROWSER", tools::echo())
13861385
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
13871386
.with_stderr_contains("[..] Opening [CWD]/target/doc/foobin/index.html")
13881387
.run();
13891388
}
13901389

13911390
#[cargo_test]
1392-
#[cfg(not(windows))] // `echo` may not be available
13931391
fn doc_workspace_open_binary_and_library() {
13941392
let p = project()
13951393
.file(
@@ -1417,7 +1415,7 @@ fn doc_workspace_open_binary_and_library() {
14171415
.build();
14181416

14191417
p.cargo("doc --open")
1420-
.env("BROWSER", "echo")
1418+
.env("BROWSER", tools::echo())
14211419
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
14221420
.with_stderr_contains("[..] Opening [CWD]/target/doc/foolib/index.html")
14231421
.run();

0 commit comments

Comments
 (0)