-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
136 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::path::Path; | ||
use std::process::{Command, Output}; | ||
|
||
use crate::{handle_failed_output, setup_common_build_cmd}; | ||
|
||
pub fn rustdoc() -> RustdocInvocationBuilder { | ||
RustdocInvocationBuilder::new() | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct RustdocInvocationBuilder { | ||
cmd: Command, | ||
} | ||
|
||
impl RustdocInvocationBuilder { | ||
fn new() -> Self { | ||
let cmd = setup_common_build_cmd(); | ||
Self { cmd } | ||
} | ||
|
||
pub fn arg(&mut self, arg: &str) -> &mut RustdocInvocationBuilder { | ||
self.cmd.arg(arg); | ||
self | ||
} | ||
|
||
pub fn arg_file(&mut self, arg: &Path) -> &mut RustdocInvocationBuilder { | ||
self.cmd.arg(arg); | ||
self | ||
} | ||
|
||
pub fn env(&mut self, key: &str, value: &str) -> &mut RustdocInvocationBuilder { | ||
self.cmd.env(key, value); | ||
self | ||
} | ||
|
||
#[track_caller] | ||
pub fn run(&mut self) -> Output { | ||
let caller_location = std::panic::Location::caller(); | ||
let caller_line_number = caller_location.line(); | ||
|
||
let output = self.cmd.output().unwrap(); | ||
if !output.status.success() { | ||
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number); | ||
} | ||
output | ||
} | ||
|
||
#[track_caller] | ||
pub fn run_fail(&mut self) -> Output { | ||
let caller_location = std::panic::Location::caller(); | ||
let caller_line_number = caller_location.line(); | ||
|
||
let output = self.cmd.output().unwrap(); | ||
if output.status.success() { | ||
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number); | ||
} | ||
output | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
extern crate run_make_support; | ||
|
||
use run_make_support::{rustc, rustdoc, tempdir}; | ||
|
||
fn main() { | ||
rustc() | ||
.arg("success.rs") | ||
.run(); | ||
|
||
assert_eq!(rustc() | ||
.arg("--invalid-arg-foo") | ||
.run_fail() | ||
.status | ||
.code().unwrap(), 1); | ||
|
||
assert_eq!(rustc() | ||
.arg("compile-error.rs") | ||
.run_fail() | ||
.status | ||
.code().unwrap(), 1); | ||
|
||
assert_eq!(rustc() | ||
.env("RUSTC_ICE", "0") | ||
.arg("-Ztreat-err-as-bug") | ||
.arg("compile-error.rs") | ||
.run_fail() | ||
.status | ||
.code().unwrap(), 101); | ||
|
||
rustdoc() | ||
.arg("-o") | ||
.arg_file(&tempdir().join("exit-code")) | ||
.arg("success.rs") | ||
.run(); | ||
|
||
assert_eq!(rustdoc() | ||
.arg("--invalid-arg-foo") | ||
.run_fail() | ||
.status | ||
.code().unwrap(), 1); | ||
|
||
assert_eq!(rustdoc() | ||
.arg("compile-error.rs") | ||
.run_fail() | ||
.status | ||
.code().unwrap(), 1); | ||
|
||
assert_eq!(rustdoc() | ||
.arg("lint-failure.rs") | ||
.run_fail() | ||
.status | ||
.code().unwrap(), 1); | ||
} |