diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 6e91a4d..553d513 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -15,11 +15,15 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: Add tools + run: sudo apt-get update -y && sudo apt-get install -y graphviz - name: Format run: cargo fmt --check - name: Build run: cargo build + - name: Test + run: cargo test - name: Clippy run: cargo clippy --all-targets --all-features - name: Build with 1.74 diff --git a/Cargo.lock b/Cargo.lock index 1f1d2db..c96af82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,7 +118,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -212,6 +212,26 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" +[[package]] +name = "folder_compare" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7cc8b9547e207c7e5233e593c59919ffdb978f17d1155ea9484cc46cb3e2397" +dependencies = [ + "fxhash", + "regex", + "walkdir", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -333,9 +353,9 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "libc" -version = "0.2.162" +version = "0.2.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" [[package]] name = "linux-raw-sys" @@ -355,6 +375,7 @@ version = "0.4.0" dependencies = [ "clap", "env_logger", + "folder_compare", "graphviz-rust", "log", "pulldown-cmark", @@ -406,7 +427,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -431,9 +452,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "307e3004becf10f5a6e0d59d20f3cd28231b0e0827a96cd3e0ce6d14bc1e4bb3" dependencies = [ "unicode-ident", ] @@ -520,9 +541,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rustix" -version = "0.38.40" +version = "0.38.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" dependencies = [ "bitflags", "errno", @@ -531,6 +552,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "serde" version = "1.0.215" @@ -548,7 +578,7 @@ checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -590,9 +620,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.87" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -638,7 +668,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] [[package]] @@ -695,9 +725,9 @@ checksum = "7e51b68083f157f853b6379db119d1c1be0e6e4dec98101079dec41f6f5cf6df" [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-width" @@ -717,6 +747,16 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -841,5 +881,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.89", ] diff --git a/Cargo.toml b/Cargo.toml index 23c4f05..6b6d6fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,9 @@ serde = {version = "1", features = ["derive"]} thiserror = "1" toml = "0.7" +[dev-dependencies] +folder_compare = "0.4.0" + # The profile that 'cargo dist' will build with [profile.dist] inherits = "release" diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..ed8f613 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +data_out diff --git a/tests/data_in/.gitignore b/tests/data_in/.gitignore new file mode 100644 index 0000000..7585238 --- /dev/null +++ b/tests/data_in/.gitignore @@ -0,0 +1 @@ +book diff --git a/tests/data_in/book.toml b/tests/data_in/book.toml new file mode 100644 index 0000000..d5c3944 --- /dev/null +++ b/tests/data_in/book.toml @@ -0,0 +1,6 @@ +[book] +authors = ["Jonathan Pallant"] +language = "en" +multilingual = false +src = "src" +title = "Sample Book" diff --git a/tests/data_in/index_template.html b/tests/data_in/index_template.html new file mode 100644 index 0000000..5319ffb --- /dev/null +++ b/tests/data_in/index_template.html @@ -0,0 +1,12 @@ + + + +$TITLE + + +

$TITLE

+
+$INDEX +
+ + diff --git a/tests/data_in/src/SUMMARY.md b/tests/data_in/src/SUMMARY.md new file mode 100644 index 0000000..fa67cf3 --- /dev/null +++ b/tests/data_in/src/SUMMARY.md @@ -0,0 +1,4 @@ +# Summary + +- [Chapter 1](./chapter_1.md) +- [Chapter 2](./chapter_2.md) diff --git a/tests/data_in/src/chapter_1.md b/tests/data_in/src/chapter_1.md new file mode 100644 index 0000000..7264736 --- /dev/null +++ b/tests/data_in/src/chapter_1.md @@ -0,0 +1,9 @@ +# Page 1 + +## Page 2 + +--- + +Page 3 + +## Page 4 diff --git a/tests/data_in/src/chapter_2.md b/tests/data_in/src/chapter_2.md new file mode 100644 index 0000000..b632ee7 --- /dev/null +++ b/tests/data_in/src/chapter_2.md @@ -0,0 +1,10 @@ +# Page 1 + +```dot process +digraph { + node [shape=record]; + "X"; +} +``` + +## Page 2 diff --git a/tests/data_in/template.html b/tests/data_in/template.html new file mode 100644 index 0000000..fac1de3 --- /dev/null +++ b/tests/data_in/template.html @@ -0,0 +1,13 @@ + + + +$TITLE + + +
+ +
+ + diff --git a/tests/data_out/.keep b/tests/data_out/.keep new file mode 100644 index 0000000..e69de29 diff --git a/tests/reference.rs b/tests/reference.rs new file mode 100644 index 0000000..aa11214 --- /dev/null +++ b/tests/reference.rs @@ -0,0 +1,44 @@ +//! Builds a reference book into a set of slides, and checks they match what we expect. + +use std::path::Path; + +#[test] +fn build_slides() { + let slide_template_string = include_str!("./data_in/template.html"); + let index_template_string = include_str!("./data_in/index_template.html"); + println!("We are in: {}", std::env::current_dir().unwrap().display()); + mdslides::run( + Some(Path::new("tests/data_in")), + Path::new("tests/data_out"), + slide_template_string, + Some(index_template_string), + ) + .expect("mdslides failed"); + + let comparison = folder_compare::FolderCompare::new( + Path::new("tests/reference_out"), + Path::new("tests/data_out"), + &vec![], + ) + .expect("failed to compare"); + if !comparison.changed_files.is_empty() { + for filename in comparison.changed_files { + let contents = std::fs::read_to_string(&filename).unwrap(); + eprintln!( + "Changed File {filename}:\n{contents}", + filename = filename.display() + ); + } + panic!("Some files differ"); + } + if !comparison.new_files.is_empty() { + for filename in comparison.new_files { + let contents = std::fs::read_to_string(&filename).unwrap(); + eprintln!( + "New File {filename}:\n{contents}", + filename = filename.display() + ); + } + panic!("Some new files found"); + } +} diff --git a/tests/reference_out/chapter_1.html b/tests/reference_out/chapter_1.html new file mode 100644 index 0000000..53521a5 --- /dev/null +++ b/tests/reference_out/chapter_1.html @@ -0,0 +1,24 @@ + + + +Chapter 1 + + +
+ +
+ + diff --git a/tests/reference_out/chapter_2.html b/tests/reference_out/chapter_2.html new file mode 100644 index 0000000..919f524 --- /dev/null +++ b/tests/reference_out/chapter_2.html @@ -0,0 +1,38 @@ + + + +Chapter 2 + + +
+ +
+ + diff --git a/tests/reference_out/index.html b/tests/reference_out/index.html new file mode 100644 index 0000000..dde97a2 --- /dev/null +++ b/tests/reference_out/index.html @@ -0,0 +1,17 @@ + + + +Sample Book + + +

Sample Book

+
+

Summary

+ + +
+ +