Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable some tests on windows. #9893

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion crates/cargo-test-support/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

use crate::{basic_manifest, paths, project, Project};
use lazy_static::lazy_static;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::Mutex;

lazy_static! {
static ref ECHO_WRAPPER: Mutex<Option<PathBuf>> = Mutex::new(None);
static ref ECHO: Mutex<Option<PathBuf>> = Mutex::new(None);
}

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

/// Returns the path to an executable that prints its arguments.
///
/// Do not expect this to be anything fancy.
pub fn echo() -> PathBuf {
let mut lock = ECHO.lock().unwrap();
if let Some(path) = &*lock {
return path.clone();
}
if let Ok(path) = cargo_util::paths::resolve_executable(Path::new("echo")) {
*lock = Some(path.clone());
return path;
}
// Often on Windows, `echo` is not available.
let p = project()
.at(paths::global_root().join("basic-echo"))
.file("Cargo.toml", &basic_manifest("basic-echo", "1.0.0"))
.file(
"src/main.rs",
r#"
fn main() {
let mut s = String::new();
let mut it = std::env::args().skip(1).peekable();
while let Some(n) = it.next() {
s.push_str(&n);
if it.peek().is_some() {
s.push(' ');
}
}
println!("{}", s);
}
"#,
)
.build();
p.cargo("build").run();
let path = p.bin("basic-echo");
*lock = Some(path.clone());
path
}

/// Returns a project which builds a cargo-echo simple subcommand
pub fn echo_subcommand() -> Project {
let p = project()
Expand Down
30 changes: 14 additions & 16 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cargo::core::compiler::RustDocFingerprint;
use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, project};
use cargo_test_support::{is_nightly, rustc_host, symlink_supported};
use cargo_test_support::{is_nightly, rustc_host, symlink_supported, tools};
use std::fs;
use std::str;

Expand Down Expand Up @@ -1250,7 +1250,6 @@ fn doc_all_member_dependency_same_name() {
}

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

// The order in which bar is compiled or documented is not deterministic
p.cargo("doc --workspace --open")
.env("BROWSER", "echo")
.env("BROWSER", tools::echo())
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
.with_stderr_contains("[..] Opening [..]/bar/index.html")
.run();
}

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

p.cargo("doc -v --no-deps -Zrustdoc-map --open")
.env("BROWSER", "echo")
.env("BROWSER", tools::echo())
.masquerade_as_nightly_cargo()
.with_stderr(
"\
Expand All @@ -1311,7 +1309,6 @@ fn doc_extern_map_local() {
}

#[cargo_test]
#[cfg(not(windows))] // `echo` may not be available
fn doc_workspace_open_different_library_and_package_names() {
let p = project()
.file(
Expand All @@ -1335,29 +1332,31 @@ fn doc_workspace_open_different_library_and_package_names() {
.build();

p.cargo("doc --open")
.env("BROWSER", "echo")
.env("BROWSER", tools::echo())
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
.with_stderr_contains("[..] [CWD]/target/doc/foolib/index.html")
.with_stdout_contains("[CWD]/target/doc/foolib/index.html")
.run();

p.change_file(
".cargo/config.toml",
r#"
[doc]
browser = ["echo", "a"]
"#,
&format!(
r#"
[doc]
browser = ["{}", "a"]
"#,
tools::echo().display().to_string().replace('\\', "\\\\")
),
);

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

#[cargo_test]
#[cfg(not(windows))] // `echo` may not be available
fn doc_workspace_open_binary() {
let p = project()
.file(
Expand All @@ -1382,14 +1381,13 @@ fn doc_workspace_open_binary() {
.build();

p.cargo("doc --open")
.env("BROWSER", "echo")
.env("BROWSER", tools::echo())
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
.with_stderr_contains("[..] Opening [CWD]/target/doc/foobin/index.html")
.run();
}

#[cargo_test]
#[cfg(not(windows))] // `echo` may not be available
fn doc_workspace_open_binary_and_library() {
let p = project()
.file(
Expand Down Expand Up @@ -1417,7 +1415,7 @@ fn doc_workspace_open_binary_and_library() {
.build();

p.cargo("doc --open")
.env("BROWSER", "echo")
.env("BROWSER", tools::echo())
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
.with_stderr_contains("[..] Opening [CWD]/target/doc/foolib/index.html")
.run();
Expand Down