Skip to content

Commit

Permalink
Auto merge of #3552 - keeperofdakeys:proc-macro-doc-test, r=alexcrichton
Browse files Browse the repository at this point in the history
Allow doc tests to run on proc macro crates

Fixes #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.
  • Loading branch information
bors committed Jan 18, 2017
2 parents 82ea175 + b3b8b7e commit 493abf5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
54 changes: 54 additions & 0 deletions tests/proc-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"));
}

0 comments on commit 493abf5

Please sign in to comment.