mirror of
https://github.com/rust-lang/cargo
synced 2024-08-24 18:15:45 +00:00
Auto merge of #3552 - keeperofdakeys:proc-macro-doc-test, r=alexcrichton
Allow doc tests to run on proc macro crates Fixes https://github.com/rust-lang/cargo/issues/3545 Since `--test` works for rustc, doctests should also work. Currently cargo isn't setup to run doctests for proc macro crates, this PR adds them to the list. Currently rustdoc can run doctests for proc-macro crates, but the `phase_2_configure_and_expand` call` triggers the following warning: ``` the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type ``` So perhaps this PR should wait until I've finished creating/testing the PR for rustc.
This commit is contained in:
commit
493abf58f6
|
@ -385,7 +385,11 @@ impl Target {
|
|||
pub fn doctested(&self) -> bool {
|
||||
self.doctest && match self.kind {
|
||||
TargetKind::Lib(ref kinds) => {
|
||||
kinds.contains(&LibKind::Rlib) || kinds.contains(&LibKind::Lib)
|
||||
kinds.iter().find(|k| {
|
||||
*k == &LibKind::Rlib ||
|
||||
*k == &LibKind::Lib ||
|
||||
*k == &LibKind::ProcMacro
|
||||
}).is_some()
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
|
|
|
@ -178,3 +178,57 @@ fn plugin_and_proc_macro() {
|
|||
assert_that(questionable.cargo_process("build"),
|
||||
execs().with_status(101).with_stderr_contains(msg));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn proc_macro_doctest() {
|
||||
if !is_nightly() {
|
||||
return
|
||||
}
|
||||
let foo = project("foo")
|
||||
.file("Cargo.toml", r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
authors = []
|
||||
[lib]
|
||||
proc-macro = true
|
||||
"#)
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(proc_macro, proc_macro_lib)]
|
||||
#![crate_type = "proc-macro"]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
/// ```
|
||||
/// assert!(true);
|
||||
/// ```
|
||||
#[proc_macro_derive(Bar)]
|
||||
pub fn derive(_input: TokenStream) -> TokenStream {
|
||||
"".parse().unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a() {
|
||||
assert!(true);
|
||||
}
|
||||
"#);
|
||||
foo.build();
|
||||
|
||||
assert_that(foo.cargo_process("test"),
|
||||
execs().with_status(0)
|
||||
.with_stdout_contains("\
|
||||
running 1 test
|
||||
test a ... ok
|
||||
|
||||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
||||
|
||||
").with_stdout_contains("\
|
||||
running 1 test
|
||||
test derive_0 ... ok
|
||||
|
||||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
||||
|
||||
"));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue