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

use eyre::{Result, WrapErr};
use std::thread::sleep;
use std::time::Duration;

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"));

    sleep(Duration::from_millis(1000));

    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(())
}