Skip to content

Commit

Permalink
Auto merge of #6628 - dwijnand:doc-no-run, r=Eh2406
Browse files Browse the repository at this point in the history
Bail when trying to run "test --doc --no-run"

Fixes #5242
  • Loading branch information
bors committed Feb 4, 2019
2 parents 0dbb2fc + fabda17 commit f7ba714
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/bin/cargo/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {

let mut compile_opts = args.compile_options(config, CompileMode::Test, Some(&ws))?;

let no_run = args.is_present("no-run");
let doc = args.is_present("doc");
if doc {
if let CompileFilter::Only { .. } = compile_opts.filter {
Expand All @@ -102,6 +103,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
101,
));
}
if no_run {
return Err(CliError::new(
failure::format_err!("Can't skip running doc tests with --no-run"),
101,
));
}
compile_opts.build_config.mode = CompileMode::Doctest;
compile_opts.filter = ops::CompileFilter::new(
true,
Expand All @@ -118,7 +125,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
}

let ops = ops::TestOptions {
no_run: args.is_present("no-run"),
no_run,
no_fail_fast: args.is_present("no-fail-fast"),
compile_opts,
};
Expand Down
20 changes: 20 additions & 0 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3449,6 +3449,26 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
.run();
}

#[test]
fn can_not_no_run_doc_tests() {
let p = project()
.file(
"src/lib.rs",
r#"
/// ```
/// let _x = 1 + "foo";
/// ```
pub fn foo() -> u8 { 1 }
"#,
)
.build();

p.cargo("test --doc --no-run")
.with_status(101)
.with_stderr("[ERROR] Can't skip running doc tests with --no-run")
.run();
}

#[test]
fn test_all_targets_lib() {
let p = project().file("src/lib.rs", "").build();
Expand Down

0 comments on commit f7ba714

Please sign in to comment.