Skip to content

Commit 2ccc792

Browse files
authored
Test mdbook like a crate (#669)
Changes the tests for the mdbook from the mdbook tool to cargo test, which is simpler for local development. Mirrors the pattern used by Timely. Signed-off-by: Moritz Hoffmann <antiguru@gmail.com>
1 parent fce4a22 commit 2ccc792

File tree

15 files changed

+72
-27
lines changed

15 files changed

+72
-27
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,3 @@ jobs:
2727
run: cargo test --workspace --all-targets
2828
- name: Cargo doc test
2929
run: cargo test --doc
30-
31-
# Check formatting with rustfmt
32-
mdbook:
33-
name: test mdBook
34-
runs-on: ubuntu-latest
35-
steps:
36-
- uses: actions/checkout@v6
37-
- uses: actions-rust-lang/setup-rust-toolchain@v1
38-
# rustdoc doesn't build dependencies, so it needs to run after `cargo build`,
39-
# but its dependency search gets confused if there are multiple copies of any
40-
# dependency in target/debug/deps, so it needs to run before `cargo test` et al.
41-
# clutter target/debug/deps with multiple copies of things.
42-
- run: cargo clean
43-
- run: cargo build
44-
- name: test mdBook
45-
run: for file in $(find mdbook -name '*.md' | sort); do rustdoc --test $file -L ./target/debug/deps; done

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ members = [
1111
"server/dataflows/random_graph",
1212
"server/dataflows/reachability",
1313
#"tpchlike",
14-
"doop"
14+
"doop",
15+
"mdbook",
1516
]
1617
resolver = "2"
1718

19+
[workspace.package]
20+
edition = "2021"
21+
1822
[workspace.dependencies]
1923
differential-dataflow = { path = "differential-dataflow", default-features = false, version = "0.19.1" }
2024
timely = { version = "0.26", default-features = false }

differential-dataflow/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repository = "https://github.com/TimelyDataflow/differential-dataflow.git"
1313
keywords = ["differential", "dataflow"]
1414
license = "MIT"
1515
readme = "../README.md"
16-
edition="2021"
16+
edition.workspace = true
1717

1818
[dev-dependencies]
1919
rand="0.4"

dogsdogsdogs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "differential-dogs3"
33
version = "0.19.1"
44
authors = ["Frank McSherry <fmcsherry@me.com>"]
55
license = "MIT"
6-
edition = "2021"
6+
edition.workspace = true
77
description = "Advanced join patterns in differential dataflow"
88

99
documentation = "https://docs.rs/differential-dogs3"

doop/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "doop"
33
version = "0.1.0"
44
authors = ["Frank McSherry <fmcsherry@me.com>"]
5-
edition = "2021"
5+
edition.workspace = true
66
publish = false
77

88
[dependencies]

experiments/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "experiments"
33
version = "0.1.0"
44
authors = ["Frank McSherry <fmcsherry@me.com>"]
5-
edition = "2021"
5+
edition.workspace = true
66
publish = false
77

88
[dependencies]

interactive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "interactive"
33
version = "0.1.0"
44
authors = ["Frank McSherry <fmcsherry@me.com>"]
5-
edition = "2021"
5+
edition.workspace = true
66
publish = false
77

88
[dependencies]

mdbook/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "mdbook"
3+
version = "0.0.0"
4+
edition.workspace = true
5+
publish = false
6+
7+
[dependencies]
8+
differential-dataflow = { path = "../differential-dataflow" }
9+
timely.workspace = true

mdbook/build.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//! Infrastructure to test the mdbook documentation.
2+
//!
3+
//! Generates a module for each Markdown file in the `src/` directory, and includes
4+
//! the contents of each file as a doc comment for that module.
5+
6+
use std::env;
7+
use std::fs;
8+
use std::io;
9+
use std::path::{Path, PathBuf};
10+
11+
/// Recursively finds all Markdown files in the given path and collects their paths into `mds`.
12+
fn find_mds(dir: impl AsRef<Path>, mds: &mut Vec<PathBuf>) -> io::Result<()> {
13+
for entry in fs::read_dir(dir)? {
14+
let path = entry?.path();
15+
if path.is_dir() {
16+
find_mds(path, mds)?;
17+
} else if path.extension().and_then(|s| s.to_str()) == Some("md") {
18+
mds.push(path);
19+
}
20+
}
21+
Ok(())
22+
}
23+
24+
fn main() -> io::Result<()> {
25+
let mut mds = Vec::new();
26+
find_mds("src", &mut mds)?;
27+
28+
let mut lib = String::new();
29+
30+
for md in mds {
31+
let md_path = md.to_str().unwrap();
32+
println!("cargo::rerun-if-changed={md_path}");
33+
let mod_name = md_path.replace(['/', '\\', '-', '.'], "_");
34+
use std::fmt::Write;
35+
writeln!(
36+
&mut lib,
37+
"#[allow(non_snake_case)] #[doc = include_str!(concat!(env!(\"CARGO_MANIFEST_DIR\"), r\"{}{md_path}\"))] mod {mod_name} {{}}",
38+
std::path::MAIN_SEPARATOR,
39+
).unwrap();
40+
}
41+
42+
let dest_path = Path::new(&env::var("OUT_DIR").unwrap()).join("mdbook.rs");
43+
fs::write(&dest_path, lib)?;
44+
println!("cargo::rerun-if-changed=build.rs");
45+
Ok(())
46+
}

mdbook/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//! Dummy library file to allow testing the mdbook documentation.
2+
include!(concat!(env!("OUT_DIR"), "/mdbook.rs"));

0 commit comments

Comments
 (0)