Migrate runmake tests away from custom commands and command_output
This commit is contained in:
parent
18ae9afa82
commit
0a190e8d2d
30 changed files with 176 additions and 141 deletions
|
@ -1,7 +1,7 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::{bin_name, cygpath_windows, env_var, handle_failed_output, is_msvc, is_windows, uname};
|
|
||||||
use crate::command::Command;
|
use crate::command::Command;
|
||||||
|
use crate::{bin_name, cygpath_windows, env_var, is_msvc, is_windows, uname};
|
||||||
|
|
||||||
/// Construct a new platform-specific C compiler invocation.
|
/// Construct a new platform-specific C compiler invocation.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::{bin_name, env_var, handle_failed_output};
|
|
||||||
use crate::command::Command;
|
use crate::command::Command;
|
||||||
|
use crate::{bin_name, env_var};
|
||||||
|
|
||||||
/// Construct a new `clang` invocation. `clang` is not always available for all targets.
|
/// Construct a new `clang` invocation. `clang` is not always available for all targets.
|
||||||
pub fn clang() -> Clang {
|
pub fn clang() -> Clang {
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
|
use crate::{assert_not_contains, handle_failed_output};
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::process::{Command as StdCommand, ExitStatus, Output, Stdio};
|
use std::process::{Command as StdCommand, ExitStatus, Output, Stdio};
|
||||||
|
|
||||||
|
/// This is a custom command wrapper that simplifies working with commands
|
||||||
|
/// and makes it easier to ensure that we check the exit status of executed
|
||||||
|
/// processes.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Command {
|
pub struct Command {
|
||||||
cmd: StdCommand,
|
cmd: StdCommand,
|
||||||
|
@ -11,16 +15,39 @@ pub struct Command {
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn new<S: AsRef<OsStr>>(program: S) -> Self {
|
pub fn new<S: AsRef<OsStr>>(program: S) -> Self {
|
||||||
Self {
|
Self { cmd: StdCommand::new(program), stdin: None }
|
||||||
cmd: StdCommand::new(program),
|
|
||||||
stdin: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_stdin(&mut self, stdin: Box<[u8]>) {
|
pub fn set_stdin(&mut self, stdin: Box<[u8]>) {
|
||||||
self.stdin = Some(stdin);
|
self.stdin = Some(stdin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Run the constructed command and assert that it is successfully run.
|
||||||
|
#[track_caller]
|
||||||
|
pub fn run(&mut self) -> CompletedProcess {
|
||||||
|
let caller_location = std::panic::Location::caller();
|
||||||
|
let caller_line_number = caller_location.line();
|
||||||
|
|
||||||
|
let output = self.command_output();
|
||||||
|
if !output.status().success() {
|
||||||
|
handle_failed_output(&self, output, caller_line_number);
|
||||||
|
}
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Run the constructed command and assert that it does not successfully run.
|
||||||
|
#[track_caller]
|
||||||
|
pub fn run_fail(&mut self) -> CompletedProcess {
|
||||||
|
let caller_location = std::panic::Location::caller();
|
||||||
|
let caller_line_number = caller_location.line();
|
||||||
|
|
||||||
|
let output = self.command_output();
|
||||||
|
if output.status().success() {
|
||||||
|
handle_failed_output(&self, output, caller_line_number);
|
||||||
|
}
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub(crate) fn command_output(&mut self) -> CompletedProcess {
|
pub(crate) fn command_output(&mut self) -> CompletedProcess {
|
||||||
// let's make sure we piped all the input and outputs
|
// let's make sure we piped all the input and outputs
|
||||||
|
@ -59,6 +86,8 @@ impl DerefMut for Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the result of an executed process.
|
/// Represents the result of an executed process.
|
||||||
|
/// The various `assert_` helper methods should preferably be used for
|
||||||
|
/// checking the contents of stdout/stderr.
|
||||||
pub struct CompletedProcess {
|
pub struct CompletedProcess {
|
||||||
output: Output,
|
output: Output,
|
||||||
}
|
}
|
||||||
|
@ -76,16 +105,47 @@ impl CompletedProcess {
|
||||||
self.output.status
|
self.output.status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks that trimmed `stdout` matches trimmed `content`.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn assert_exit_code(&self, code: i32) {
|
pub fn assert_stdout_equals<S: AsRef<str>>(self, content: S) -> Self {
|
||||||
|
assert_eq!(self.stdout_utf8().trim(), content.as_ref().trim());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
pub fn assert_stdout_not_contains<S: AsRef<str>>(self, needle: S) -> Self {
|
||||||
|
assert_not_contains(&self.stdout_utf8(), needle.as_ref());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks that trimmed `stderr` matches trimmed `content`.
|
||||||
|
#[track_caller]
|
||||||
|
pub fn assert_stderr_equals<S: AsRef<str>>(self, content: S) -> Self {
|
||||||
|
assert_eq!(self.stderr_utf8().trim(), content.as_ref().trim());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
pub fn assert_stderr_contains<S: AsRef<str>>(self, needle: S) -> Self {
|
||||||
|
assert!(self.stderr_utf8().contains(needle.as_ref()));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
pub fn assert_stderr_not_contains<S: AsRef<str>>(self, needle: S) -> Self {
|
||||||
|
assert_not_contains(&self.stdout_utf8(), needle.as_ref());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
pub fn assert_exit_code(self, code: i32) -> Self {
|
||||||
assert!(self.output.status.code() == Some(code));
|
assert!(self.output.status.code() == Some(code));
|
||||||
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Output> for CompletedProcess {
|
impl From<Output> for CompletedProcess {
|
||||||
fn from(output: Output) -> Self {
|
fn from(output: Output) -> Self {
|
||||||
Self {
|
Self { output }
|
||||||
output
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
|
|
||||||
pub mod cc;
|
pub mod cc;
|
||||||
pub mod clang;
|
pub mod clang;
|
||||||
|
mod command;
|
||||||
pub mod diff;
|
pub mod diff;
|
||||||
pub mod llvm_readobj;
|
pub mod llvm_readobj;
|
||||||
pub mod run;
|
pub mod run;
|
||||||
pub mod rustc;
|
pub mod rustc;
|
||||||
pub mod rustdoc;
|
pub mod rustdoc;
|
||||||
mod command;
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
|
@ -27,7 +27,7 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
|
||||||
pub use clang::{clang, Clang};
|
pub use clang::{clang, Clang};
|
||||||
pub use diff::{diff, Diff};
|
pub use diff::{diff, Diff};
|
||||||
pub use llvm_readobj::{llvm_readobj, LlvmReadobj};
|
pub use llvm_readobj::{llvm_readobj, LlvmReadobj};
|
||||||
pub use run::{run, run_fail};
|
pub use run::{cmd, run, run_fail};
|
||||||
pub use rustc::{aux_build, rustc, Rustc};
|
pub use rustc::{aux_build, rustc, Rustc};
|
||||||
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};
|
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};
|
||||||
|
|
||||||
|
@ -285,6 +285,7 @@ pub fn read_dir<F: Fn(&Path)>(dir: impl AsRef<Path>, callback: F) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check that `haystack` does not contain `needle`. Panic otherwise.
|
/// Check that `haystack` does not contain `needle`. Panic otherwise.
|
||||||
|
#[track_caller]
|
||||||
pub fn assert_not_contains(haystack: &str, needle: &str) {
|
pub fn assert_not_contains(haystack: &str, needle: &str) {
|
||||||
if haystack.contains(needle) {
|
if haystack.contains(needle) {
|
||||||
eprintln!("=== HAYSTACK ===");
|
eprintln!("=== HAYSTACK ===");
|
||||||
|
@ -412,27 +413,13 @@ macro_rules! impl_common_helpers {
|
||||||
/// Run the constructed command and assert that it is successfully run.
|
/// Run the constructed command and assert that it is successfully run.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn run(&mut self) -> crate::command::CompletedProcess {
|
pub fn run(&mut self) -> crate::command::CompletedProcess {
|
||||||
let caller_location = ::std::panic::Location::caller();
|
self.cmd.run()
|
||||||
let caller_line_number = caller_location.line();
|
|
||||||
|
|
||||||
let output = self.cmd.command_output();
|
|
||||||
if !output.status().success() {
|
|
||||||
handle_failed_output(&self.cmd, output, caller_line_number);
|
|
||||||
}
|
|
||||||
output
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run the constructed command and assert that it does not successfully run.
|
/// Run the constructed command and assert that it does not successfully run.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn run_fail(&mut self) -> crate::command::CompletedProcess {
|
pub fn run_fail(&mut self) -> crate::command::CompletedProcess {
|
||||||
let caller_location = ::std::panic::Location::caller();
|
self.cmd.run_fail()
|
||||||
let caller_line_number = caller_location.line();
|
|
||||||
|
|
||||||
let output = self.cmd.command_output();
|
|
||||||
if output.status().success() {
|
|
||||||
handle_failed_output(&self.cmd, output, caller_line_number);
|
|
||||||
}
|
|
||||||
output
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the path where the command will be run.
|
/// Set the path where the command will be run.
|
||||||
|
@ -444,5 +431,5 @@ macro_rules! impl_common_helpers {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) use impl_common_helpers;
|
|
||||||
use crate::command::{Command, CompletedProcess};
|
use crate::command::{Command, CompletedProcess};
|
||||||
|
pub(crate) use impl_common_helpers;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use crate::{env_var, handle_failed_output};
|
|
||||||
use crate::command::Command;
|
use crate::command::Command;
|
||||||
|
use crate::env_var;
|
||||||
|
|
||||||
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
|
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
|
||||||
/// at `$LLVM_BIN_DIR/llvm-readobj`.
|
/// at `$LLVM_BIN_DIR/llvm-readobj`.
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::ffi::OsStr;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use crate::{cwd, env_var, is_windows};
|
|
||||||
use crate::command::{Command, CompletedProcess};
|
use crate::command::{Command, CompletedProcess};
|
||||||
|
use crate::{cwd, env_var, is_windows, set_host_rpath};
|
||||||
|
|
||||||
use super::handle_failed_output;
|
use super::handle_failed_output;
|
||||||
|
|
||||||
|
@ -62,3 +63,11 @@ pub fn run_fail(name: &str) -> CompletedProcess {
|
||||||
}
|
}
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new custom Command.
|
||||||
|
/// This should be preferred to creating `std::process::Command` directly.
|
||||||
|
pub fn cmd<S: AsRef<OsStr>>(program: S) -> Command {
|
||||||
|
let mut command = Command::new(program);
|
||||||
|
set_host_rpath(&mut command);
|
||||||
|
command
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
use command::Command;
|
||||||
use std::ffi::{OsStr, OsString};
|
use std::ffi::{OsStr, OsString};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use command::Command;
|
|
||||||
|
|
||||||
use crate::{command, cwd, env_var, handle_failed_output, set_host_rpath};
|
use crate::{command, cwd, env_var, set_host_rpath};
|
||||||
|
|
||||||
/// Construct a new `rustc` invocation.
|
/// Construct a new `rustc` invocation.
|
||||||
pub fn rustc() -> Rustc {
|
pub fn rustc() -> Rustc {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::{env_var, env_var_os, handle_failed_output, set_host_rpath};
|
|
||||||
use crate::command::Command;
|
use crate::command::Command;
|
||||||
|
use crate::{env_var, env_var_os, set_host_rpath};
|
||||||
|
|
||||||
/// Construct a plain `rustdoc` invocation with no flags set.
|
/// Construct a plain `rustdoc` invocation with no flags set.
|
||||||
pub fn bare_rustdoc() -> Rustdoc {
|
pub fn bare_rustdoc() -> Rustdoc {
|
||||||
|
|
|
@ -10,14 +10,10 @@ use run_make_support::{aux_build, rustc, source_root};
|
||||||
fn main() {
|
fn main() {
|
||||||
aux_build().input("stable.rs").emit("metadata").run();
|
aux_build().input("stable.rs").emit("metadata").run();
|
||||||
|
|
||||||
let output = rustc()
|
let output =
|
||||||
.input("main.rs")
|
rustc().input("main.rs").emit("metadata").extern_("stable", "libstable.rmeta").run();
|
||||||
.emit("metadata")
|
|
||||||
.extern_("stable", "libstable.rmeta")
|
|
||||||
.command_output();
|
|
||||||
|
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
||||||
let version = std::fs::read_to_string(source_root().join("src/version")).unwrap();
|
let version = std::fs::read_to_string(source_root().join("src/version")).unwrap();
|
||||||
let expected_string = format!("stable since {}", version.trim());
|
let expected_string = format!("stable since {}", version.trim());
|
||||||
assert!(stderr.contains(&expected_string));
|
output.assert_stderr_contains(expected_string);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
// Test that `-Awarnings` suppresses warnings for unstable APIs.
|
// Test that `-Awarnings` suppresses warnings for unstable APIs.
|
||||||
|
|
||||||
use run_make_support::{assert_not_contains, rustc};
|
use run_make_support::rustc;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
rustc().input("bar.rs").run();
|
rustc().input("bar.rs").run();
|
||||||
let output = rustc().input("foo.rs").arg("-Awarnings").run();
|
rustc()
|
||||||
|
.input("foo.rs")
|
||||||
assert_not_contains(&String::from_utf8(output.stdout).unwrap(), "warning");
|
.arg("-Awarnings")
|
||||||
assert_not_contains(&String::from_utf8(output.stderr).unwrap(), "warning");
|
.run()
|
||||||
|
.assert_stdout_not_contains("warning")
|
||||||
|
.assert_stderr_not_contains("warning");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@ use run_make_support::object::read::Object;
|
||||||
use run_make_support::object::ObjectSection;
|
use run_make_support::object::ObjectSection;
|
||||||
use run_make_support::object::ObjectSymbol;
|
use run_make_support::object::ObjectSymbol;
|
||||||
use run_make_support::object::RelocationTarget;
|
use run_make_support::object::RelocationTarget;
|
||||||
use run_make_support::set_host_rpath;
|
use run_make_support::{cmd, env_var, object};
|
||||||
use run_make_support::{env_var, object};
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ fn main() {
|
||||||
let path = env_var("PATH");
|
let path = env_var("PATH");
|
||||||
let rustc = env_var("RUSTC");
|
let rustc = env_var("RUSTC");
|
||||||
let bootstrap_cargo = env_var("BOOTSTRAP_CARGO");
|
let bootstrap_cargo = env_var("BOOTSTRAP_CARGO");
|
||||||
let mut cmd = std::process::Command::new(bootstrap_cargo);
|
let mut cmd = cmd(bootstrap_cargo);
|
||||||
cmd.args([
|
cmd.args([
|
||||||
"build",
|
"build",
|
||||||
"--manifest-path",
|
"--manifest-path",
|
||||||
|
@ -52,10 +51,8 @@ fn main() {
|
||||||
// Visual Studio 2022 requires that the LIB env var be set so it can
|
// Visual Studio 2022 requires that the LIB env var be set so it can
|
||||||
// find the Windows SDK.
|
// find the Windows SDK.
|
||||||
.env("LIB", std::env::var("LIB").unwrap_or_default());
|
.env("LIB", std::env::var("LIB").unwrap_or_default());
|
||||||
set_host_rpath(&mut cmd);
|
|
||||||
|
|
||||||
let status = cmd.status().unwrap();
|
cmd.run();
|
||||||
assert!(status.success());
|
|
||||||
|
|
||||||
let rlibs_path = target_dir.join(target).join("debug").join("deps");
|
let rlibs_path = target_dir.join(target).join("debug").join("deps");
|
||||||
let compiler_builtins_rlib = std::fs::read_dir(rlibs_path)
|
let compiler_builtins_rlib = std::fs::read_dir(rlibs_path)
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::fs;
|
||||||
use run_make_support::{cwd, rustc};
|
use run_make_support::{cwd, rustc};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
rustc().input("input.rs").run_fail_assert_exit_code(1);
|
rustc().input("input.rs").run_fail().assert_exit_code(1);
|
||||||
|
|
||||||
for entry in fs::read_dir(cwd()).unwrap() {
|
for entry in fs::read_dir(cwd()).unwrap() {
|
||||||
let entry = entry.unwrap();
|
let entry = entry.unwrap();
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
use std::process::Output;
|
|
||||||
|
|
||||||
use run_make_support::{bin_name, rust_lib_name, rustc};
|
use run_make_support::{bin_name, rust_lib_name, rustc};
|
||||||
|
|
||||||
fn compare_stdout<S: AsRef<str>>(output: Output, expected: S) {
|
|
||||||
assert_eq!(String::from_utf8(output.stdout).unwrap().trim(), expected.as_ref());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
compare_stdout(rustc().print("crate-name").input("crate.rs").run(), "foo");
|
rustc().print("crate-name").input("crate.rs").run().assert_stdout_equals("foo");
|
||||||
compare_stdout(rustc().print("file-names").input("crate.rs").run(), bin_name("foo"));
|
rustc().print("file-names").input("crate.rs").run().assert_stdout_equals(bin_name("foo"));
|
||||||
compare_stdout(
|
rustc()
|
||||||
rustc().print("file-names").crate_type("lib").arg("--test").input("crate.rs").run(),
|
.print("file-names")
|
||||||
bin_name("foo"),
|
.crate_type("lib")
|
||||||
);
|
.arg("--test")
|
||||||
compare_stdout(
|
.input("crate.rs")
|
||||||
rustc().print("file-names").arg("--test").input("lib.rs").run(),
|
.run()
|
||||||
bin_name("mylib"),
|
.assert_stdout_equals(bin_name("foo"));
|
||||||
);
|
rustc()
|
||||||
compare_stdout(rustc().print("file-names").input("lib.rs").run(), rust_lib_name("mylib"));
|
.print("file-names")
|
||||||
compare_stdout(rustc().print("file-names").input("rlib.rs").run(), rust_lib_name("mylib"));
|
.arg("--test")
|
||||||
|
.input("lib.rs")
|
||||||
|
.run()
|
||||||
|
.assert_stdout_equals(bin_name("mylib"));
|
||||||
|
rustc().print("file-names").input("lib.rs").run().assert_stdout_equals(rust_lib_name("mylib"));
|
||||||
|
rustc().print("file-names").input("rlib.rs").run().assert_stdout_equals(rust_lib_name("mylib"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,21 +5,22 @@ use run_make_support::{rustc, rustdoc};
|
||||||
fn main() {
|
fn main() {
|
||||||
rustc().arg("success.rs").run();
|
rustc().arg("success.rs").run();
|
||||||
|
|
||||||
rustc().arg("--invalid-arg-foo").run_fail_assert_exit_code(1);
|
rustc().arg("--invalid-arg-foo").run_fail().assert_exit_code(1);
|
||||||
|
|
||||||
rustc().arg("compile-error.rs").run_fail_assert_exit_code(1);
|
rustc().arg("compile-error.rs").run_fail().assert_exit_code(1);
|
||||||
|
|
||||||
rustc()
|
rustc()
|
||||||
.env("RUSTC_ICE", "0")
|
.env("RUSTC_ICE", "0")
|
||||||
.arg("-Ztreat-err-as-bug")
|
.arg("-Ztreat-err-as-bug")
|
||||||
.arg("compile-error.rs")
|
.arg("compile-error.rs")
|
||||||
.run_fail_assert_exit_code(101);
|
.run_fail()
|
||||||
|
.assert_exit_code(101);
|
||||||
|
|
||||||
rustdoc().arg("success.rs").output("exit-code").run();
|
rustdoc().arg("success.rs").output("exit-code").run();
|
||||||
|
|
||||||
rustdoc().arg("--invalid-arg-foo").run_fail_assert_exit_code(1);
|
rustdoc().arg("--invalid-arg-foo").run_fail().assert_exit_code(1);
|
||||||
|
|
||||||
rustdoc().arg("compile-error.rs").run_fail_assert_exit_code(1);
|
rustdoc().arg("compile-error.rs").run_fail().assert_exit_code(1);
|
||||||
|
|
||||||
rustdoc().arg("lint-failure.rs").run_fail_assert_exit_code(1);
|
rustdoc().arg("lint-failure.rs").run_fail().assert_exit_code(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@ fn main() {
|
||||||
rustc().crate_type("rlib").input("foo.rs").run();
|
rustc().crate_type("rlib").input("foo.rs").run();
|
||||||
rustc().crate_type("dylib").input("bar1.rs").arg("-Cprefer-dynamic").run();
|
rustc().crate_type("dylib").input("bar1.rs").arg("-Cprefer-dynamic").run();
|
||||||
rustc().crate_type("dylib").input("bar2.rs").arg("-Cprefer-dynamic").run();
|
rustc().crate_type("dylib").input("bar2.rs").arg("-Cprefer-dynamic").run();
|
||||||
rustc().crate_type("dylib").input("baz2.rs").run_fail_assert_exit_code(1);
|
rustc().crate_type("dylib").input("baz2.rs").run_fail().assert_exit_code(1);
|
||||||
rustc().crate_type("bin").input("baz2.rs").run_fail_assert_exit_code(1);
|
rustc().crate_type("bin").input("baz2.rs").run_fail().assert_exit_code(1);
|
||||||
});
|
});
|
||||||
run_in_tmpdir(|| {
|
run_in_tmpdir(|| {
|
||||||
rustc().crate_type("rlib").input("foo.rs").run();
|
rustc().crate_type("rlib").input("foo.rs").run();
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
error: no input filename given
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use run_make_support::{diff, rustc};
|
use run_make_support::rustc;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let output = rustc().print("crate-name").run_fail_assert_exit_code(1);
|
rustc()
|
||||||
|
.print("crate-name")
|
||||||
diff().expected_file("no-input-file.stderr").actual_text("output", output.stderr).run();
|
.run_fail()
|
||||||
|
.assert_exit_code(1)
|
||||||
|
.assert_stderr_equals("error: no input filename given");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ fn main() {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
let non_unicode: std::ffi::OsString = std::os::windows::ffi::OsStringExt::from_wide(&[0xD800]);
|
let non_unicode: std::ffi::OsString = std::os::windows::ffi::OsStringExt::from_wide(&[0xD800]);
|
||||||
let output = rustc().input("non_unicode_env.rs").env("NON_UNICODE_VAR", non_unicode).run_fail();
|
let output = rustc().input("non_unicode_env.rs").env("NON_UNICODE_VAR", non_unicode).run_fail();
|
||||||
let actual = std::str::from_utf8(&output.stderr).unwrap();
|
|
||||||
let expected = std::fs::read_to_string("non_unicode_env.stderr").unwrap();
|
let expected = std::fs::read_to_string("non_unicode_env.stderr").unwrap();
|
||||||
assert_eq!(actual, expected);
|
output.assert_stderr_equals(expected);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ fn main() {
|
||||||
.error_format("json")
|
.error_format("json")
|
||||||
.incremental(cwd())
|
.incremental(cwd())
|
||||||
.run();
|
.run();
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
let stderr = output.stderr_utf8();
|
||||||
for file in &["lib.o", "lib.ll", "lib.bc", "lib.s"] {
|
for file in &["lib.o", "lib.ll", "lib.bc", "lib.s"] {
|
||||||
assert!(stderr.contains(file), "No {:?} in {:?}", file, stderr);
|
assert!(stderr.contains(file), "No {:?} in {:?}", file, stderr);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ fn main() {
|
||||||
.error_format("json")
|
.error_format("json")
|
||||||
.incremental(cwd())
|
.incremental(cwd())
|
||||||
.run();
|
.run();
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
let stderr = output.stderr_utf8();
|
||||||
for file in &["rcgu.o", "rcgu.ll", "rcgu.bc", "rcgu.s"] {
|
for file in &["rcgu.o", "rcgu.ll", "rcgu.bc", "rcgu.s"] {
|
||||||
assert!(stderr.contains(file), "No {:?} in {:?}", file, stderr);
|
assert!(stderr.contains(file), "No {:?} in {:?}", file, stderr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,8 +83,7 @@ fn check(PrintCfg { target, includes, disallow }: PrintCfg) {
|
||||||
// --print=cfg
|
// --print=cfg
|
||||||
{
|
{
|
||||||
let output = rustc().target(target).print("cfg").run();
|
let output = rustc().target(target).print("cfg").run();
|
||||||
|
let stdout = output.stdout_utf8();
|
||||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
|
||||||
|
|
||||||
check_(&stdout, includes, disallow);
|
check_(&stdout, includes, disallow);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +94,7 @@ fn check(PrintCfg { target, includes, disallow }: PrintCfg) {
|
||||||
let mut print_arg = OsString::from("--print=cfg=");
|
let mut print_arg = OsString::from("--print=cfg=");
|
||||||
print_arg.push(tmp_path.as_os_str());
|
print_arg.push(tmp_path.as_os_str());
|
||||||
|
|
||||||
let output = rustc().target(target).arg(print_arg).run();
|
rustc().target(target).arg(print_arg).run();
|
||||||
|
|
||||||
let output = std::fs::read_to_string(&tmp_path).unwrap();
|
let output = std::fs::read_to_string(&tmp_path).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ fn check(CheckCfg { args, contains }: CheckCfg) {
|
||||||
.args(&*args)
|
.args(&*args)
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
let stdout = output.stdout_utf8();
|
||||||
|
|
||||||
let mut found = HashSet::<String>::new();
|
let mut found = HashSet::<String>::new();
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,7 @@ fn main() {
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
let mut found_note = false;
|
let mut found_note = false;
|
||||||
for l in output.stderr.lines() {
|
for l in output.stderr_utf8().lines() {
|
||||||
let l = l.expect("utf-8 string");
|
|
||||||
|
|
||||||
let Some(args) = l.strip_prefix("note: native-static-libs:") else {
|
let Some(args) = l.strip_prefix("note: native-static-libs:") else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,11 +39,7 @@ fn check(args: Option) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// --print={option}
|
// --print={option}
|
||||||
let stdout = {
|
let stdout = rustc().target(args.target).print(args.option).run().stdout_utf8();
|
||||||
let output = rustc().target(args.target).print(args.option).run();
|
|
||||||
|
|
||||||
String::from_utf8(output.stdout).unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
// --print={option}=PATH
|
// --print={option}=PATH
|
||||||
let output = {
|
let output = {
|
||||||
|
@ -51,7 +47,7 @@ fn check(args: Option) {
|
||||||
let mut print_arg = OsString::from(format!("--print={}=", args.option));
|
let mut print_arg = OsString::from(format!("--print={}=", args.option));
|
||||||
print_arg.push(tmp_path.as_os_str());
|
print_arg.push(tmp_path.as_os_str());
|
||||||
|
|
||||||
let _output = rustc().target(args.target).arg(print_arg).run();
|
rustc().target(args.target).arg(print_arg).run();
|
||||||
|
|
||||||
std::fs::read_to_string(&tmp_path).unwrap()
|
std::fs::read_to_string(&tmp_path).unwrap()
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,9 +17,9 @@ fn main() {
|
||||||
.input("main.rs")
|
.input("main.rs")
|
||||||
.run();
|
.run();
|
||||||
assert!(
|
assert!(
|
||||||
find_lld_version_in_logs(&output),
|
find_lld_version_in_logs(output.stderr_utf8()),
|
||||||
"the LLD version string should be present in the output logs:\n{}",
|
"the LLD version string should be present in the output logs:\n{}",
|
||||||
std::str::from_utf8(&output.stderr).unwrap()
|
output.stderr_utf8()
|
||||||
);
|
);
|
||||||
|
|
||||||
// But it can still be disabled by turning the linker feature off.
|
// But it can still be disabled by turning the linker feature off.
|
||||||
|
@ -30,14 +30,13 @@ fn main() {
|
||||||
.input("main.rs")
|
.input("main.rs")
|
||||||
.run();
|
.run();
|
||||||
assert!(
|
assert!(
|
||||||
!find_lld_version_in_logs(&output),
|
!find_lld_version_in_logs(output.stderr_utf8()),
|
||||||
"the LLD version string should not be present in the output logs:\n{}",
|
"the LLD version string should not be present in the output logs:\n{}",
|
||||||
std::str::from_utf8(&output.stderr).unwrap()
|
output.stderr_utf8()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_lld_version_in_logs(output: &Output) -> bool {
|
fn find_lld_version_in_logs(stderr: String) -> bool {
|
||||||
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
|
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
|
||||||
let stderr = std::str::from_utf8(&output.stderr).unwrap();
|
|
||||||
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
|
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@ fn main() {
|
||||||
.input("lib.rs")
|
.input("lib.rs")
|
||||||
.run();
|
.run();
|
||||||
assert!(
|
assert!(
|
||||||
find_lld_version_in_logs(&output),
|
find_lld_version_in_logs(output.stderr_utf8()),
|
||||||
"the LLD version string should be present in the output logs:\n{}",
|
"the LLD version string should be present in the output logs:\n{}",
|
||||||
std::str::from_utf8(&output.stderr).unwrap()
|
output.stderr_utf8()
|
||||||
);
|
);
|
||||||
|
|
||||||
// But it can also be disabled via linker features.
|
// But it can also be disabled via linker features.
|
||||||
|
@ -38,14 +38,13 @@ fn main() {
|
||||||
.input("lib.rs")
|
.input("lib.rs")
|
||||||
.run();
|
.run();
|
||||||
assert!(
|
assert!(
|
||||||
!find_lld_version_in_logs(&output),
|
!find_lld_version_in_logs(output.stderr_utf8()),
|
||||||
"the LLD version string should not be present in the output logs:\n{}",
|
"the LLD version string should not be present in the output logs:\n{}",
|
||||||
std::str::from_utf8(&output.stderr).unwrap()
|
output.stderr_utf8()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_lld_version_in_logs(output: &Output) -> bool {
|
fn find_lld_version_in_logs(stderr: String) -> bool {
|
||||||
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
|
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
|
||||||
let stderr = std::str::from_utf8(&output.stderr).unwrap();
|
|
||||||
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
|
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@ fn main() {
|
||||||
.input("main.rs")
|
.input("main.rs")
|
||||||
.run();
|
.run();
|
||||||
assert!(
|
assert!(
|
||||||
find_lld_version_in_logs(&output),
|
find_lld_version_in_logs(output.stderr_utf8()),
|
||||||
"the LLD version string should be present in the output logs:\n{}",
|
"the LLD version string should be present in the output logs:\n{}",
|
||||||
std::str::from_utf8(&output.stderr).unwrap()
|
output.stderr_utf8()
|
||||||
);
|
);
|
||||||
|
|
||||||
// It should not be used when we explictly opt-out of lld.
|
// It should not be used when we explictly opt-out of lld.
|
||||||
|
@ -34,9 +34,9 @@ fn main() {
|
||||||
.input("main.rs")
|
.input("main.rs")
|
||||||
.run();
|
.run();
|
||||||
assert!(
|
assert!(
|
||||||
!find_lld_version_in_logs(&output),
|
!find_lld_version_in_logs(output.stderr_utf8()),
|
||||||
"the LLD version string should not be present in the output logs:\n{}",
|
"the LLD version string should not be present in the output logs:\n{}",
|
||||||
std::str::from_utf8(&output.stderr).unwrap()
|
output.stderr_utf8()
|
||||||
);
|
);
|
||||||
|
|
||||||
// While we're here, also check that the last linker feature flag "wins" when passed multiple
|
// While we're here, also check that the last linker feature flag "wins" when passed multiple
|
||||||
|
@ -52,14 +52,13 @@ fn main() {
|
||||||
.input("main.rs")
|
.input("main.rs")
|
||||||
.run();
|
.run();
|
||||||
assert!(
|
assert!(
|
||||||
find_lld_version_in_logs(&output),
|
find_lld_version_in_logs(output.stderr_utf8()),
|
||||||
"the LLD version string should be present in the output logs:\n{}",
|
"the LLD version string should be present in the output logs:\n{}",
|
||||||
std::str::from_utf8(&output.stderr).unwrap()
|
output.stderr_utf8()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_lld_version_in_logs(output: &Output) -> bool {
|
fn find_lld_version_in_logs(stderr: String) -> bool {
|
||||||
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
|
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
|
||||||
let stderr = std::str::from_utf8(&output.stderr).unwrap();
|
|
||||||
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
|
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,7 @@
|
||||||
use run_make_support::rustdoc;
|
use run_make_support::rustdoc;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let output =
|
let output = rustdoc().input("input.rs").arg("--test").run_fail().stdout_utf8();
|
||||||
String::from_utf8(rustdoc().input("input.rs").arg("--test").command_output().stdout)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let should_contain = &[
|
let should_contain = &[
|
||||||
"input.rs - foo (line 5)",
|
"input.rs - foo (line 5)",
|
||||||
|
|
|
@ -8,17 +8,14 @@ fn main() {
|
||||||
let proc_crate_name = "foobar_macro";
|
let proc_crate_name = "foobar_macro";
|
||||||
let crate_name = "foobar";
|
let crate_name = "foobar";
|
||||||
|
|
||||||
let dylib_name = String::from_utf8(
|
let dylib_name = rustc()
|
||||||
rustc()
|
.crate_name(proc_crate_name)
|
||||||
.crate_name(proc_crate_name)
|
.crate_type("dylib")
|
||||||
.crate_type("dylib")
|
.arg("--print")
|
||||||
.arg("--print")
|
.arg("file-names")
|
||||||
.arg("file-names")
|
.arg("-")
|
||||||
.arg("-")
|
.run()
|
||||||
.command_output()
|
.stdout_utf8();
|
||||||
.stdout,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
rustc()
|
rustc()
|
||||||
.input("src/proc.rs")
|
.input("src/proc.rs")
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use run_make_support::{rustc, rustdoc, Diff};
|
use run_make_support::{rustc, rustdoc, Diff};
|
||||||
|
|
||||||
fn compare_outputs(args: &[&str]) {
|
fn compare_outputs(args: &[&str]) {
|
||||||
let rustc_output = String::from_utf8(rustc().args(args).command_output().stdout).unwrap();
|
let rustc_output = rustc().args(args).run().stdout_utf8();
|
||||||
let rustdoc_output = String::from_utf8(rustdoc().args(args).command_output().stdout).unwrap();
|
let rustdoc_output = rustdoc().args(args).run().stdout_utf8();
|
||||||
|
|
||||||
Diff::new().expected_text("rustc", rustc_output).actual_text("rustdoc", rustdoc_output).run();
|
Diff::new().expected_text("rustc", rustc_output).actual_text("rustdoc", rustdoc_output).run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ fn main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
// echo $NOT_UTF8 | rustc -
|
// echo $NOT_UTF8 | rustc -
|
||||||
let output = rustc().arg("-").stdin(NOT_UTF8).run_fail();
|
rustc().arg("-").stdin(NOT_UTF8).run_fail().assert_stderr_contains(
|
||||||
let stderr = String::from_utf8(output.stderr).unwrap();
|
"error: couldn't read from stdin, as it did not contain valid UTF-8",
|
||||||
assert!(stderr.contains("error: couldn't read from stdin, as it did not contain valid UTF-8"));
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue