Skip to content

Commit d7c7d91

Browse files
committed
Write preprocessed content to file before testing with rustdoc
Fixes #855.
1 parent c068703 commit d7c7d91

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

src/book/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,12 @@ impl MDBook {
242242
if let BookItem::Chapter(ref ch) = *item {
243243
if !ch.path.as_os_str().is_empty() {
244244
let path = self.source_dir().join(&ch.path);
245-
let content = utils::fs::file_to_string(&path)?;
246245
info!("Testing file: {:?}", path);
247246

248247
// write preprocessed file to tempdir
249248
let path = temp_dir.path().join(&ch.path);
250249
let mut tmpf = utils::fs::create_file(&path)?;
251-
tmpf.write_all(content.as_bytes())?;
250+
tmpf.write_all(ch.content.as_bytes())?;
252251

253252
let output = Command::new("rustdoc")
254253
.arg(&path)

tests/dummy_book/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ impl DummyBook {
5858
})?;
5959

6060
let sub_pattern = if self.passing_test { "true" } else { "false" };
61-
let file_containing_test = temp.path().join("src/first/nested.md");
62-
replace_pattern_in_file(&file_containing_test, "$TEST_STATUS", sub_pattern)?;
61+
let files_containing_tests = ["src/first/nested.md", "src/first/nested-test.rs"];
62+
for file in &files_containing_tests {
63+
let path_containing_tests = temp.path().join(file);
64+
replace_pattern_in_file(&path_containing_tests, "$TEST_STATUS", sub_pattern)?;
65+
}
6366

6467
Ok(temp)
6568
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert!($TEST_STATUS);

tests/dummy_book/src/first/nested.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ assert!($TEST_STATUS);
77
```
88

99
## Some Section
10+
11+
```rust
12+
{{#include nested-test.rs}}
13+
```

tests/searchindex_fixture.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"title": 2
4747
},
4848
"5": {
49-
"body": 0,
49+
"body": 1,
5050
"breadcrumbs": 3,
5151
"title": 1
5252
},
@@ -109,7 +109,7 @@
109109
"title": "Nested Chapter"
110110
},
111111
"5": {
112-
"body": "",
112+
"body": "assert!(true);",
113113
"breadcrumbs": "First Chapter » Some Section",
114114
"id": "5",
115115
"title": "Some Section"
@@ -177,10 +177,13 @@
177177
"df": 0,
178178
"docs": {},
179179
"u": {
180-
"df": 1,
180+
"df": 2,
181181
"docs": {
182182
"4": {
183183
"tf": 1.0
184+
},
185+
"5": {
186+
"tf": 1.0
184187
}
185188
}
186189
}
@@ -1336,10 +1339,13 @@
13361339
"df": 0,
13371340
"docs": {},
13381341
"u": {
1339-
"df": 1,
1342+
"df": 2,
13401343
"docs": {
13411344
"4": {
13421345
"tf": 1.0
1346+
},
1347+
"5": {
1348+
"tf": 1.0
13431349
}
13441350
}
13451351
}

0 commit comments

Comments
 (0)