flag_package: Vec<String>,
flag_target: Option<String>,
flag_lib: bool,
+ flag_doc: bool,
flag_bin: Vec<String>,
flag_example: Vec<String>,
flag_test: Vec<String>,
Options:
-h, --help Print this message
--lib Test only this package's library
+ --doc Test only this library's documentation
--bin NAME Test only the specified binary
--example NAME Test only the specified example
--test NAME Test only the specified integration test target
&options.flag_color));
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
+ let empty = Vec::new();
+ let (mode, filter);
+ if options.flag_doc {
+ mode = ops::CompileMode::Build;
+ filter = ops::CompileFilter::new(true, &empty, &empty, &empty, &empty);
+ } else {
+ mode = ops::CompileMode::Test;
+ filter = ops::CompileFilter::new(options.flag_lib,
+ &options.flag_bin,
+ &options.flag_test,
+ &options.flag_example,
+ &options.flag_bench);
+ }
+
let ops = ops::TestOptions {
no_run: options.flag_no_run,
no_fail_fast: options.flag_no_fail_fast,
+ only_doc: options.flag_doc,
compile_opts: ops::CompileOptions {
config: config,
jobs: options.flag_jobs,
spec: &options.flag_package,
exec_engine: None,
release: options.flag_release,
- mode: ops::CompileMode::Test,
- filter: ops::CompileFilter::new(options.flag_lib,
- &options.flag_bin,
- &options.flag_test,
- &options.flag_example,
- &options.flag_bench),
+ mode: mode,
+ filter: filter,
target_rustdoc_args: None,
target_rustc_args: None,
},
pub compile_opts: ops::CompileOptions<'a>,
pub no_run: bool,
pub no_fail_fast: bool,
+ pub only_doc: bool,
}
-
-
pub fn run_tests(manifest_path: &Path,
options: &TestOptions,
test_args: &[String]) -> CargoResult<Option<CargoTestError>> {
if options.no_run {
return Ok(None)
}
- let mut errors = try!(run_unit_tests(options, test_args, &compilation));
+ let mut errors = if options.only_doc {
+ Vec::new()
+ } else {
+ try!(run_unit_tests(options, test_args, &compilation))
+ };
// If we have an error and want to fail fast, return
if !errors.is_empty() && !options.no_fail_fast {
{running} `rustc a[..]src[..]lib.rs [..]`
", compiling = COMPILING, running = RUNNING)));
});
+
+test!(only_test_docs {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/lib.rs", r#"
+ #[test]
+ fn foo() {
+ let a: u32 = "hello";
+ }
+
+ /// ```
+ /// println!("ok");
+ /// ```
+ pub fn bar() {
+ }
+ "#)
+ .file("tests/foo.rs", "this is not rust");
+ p.build();
+
+ assert_that(p.cargo("test").arg("--doc"),
+ execs().with_status(0));
+});