Skip to content
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
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