diff options
author | Jan-Erik Rediger <janerik@fnordig.de> | 2021-04-06 14:00:09 +0200 |
---|---|---|
committer | Jan-Erik Rediger <janerik@fnordig.de> | 2021-04-06 14:00:09 +0200 |
commit | 0b98d594276550bcd2ee35cfa977c2e37266709a (patch) | |
tree | 39b1b7af0dcc53f844d40c009227980d6cda2a43 | |
parent | 6bb54e54aaaea399c530c941b4afb43866c8576c (diff) |
Add tests for the `install` subcommand
These test that it modifies the book.toml and compares it against the
expected output.
-rw-r--r-- | Cargo.lock | 214 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | tests/it/empty.toml | 2 | ||||
-rw-r--r-- | tests/it/empty.toml.output | 8 | ||||
-rw-r--r-- | tests/it/full.toml | 9 | ||||
-rw-r--r-- | tests/it/full.toml.output | 9 | ||||
-rw-r--r-- | tests/it/install.rs | 52 | ||||
-rw-r--r-- | tests/it/main.rs | 1 | ||||
-rw-r--r-- | tests/it/missing-js.toml | 5 | ||||
-rw-r--r-- | tests/it/missing-js.toml.output | 8 | ||||
-rw-r--r-- | tests/it/some.toml | 5 | ||||
-rw-r--r-- | tests/it/some.toml.output | 8 |
12 files changed, 299 insertions, 26 deletions
@@ -34,6 +34,15 @@ dependencies = [ ] [[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi 0.3.8", +] + +[[package]] name = "anyhow" version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -46,6 +55,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" [[package]] +name = "assert_cmd" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2475b58cd94eb4f70159f4fd8844ba3b807532fe3131b3373fae060bbe30396" +dependencies = [ + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -105,6 +128,17 @@ dependencies = [ ] [[package]] +name = "bstr" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", +] + +[[package]] name = "byte-tools" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -151,7 +185,7 @@ version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ - "ansi_term", + "ansi_term 0.11.0", "atty", "bitflags", "strsim", @@ -190,6 +224,12 @@ dependencies = [ ] [[package]] +name = "diff" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" + +[[package]] name = "difference" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -214,6 +254,12 @@ dependencies = [ ] [[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] name = "dtoa" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -267,7 +313,7 @@ checksum = "f59efc38004c988e4201d11d263b8171f49a2e7ec0bdbb71773433f271504a5e" dependencies = [ "cfg-if 0.1.10", "libc", - "redox_syscall", + "redox_syscall 0.1.56", "winapi 0.3.8", ] @@ -438,7 +484,18 @@ checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" dependencies = [ "cfg-if 0.1.10", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", ] [[package]] @@ -809,6 +866,7 @@ dependencies = [ name = "mdbook-mermaid" version = "0.8.1-alpha.0" dependencies = [ + "assert_cmd", "clap", "env_logger", "log", @@ -817,6 +875,7 @@ dependencies = [ "pulldown-cmark", "pulldown-cmark-to-cmark", "serde_json", + "tempfile", "toml_edit", ] @@ -1050,7 +1109,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" dependencies = [ "phf_shared", - "rand", + "rand 0.7.3", ] [[package]] @@ -1096,9 +1155,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "ppv-lite86" -version = "0.2.6" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "precomputed-hash" @@ -1107,14 +1166,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] +name = "predicates" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeb433456c1a57cc93554dea3ce40b4c19c4057e41c55d4a0f3d84ea71c325aa" +dependencies = [ + "difference", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" + +[[package]] +name = "predicates-tree" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" +dependencies = [ + "predicates-core", + "treeline", +] + +[[package]] name = "pretty_assertions" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427" +checksum = "f297542c27a7df8d45de2b0e620308ab883ad232d06c14b76ac3e144bda50184" dependencies = [ - "ansi_term", + "ansi_term 0.12.1", "ctor", - "difference", + "diff", "output_vt100", ] @@ -1199,22 +1284,44 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.14", "libc", - "rand_chacha", - "rand_core", - "rand_hc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", "rand_pcg", ] [[package]] +name = "rand" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +dependencies = [ + "libc", + "rand_chacha 0.3.0", + "rand_core 0.6.2", + "rand_hc 0.3.0", +] + +[[package]] name = "rand_chacha" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.2", ] [[package]] @@ -1223,7 +1330,16 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.14", +] + +[[package]] +name = "rand_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom 0.2.2", ] [[package]] @@ -1232,7 +1348,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core 0.6.2", ] [[package]] @@ -1241,7 +1366,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" dependencies = [ - "rand_core", + "rand_core 0.5.1", ] [[package]] @@ -1251,6 +1376,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" [[package]] +name = "redox_syscall" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +dependencies = [ + "bitflags", +] + +[[package]] name = "regex" version = "1.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1263,6 +1397,15 @@ dependencies = [ ] [[package]] +name = "regex-automata" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" +dependencies = [ + "byteorder", +] + +[[package]] name = "regex-syntax" version = "0.6.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1471,14 +1614,14 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", - "rand", - "redox_syscall", + "rand 0.8.3", + "redox_syscall 0.2.5", "remove_dir_all", "winapi 0.3.8", ] @@ -1528,7 +1671,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" dependencies = [ "libc", - "redox_syscall", + "redox_syscall 0.1.56", "winapi 0.3.8", ] @@ -1645,6 +1788,12 @@ dependencies = [ ] [[package]] +name = "treeline" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" + +[[package]] name = "try-lock" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1663,7 +1812,7 @@ dependencies = [ "httparse", "input_buffer", "log", - "rand", + "rand 0.7.3", "sha-1 0.9.1", "url", "utf-8", @@ -1783,6 +1932,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] name = "walkdir" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1837,6 +1995,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] name = "winapi" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -19,4 +19,6 @@ serde_json = "1.0.57" toml_edit = "0.2.0" [dev-dependencies] -pretty_assertions = "0.6.1" +assert_cmd = "1.0.3" +pretty_assertions = "0.7.1" +tempfile = "3.2.0" diff --git a/tests/it/empty.toml b/tests/it/empty.toml new file mode 100644 index 0000000..620da2d --- /dev/null +++ b/tests/it/empty.toml @@ -0,0 +1,2 @@ +[book] +title = "All mermaid config options missing" diff --git a/tests/it/empty.toml.output b/tests/it/empty.toml.output new file mode 100644 index 0000000..c9403c7 --- /dev/null +++ b/tests/it/empty.toml.output @@ -0,0 +1,8 @@ +[book] +title = "All mermaid config options missing" +[preprocessor] +[preprocessor.mermaid] +command = "mdbook-mermaid" +[output] +[output.html] +additional-js =["mermaid.min.js", "mermaid-init.js"] diff --git a/tests/it/full.toml b/tests/it/full.toml new file mode 100644 index 0000000..f0b7ad1 --- /dev/null +++ b/tests/it/full.toml @@ -0,0 +1,9 @@ +[book] +title = "mdbook-mermaid fully configured" + +[preprocessor.mermaid] +command = "mdbook-mermaid" +renderer = ["html"] + +[output.html] +additional-js =["mermaid.min.js", "mermaid-init.js"] diff --git a/tests/it/full.toml.output b/tests/it/full.toml.output new file mode 100644 index 0000000..f0b7ad1 --- /dev/null +++ b/tests/it/full.toml.output @@ -0,0 +1,9 @@ +[book] +title = "mdbook-mermaid fully configured" + +[preprocessor.mermaid] +command = "mdbook-mermaid" +renderer = ["html"] + +[output.html] +additional-js =["mermaid.min.js", "mermaid-init.js"] diff --git a/tests/it/install.rs b/tests/it/install.rs new file mode 100644 index 0000000..c53a1cb --- /dev/null +++ b/tests/it/install.rs @@ -0,0 +1,52 @@ +use std::fs; +use std::process::Command; + +use assert_cmd::prelude::*; + +macro_rules! test_install { + ($inputfile:expr, $msg:expr) => { + let input = include_str!($inputfile); + let expected = include_str!(concat!($inputfile, ".output")); + + let tmp = tempfile::tempdir().expect("can't create tempdir"); + + let book_toml = tmp.path().join("book.toml"); + fs::write(&book_toml, input).expect("can't write book.toml"); + + let mut cmd = Command::cargo_bin("mdbook-mermaid").unwrap(); + cmd.arg("install").current_dir(tmp.path()); + cmd.assert().success(); + + let output = fs::read_to_string(&book_toml).expect("can't read book.toml"); + pretty_assertions::assert_eq!( + expected, + output, + "Mismatched data in {}: {}", + $inputfile, + $msg + ); + + assert!(tmp.path().join("mermaid.min.js").exists(), "Failed to copy mermaid.min.js"); + assert!(tmp.path().join("mermaid-init.js").exists(), "Failed to copy mermaid.min.js"); + }; +} + +#[test] +fn empty() { + test_install!("empty.toml", "should add all configuration options"); +} + +#[test] +fn full() { + test_install!("full.toml", "should leave it untouched"); +} + +#[test] +fn some() { + test_install!("some.toml", "should add missing configuration options"); +} + +#[test] +fn missing_js() { + test_install!("missing-js.toml", "should add missing javascript file"); +} diff --git a/tests/it/main.rs b/tests/it/main.rs new file mode 100644 index 0000000..502ae4c --- /dev/null +++ b/tests/it/main.rs @@ -0,0 +1 @@ +mod install; diff --git a/tests/it/missing-js.toml b/tests/it/missing-js.toml new file mode 100644 index 0000000..51a463c --- /dev/null +++ b/tests/it/missing-js.toml @@ -0,0 +1,5 @@ +[book] +title = "Some configuration options are set" + +[preprocessor.mermaid] +command = "mdbook-mermaid" diff --git a/tests/it/missing-js.toml.output b/tests/it/missing-js.toml.output new file mode 100644 index 0000000..88a4c0a --- /dev/null +++ b/tests/it/missing-js.toml.output @@ -0,0 +1,8 @@ +[book] +title = "Some configuration options are set" + +[preprocessor.mermaid] +command = "mdbook-mermaid" +[output] +[output.html] +additional-js =["mermaid.min.js", "mermaid-init.js"] diff --git a/tests/it/some.toml b/tests/it/some.toml new file mode 100644 index 0000000..51a463c --- /dev/null +++ b/tests/it/some.toml @@ -0,0 +1,5 @@ +[book] +title = "Some configuration options are set" + +[preprocessor.mermaid] +command = "mdbook-mermaid" diff --git a/tests/it/some.toml.output b/tests/it/some.toml.output new file mode 100644 index 0000000..88a4c0a --- /dev/null +++ b/tests/it/some.toml.output @@ -0,0 +1,8 @@ +[book] +title = "Some configuration options are set" + +[preprocessor.mermaid] +command = "mdbook-mermaid" +[output] +[output.html] +additional-js =["mermaid.min.js", "mermaid-init.js"] |