Skip to content

Commit fabda17

Browse files
committed
Bail when trying to run "test --doc --no-run"
1 parent 4e74e2f commit fabda17

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/bin/cargo/commands/test.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
9494

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

97+
let no_run = args.is_present("no-run");
9798
let doc = args.is_present("doc");
9899
if doc {
99100
if let CompileFilter::Only { .. } = compile_opts.filter {
@@ -102,6 +103,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
102103
101,
103104
));
104105
}
106+
if no_run {
107+
return Err(CliError::new(
108+
failure::format_err!("Can't skip running doc tests with --no-run"),
109+
101,
110+
));
111+
}
105112
compile_opts.build_config.mode = CompileMode::Doctest;
106113
compile_opts.filter = ops::CompileFilter::new(
107114
true,
@@ -118,7 +125,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
118125
}
119126

120127
let ops = ops::TestOptions {
121-
no_run: args.is_present("no-run"),
128+
no_run,
122129
no_fail_fast: args.is_present("no-fail-fast"),
123130
compile_opts,
124131
};

tests/testsuite/test.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3449,6 +3449,26 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
34493449
.run();
34503450
}
34513451

3452+
#[test]
3453+
fn can_not_no_run_doc_tests() {
3454+
let p = project()
3455+
.file(
3456+
"src/lib.rs",
3457+
r#"
3458+
/// ```
3459+
/// let _x = 1 + "foo";
3460+
/// ```
3461+
pub fn foo() -> u8 { 1 }
3462+
"#,
3463+
)
3464+
.build();
3465+
3466+
p.cargo("test --doc --no-run")
3467+
.with_status(101)
3468+
.with_stderr("[ERROR] Can't skip running doc tests with --no-run")
3469+
.run();
3470+
}
3471+
34523472
#[test]
34533473
fn test_all_targets_lib() {
34543474
let p = project().file("src/lib.rs", "").build();

0 commit comments

Comments
 (0)