aboutsummaryrefslogtreecommitdiff
path: root/tests/update_logic.rs
blob: 2b746065e381629f76fa6fcc236acdbeb5bae2b0 (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
use std::fs;
use std::path::Path;
use std::process::{Command, Output};

use eyre::{Result, WrapErr};

type R = Result<()>;

fn make(dir: impl AsRef<Path>) -> Result<Output> {
    Command::new(env!("CARGO_BIN_EXE_makers"))
        .current_dir(dir)
        .output()
        .wrap_err("")
}

#[test]
fn basic_test() -> R {
    let dir = tempfile::tempdir()?;
    let file = "
based-on-what: based-on-this
\techo hi
    ";
    fs::write(dir.path().join("Makefile"), file)?;
    let result = make(&dir)?;
    assert!(!result.status.success());
    assert!(String::from_utf8(result.stderr)?.contains("based-on-this"));

    fs::write(dir.path().join("based-on-this"), "")?;
    let result = make(&dir)?;
    assert!(result.status.success());
    assert!(String::from_utf8(result.stdout)?.contains("echo hi"));

    let result = make(&dir)?;
    assert!(result.status.success());
    assert!(String::from_utf8(result.stdout)?.contains("echo hi"));

    fs::write(dir.path().join("based-on-what"), "")?;
    let result = make(&dir)?;
    assert!(result.status.success());
    assert!(!String::from_utf8(result.stdout)?.contains("echo hi"));

    fs::write(dir.path().join("based-on-this"), "")?;
    let result = make(&dir)?;
    assert!(result.status.success());
    assert!(String::from_utf8(result.stdout)?.contains("echo hi"));

    Ok(())
}