Skip to content

Commit 25c8210

Browse files
committed
Put #[macro_use] extern crate <crate> before fn main() in doctests
1 parent a04b88d commit 25c8210

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/librustdoc/test.rs

+19
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ fn partition_source(s: &str) -> (String, String) {
416416
let trimline = line.trim();
417417
let header = trimline.is_whitespace() ||
418418
trimline.starts_with("#![") ||
419+
trimline.starts_with("#[macro_use] extern crate") ||
419420
trimline.starts_with("extern crate");
420421
if !header || after_header {
421422
after_header = true;
@@ -825,6 +826,24 @@ assert_eq!(2+2, 4);
825826
assert_eq!(output, (expected, 2));
826827
}
827828

829+
#[test]
830+
fn make_test_manual_extern_crate_with_macro_use() {
831+
let opts = TestOptions::default();
832+
let input =
833+
"#[macro_use] extern crate asdf;
834+
use asdf::qwop;
835+
assert_eq!(2+2, 4);";
836+
let expected =
837+
"#![allow(unused)]
838+
#[macro_use] extern crate asdf;
839+
fn main() {
840+
use asdf::qwop;
841+
assert_eq!(2+2, 4);
842+
}".to_string();
843+
let output = make_test(input, Some("asdf"), false, &opts);
844+
assert_eq!(output, (expected, 2));
845+
}
846+
828847
#[test]
829848
fn make_test_opts_attrs() {
830849
//if you supplied some doctest attributes with #![doc(test(attr(...)))], it will use those

0 commit comments

Comments
 (0)