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 /tests | |
parent | 6bb54e54aaaea399c530c941b4afb43866c8576c (diff) |
Add tests for the `install` subcommand
These test that it modifies the book.toml and compares it against the
expected output.
Diffstat (limited to 'tests')
-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 |
10 files changed, 107 insertions, 0 deletions
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"] |