pub fn benched(&self) -> bool {
self.benched
}
-
pub fn doctested(&self) -> bool {
- self.doctest && match self.kind {
+ self.doctest
+ }
+
+ pub fn doctestable(&self) -> bool {
+ match self.kind {
TargetKind::Lib(ref kinds) => kinds
.iter()
.any(|k| *k == LibKind::Rlib || *k == LibKind::Lib || *k == LibKind::ProcMacro),
proposals.extend(default_units);
if build_config.mode == CompileMode::Test {
// Include doctest for lib.
- if let Some(t) = pkg.targets().iter().find(|t| t.is_lib() && t.doctested()) {
+ if let Some(t) = pkg
+ .targets()
+ .iter()
+ .find(|t| t.is_lib() && t.doctested() && t.doctestable())
+ {
proposals.push((new_unit(pkg, t, CompileMode::Doctest), false));
}
}
} => {
if lib {
if let Some(target) = pkg.targets().iter().find(|t| t.is_lib()) {
+ if build_config.mode == CompileMode::Doctest && !target.doctestable() {
+ bail!(
+ "doc tests are not supported for crate type(s) `{}` in package `{}`",
+ target.rustc_crate_types().join(", "),
+ pkg.name()
+ );
+ }
proposals.push((new_unit(pkg, target, build_config.mode), false));
} else if !all_targets {
- bail!("no library targets found")
+ bail!("no library targets found in package `{}`", pkg.name())
}
}
// If --tests was specified, add all targets that would be
p.cargo("build").arg("--lib"),
execs()
.with_status(101)
- .with_stderr("[ERROR] no library targets found"),
+ .with_stderr("[ERROR] no library targets found in package `foo`"),
);
}
execs().with_status(0),
);
}
+
+#[test]
+fn doctest_skip_staticlib() {
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+
+ [lib]
+ crate-type = ["staticlib"]
+ "#,
+ )
+ .file(
+ "src/lib.rs",
+ r#"
+ //! ```
+ //! assert_eq!(1,2);
+ //! ```
+ "#,
+ )
+ .build();
+
+ assert_that(
+ p.cargo("test --doc"),
+ execs().with_status(101).with_stderr(
+ "[ERROR] doc tests are not supported for crate type(s) `staticlib` in package `foo`",
+ ),
+ );
+
+ assert_that(
+ p.cargo("test"),
+ execs().with_status(0).with_stderr(
+ "\
+[COMPILING] foo [..]
+[FINISHED] dev [..]
+[RUNNING] target[/]debug[/]deps[/]foo-[..]",
+ ),
+ )
+}