summaryrefslogtreecommitdiffstats
path: root/tests/it/install.rs
blob: b2552a78668b9fd6aa81556cad588b3ea8896c62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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");
}