mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-01 01:23:26 +00:00
Auto merge of #124753 - GuillaumeGomez:migrate-rustdoc-determinism, r=jieyouxu
Migrate `run-make/rustdoc-error-lines` to new `rmake.rs` Part of https://github.com/rust-lang/rust/issues/121876. There was a weird naming inconsistency with `input`/`output`. A few tests write `.arg("-o").arg(path)` and the `output` method was actually the command output. So instead, I renamed the original `output` into `command_output` so that I could create the `output` method with the expected effect (and updated the tests to use it too). EDIT: The first two commits come from https://github.com/rust-lang/rust/pull/124711. Some weird things happened recently pparently. ^^' r? `@jieyouxu`
This commit is contained in:
commit
25e3949aa1
@ -73,7 +73,7 @@ impl Cc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the [`Output`][::std::process::Output] of the finished process.
|
/// Get the [`Output`][::std::process::Output] of the finished process.
|
||||||
pub fn output(&mut self) -> ::std::process::Output {
|
pub fn command_output(&mut self) -> ::std::process::Output {
|
||||||
self.cmd.output().expect("failed to get output of finished process")
|
self.cmd.output().expect("failed to get output of finished process")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ impl Clang {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the [`Output`][::std::process::Output] of the finished process.
|
/// Get the [`Output`][::std::process::Output] of the finished process.
|
||||||
pub fn output(&mut self) -> ::std::process::Output {
|
pub fn command_output(&mut self) -> ::std::process::Output {
|
||||||
self.cmd.output().expect("failed to get output of finished process")
|
self.cmd.output().expect("failed to get output of finished process")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ pub fn set_host_rpath(cmd: &mut Command) {
|
|||||||
///
|
///
|
||||||
/// impl CommandWrapper {
|
/// impl CommandWrapper {
|
||||||
/// /// Get the [`Output`][::std::process::Output] of the finished process.
|
/// /// Get the [`Output`][::std::process::Output] of the finished process.
|
||||||
/// pub fn output(&mut self) -> Output { /* ... */ } // <- required `output()` method
|
/// pub fn command_output(&mut self) -> Output { /* ... */ } // <- required `command_output()` method
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// crate::impl_common_helpers!(CommandWrapper);
|
/// crate::impl_common_helpers!(CommandWrapper);
|
||||||
@ -242,7 +242,7 @@ macro_rules! impl_common_helpers {
|
|||||||
let caller_location = ::std::panic::Location::caller();
|
let caller_location = ::std::panic::Location::caller();
|
||||||
let caller_line_number = caller_location.line();
|
let caller_line_number = caller_location.line();
|
||||||
|
|
||||||
let output = self.output();
|
let output = self.command_output();
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
handle_failed_output(&self.cmd, output, caller_line_number);
|
handle_failed_output(&self.cmd, output, caller_line_number);
|
||||||
}
|
}
|
||||||
@ -255,7 +255,7 @@ macro_rules! impl_common_helpers {
|
|||||||
let caller_location = ::std::panic::Location::caller();
|
let caller_location = ::std::panic::Location::caller();
|
||||||
let caller_line_number = caller_location.line();
|
let caller_line_number = caller_location.line();
|
||||||
|
|
||||||
let output = self.output();
|
let output = self.command_output();
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
handle_failed_output(&self.cmd, output, caller_line_number);
|
handle_failed_output(&self.cmd, output, caller_line_number);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ impl LlvmReadobj {
|
|||||||
|
|
||||||
/// Get the [`Output`][::std::process::Output] of the finished process.
|
/// Get the [`Output`][::std::process::Output] of the finished process.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn output(&mut self) -> ::std::process::Output {
|
pub fn command_output(&mut self) -> ::std::process::Output {
|
||||||
self.cmd.output().expect("failed to get output of finished process")
|
self.cmd.output().expect("failed to get output of finished process")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,13 @@ impl Rustc {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specify path to the output file.
|
||||||
|
pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
||||||
|
self.cmd.arg("-o");
|
||||||
|
self.cmd.arg(path.as_ref());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// This flag defers LTO optimizations to the linker.
|
/// This flag defers LTO optimizations to the linker.
|
||||||
pub fn linker_plugin_lto(&mut self, option: &str) -> &mut Self {
|
pub fn linker_plugin_lto(&mut self, option: &str) -> &mut Self {
|
||||||
self.cmd.arg(format!("-Clinker-plugin-lto={option}"));
|
self.cmd.arg(format!("-Clinker-plugin-lto={option}"));
|
||||||
@ -171,7 +178,7 @@ impl Rustc {
|
|||||||
|
|
||||||
/// Get the [`Output`][::std::process::Output] of the finished process.
|
/// Get the [`Output`][::std::process::Output] of the finished process.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn output(&mut self) -> ::std::process::Output {
|
pub fn command_output(&mut self) -> ::std::process::Output {
|
||||||
// let's make sure we piped all the input and outputs
|
// let's make sure we piped all the input and outputs
|
||||||
self.cmd.stdin(Stdio::piped());
|
self.cmd.stdin(Stdio::piped());
|
||||||
self.cmd.stdout(Stdio::piped());
|
self.cmd.stdout(Stdio::piped());
|
||||||
@ -196,7 +203,7 @@ impl Rustc {
|
|||||||
let caller_location = std::panic::Location::caller();
|
let caller_location = std::panic::Location::caller();
|
||||||
let caller_line_number = caller_location.line();
|
let caller_line_number = caller_location.line();
|
||||||
|
|
||||||
let output = self.output();
|
let output = self.command_output();
|
||||||
if output.status.code().unwrap() != code {
|
if output.status.code().unwrap() != code {
|
||||||
handle_failed_output(&self.cmd, output, caller_line_number);
|
handle_failed_output(&self.cmd, output, caller_line_number);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,13 @@ impl Rustdoc {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specify path to the output folder.
|
||||||
|
pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
||||||
|
self.cmd.arg("-o");
|
||||||
|
self.cmd.arg(path.as_ref());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Specify output directory.
|
/// Specify output directory.
|
||||||
pub fn out_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
pub fn out_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
||||||
self.cmd.arg("--out-dir").arg(path.as_ref());
|
self.cmd.arg("--out-dir").arg(path.as_ref());
|
||||||
@ -73,7 +80,7 @@ impl Rustdoc {
|
|||||||
|
|
||||||
/// Get the [`Output`][::std::process::Output] of the finished process.
|
/// Get the [`Output`][::std::process::Output] of the finished process.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn output(&mut self) -> ::std::process::Output {
|
pub fn command_output(&mut self) -> ::std::process::Output {
|
||||||
// let's make sure we piped all the input and outputs
|
// let's make sure we piped all the input and outputs
|
||||||
self.cmd.stdin(Stdio::piped());
|
self.cmd.stdin(Stdio::piped());
|
||||||
self.cmd.stdout(Stdio::piped());
|
self.cmd.stdout(Stdio::piped());
|
||||||
@ -93,12 +100,19 @@ impl Rustdoc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specify the edition year.
|
||||||
|
pub fn edition(&mut self, edition: &str) -> &mut Self {
|
||||||
|
self.cmd.arg("--edition");
|
||||||
|
self.cmd.arg(edition);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
|
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
|
||||||
let caller_location = std::panic::Location::caller();
|
let caller_location = std::panic::Location::caller();
|
||||||
let caller_line_number = caller_location.line();
|
let caller_line_number = caller_location.line();
|
||||||
|
|
||||||
let output = self.output();
|
let output = self.command_output();
|
||||||
if output.status.code().unwrap() != code {
|
if output.status.code().unwrap() != code {
|
||||||
handle_failed_output(&self.cmd, output, caller_line_number);
|
handle_failed_output(&self.cmd, output, caller_line_number);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,6 @@ run-make/dep-graph/Makefile
|
|||||||
run-make/dep-info-doesnt-run-much/Makefile
|
run-make/dep-info-doesnt-run-much/Makefile
|
||||||
run-make/dep-info-spaces/Makefile
|
run-make/dep-info-spaces/Makefile
|
||||||
run-make/dep-info/Makefile
|
run-make/dep-info/Makefile
|
||||||
run-make/doctests-runtool/Makefile
|
|
||||||
run-make/dump-ice-to-disk/Makefile
|
run-make/dump-ice-to-disk/Makefile
|
||||||
run-make/dump-mono-stats/Makefile
|
run-make/dump-mono-stats/Makefile
|
||||||
run-make/duplicate-output-flavors/Makefile
|
run-make/duplicate-output-flavors/Makefile
|
||||||
@ -245,7 +244,6 @@ run-make/rlib-format-packed-bundled-libs-3/Makefile
|
|||||||
run-make/rlib-format-packed-bundled-libs/Makefile
|
run-make/rlib-format-packed-bundled-libs/Makefile
|
||||||
run-make/rmeta-preferred/Makefile
|
run-make/rmeta-preferred/Makefile
|
||||||
run-make/rustc-macro-dep-files/Makefile
|
run-make/rustc-macro-dep-files/Makefile
|
||||||
run-make/rustdoc-error-lines/Makefile
|
|
||||||
run-make/rustdoc-io-error/Makefile
|
run-make/rustdoc-io-error/Makefile
|
||||||
run-make/rustdoc-map-file/Makefile
|
run-make/rustdoc-map-file/Makefile
|
||||||
run-make/rustdoc-output-path/Makefile
|
run-make/rustdoc-output-path/Makefile
|
||||||
|
@ -13,7 +13,8 @@ fn main() {
|
|||||||
let mut stable_path = PathBuf::from(env!("TMPDIR"));
|
let mut stable_path = PathBuf::from(env!("TMPDIR"));
|
||||||
stable_path.push("libstable.rmeta");
|
stable_path.push("libstable.rmeta");
|
||||||
|
|
||||||
let output = rustc().input("main.rs").emit("metadata").extern_("stable", &stable_path).output();
|
let output =
|
||||||
|
rustc().input("main.rs").emit("metadata").extern_("stable", &stable_path).command_output();
|
||||||
|
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
let version = include_str!(concat!(env!("S"), "/src/version"));
|
let version = include_str!(concat!(env!("S"), "/src/version"));
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
# ignore-cross-compile
|
|
||||||
include ../tools.mk
|
|
||||||
|
|
||||||
# Tests behavior of rustdoc --runtool
|
|
||||||
|
|
||||||
MY_SRC_DIR := ${CURDIR}
|
|
||||||
|
|
||||||
all: with_test_run_directory
|
|
||||||
|
|
||||||
# Behavior with --runtool with relative paths and --test-run-directory.
|
|
||||||
with_test_run_directory:
|
|
||||||
mkdir -p $(TMPDIR)/rundir
|
|
||||||
mkdir -p $(TMPDIR)/runtool
|
|
||||||
$(RUSTC) --crate-type rlib t.rs
|
|
||||||
$(RUSTC) runtool.rs -o $(TMPDIR)/runtool/runtool
|
|
||||||
( cd $(TMPDIR); \
|
|
||||||
$(RUSTDOC) -Zunstable-options --test --test-run-directory rundir \
|
|
||||||
--runtool runtool/runtool --extern t=libt.rlib $(MY_SRC_DIR)/t.rs \
|
|
||||||
)
|
|
||||||
rm -rf $(TMPDIR)/rundir $(TMPDIR)/runtool
|
|
39
tests/run-make/doctests-runtool/rmake.rs
Normal file
39
tests/run-make/doctests-runtool/rmake.rs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Tests behavior of rustdoc `--runtool`.
|
||||||
|
|
||||||
|
use run_make_support::{rustc, rustdoc, tmp_dir};
|
||||||
|
use std::env::current_dir;
|
||||||
|
use std::fs::{create_dir, remove_dir_all};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
fn mkdir(name: &str) -> PathBuf {
|
||||||
|
let dir = tmp_dir().join(name);
|
||||||
|
create_dir(&dir).expect("failed to create doctests folder");
|
||||||
|
dir
|
||||||
|
}
|
||||||
|
|
||||||
|
// Behavior with --runtool with relative paths and --test-run-directory.
|
||||||
|
fn main() {
|
||||||
|
let run_dir_name = "rundir";
|
||||||
|
let run_dir = mkdir(run_dir_name);
|
||||||
|
let run_tool = mkdir("runtool");
|
||||||
|
let run_tool_binary = run_tool.join("runtool");
|
||||||
|
|
||||||
|
rustc().input("t.rs").crate_type("rlib").run();
|
||||||
|
rustc().input("runtool.rs").output(&run_tool_binary).run();
|
||||||
|
|
||||||
|
rustdoc()
|
||||||
|
.input(current_dir().unwrap().join("t.rs"))
|
||||||
|
.arg("-Zunstable-options")
|
||||||
|
.arg("--test")
|
||||||
|
.arg("--test-run-directory")
|
||||||
|
.arg(run_dir_name)
|
||||||
|
.arg("--runtool")
|
||||||
|
.arg(&run_tool_binary)
|
||||||
|
.arg("--extern")
|
||||||
|
.arg("t=libt.rlib")
|
||||||
|
.current_dir(tmp_dir())
|
||||||
|
.run();
|
||||||
|
|
||||||
|
remove_dir_all(run_dir);
|
||||||
|
remove_dir_all(run_tool);
|
||||||
|
}
|
@ -15,7 +15,7 @@ fn main() {
|
|||||||
.arg("compile-error.rs")
|
.arg("compile-error.rs")
|
||||||
.run_fail_assert_exit_code(101);
|
.run_fail_assert_exit_code(101);
|
||||||
|
|
||||||
rustdoc().arg("success.rs").arg("-o").arg(tmp_dir().join("exit-code")).run();
|
rustdoc().arg("success.rs").output(tmp_dir().join("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);
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let output = tmp_dir().join("repr128");
|
let output = tmp_dir().join("repr128");
|
||||||
rustc().input("main.rs").arg("-o").arg(&output).arg("-Cdebuginfo=2").run();
|
rustc().input("main.rs").output(&output).arg("-Cdebuginfo=2").run();
|
||||||
// Mach-O uses packed debug info
|
// Mach-O uses packed debug info
|
||||||
let dsym_location = output
|
let dsym_location = output
|
||||||
.with_extension("dSYM")
|
.with_extension("dSYM")
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
use run_make_support::{diff, rustc, rustdoc, tmp_dir};
|
// Assert that the search index is generated deterministically, regardless of the
|
||||||
|
// order that crates are documented in.
|
||||||
|
|
||||||
|
use run_make_support::{diff, rustdoc, tmp_dir};
|
||||||
|
|
||||||
/// Assert that the search index is generated deterministically, regardless of the
|
|
||||||
/// order that crates are documented in.
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let dir_first = tmp_dir().join("first");
|
let foo_first = tmp_dir().join("foo_first");
|
||||||
rustdoc().out_dir(&dir_first).input("foo.rs").run();
|
rustdoc().input("foo.rs").output(&foo_first).run();
|
||||||
rustdoc().out_dir(&dir_first).input("bar.rs").run();
|
rustdoc().input("bar.rs").output(&foo_first).run();
|
||||||
|
|
||||||
let dir_second = tmp_dir().join("second");
|
let bar_first = tmp_dir().join("bar_first");
|
||||||
rustdoc().out_dir(&dir_second).input("bar.rs").run();
|
rustdoc().input("bar.rs").output(&bar_first).run();
|
||||||
rustdoc().out_dir(&dir_second).input("foo.rs").run();
|
rustdoc().input("foo.rs").output(&bar_first).run();
|
||||||
|
|
||||||
diff()
|
diff()
|
||||||
.expected_file(dir_first.join("search-index.js"))
|
.expected_file(foo_first.join("search-index.js"))
|
||||||
.actual_file(dir_second.join("search-index.js"))
|
.actual_file(bar_first.join("search-index.js"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
include ../tools.mk
|
|
||||||
|
|
||||||
# Test that hir-tree output doesn't crash and includes
|
|
||||||
# the string constant we would expect to see.
|
|
||||||
|
|
||||||
all:
|
|
||||||
$(RUSTDOC) --test input.rs > $(TMPDIR)/output || true
|
|
||||||
$(CGREP) 'input.rs - foo (line 5)' < $(TMPDIR)/output
|
|
||||||
$(CGREP) 'input.rs:7:15' < $(TMPDIR)/output
|
|
||||||
$(CGREP) 'input.rs - bar (line 15)' < $(TMPDIR)/output
|
|
||||||
$(CGREP) 'input.rs:17:15' < $(TMPDIR)/output
|
|
||||||
$(CGREP) 'input.rs - bar (line 24)' < $(TMPDIR)/output
|
|
||||||
$(CGREP) 'input.rs:26:15' < $(TMPDIR)/output
|
|
22
tests/run-make/rustdoc-error-lines/rmake.rs
Normal file
22
tests/run-make/rustdoc-error-lines/rmake.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Assert that the search index is generated deterministically, regardless of the
|
||||||
|
// order that crates are documented in.
|
||||||
|
|
||||||
|
use run_make_support::rustdoc;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let output =
|
||||||
|
String::from_utf8(rustdoc().input("input.rs").arg("--test").command_output().stdout)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let should_contain = &[
|
||||||
|
"input.rs - foo (line 5)",
|
||||||
|
"input.rs:7:15",
|
||||||
|
"input.rs - bar (line 15)",
|
||||||
|
"input.rs:17:15",
|
||||||
|
"input.rs - bar (line 24)",
|
||||||
|
"input.rs:26:15",
|
||||||
|
];
|
||||||
|
for text in should_contain {
|
||||||
|
assert!(output.contains(text), "output doesn't contains {:?}", text);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user