aboutsummaryrefslogtreecommitdiff
path: root/tests/rule_specific_macros.rs
blob: 8cc9c121bf16132d13f77e124f61a3e86f6d49ca (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
mod utils;

use std::fs;
use utils::{make, R};

#[test]
#[cfg(feature = "full")]
fn target_specific_macros() -> R {
    let dir = tempfile::tempdir()?;

    let file = "
foo.h: EGG = bug
foo.h:
\techo $(EGG)
    ";
    fs::write(dir.path().join("Makefile"), file)?;

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

    Ok(())
}

#[test]
#[ignore = "not yet implemented"]
#[cfg(feature = "full")]
fn target_specific_macros_inherited() -> R {
    let dir = tempfile::tempdir()?;

    // example from https://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html
    let file = "
CC=echo cc
prog : CFLAGS = -g
prog : prog.o foo.o bar.o
    ";
    fs::write(dir.path().join("Makefile"), file)?;
    fs::write(dir.path().join("prog.c"), "")?;
    fs::write(dir.path().join("foo.c"), "")?;
    fs::write(dir.path().join("bar.c"), "")?;

    let result = make(&dir)?;
    dbg!(&result);
    assert!(result.status.success());
    let stdout = String::from_utf8(result.stdout)?;
    assert!(stdout.contains("echo cc -g -c foo.c"));
    assert!(stdout.contains("echo cc -g -c bar.o"));
    assert!(stdout.contains("echo cc -g -c prog.c"));

    Ok(())
}

#[test]
#[ignore = "not yet implemented"]
#[cfg(feature = "full")]
fn inference_rule_specific_macros() -> R {
    let dir = tempfile::tempdir()?;

    // example from https://www.gnu.org/software/make/manual/html_node/Pattern_002dspecific.html
    let file = "
CC=echo cc
%.o: %.c
\t$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

lib/%.o: CFLAGS := -fPIC -g
%.o: CFLAGS := -g

all: foo.o lib/bar.o
    ";
    fs::write(dir.path().join("Makefile"), file)?;
    fs::write(dir.path().join("foo.c"), "")?;
    fs::create_dir(dir.path().join("lib"))?;
    fs::write(dir.path().join("bar.c"), "")?;

    let result = make(&dir)?;
    dbg!(&result);
    assert!(result.status.success());
    let stdout = String::from_utf8(result.stdout)?;
    dbg!(&stdout);
    assert!(stdout.contains("echo cc -g foo.c -o foo.o"));
    assert!(stdout.contains("echo cc -fPIC -g lib/bar.c -o lib/bar.o"));

    Ok(())
}