-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathbindings.rs
More file actions
149 lines (133 loc) · 2.91 KB
/
Copy pathbindings.rs
File metadata and controls
149 lines (133 loc) · 2.91 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//! Tests for behavior around variable bindings.
use super::*;
// Repro for issue #83.
#[cfg(unix)]
#[test]
fn eval_twice() -> anyhow::Result<()> {
let space = TestSpace::new()?;
space.write(
"build.ninja",
&[
TOUCH_RULE,
"
var = 123
rule custom
command = $cmd $var
build out: custom
cmd = echo $var hello
",
]
.join("\n"),
)?;
let out = space.run_expect(&mut n2_command(vec!["out"]))?;
assert_output_contains(&out, "echo 123 hello 123");
Ok(())
}
#[test]
fn bad_rule_variable() -> anyhow::Result<()> {
let space = TestSpace::new()?;
space.write(
"build.ninja",
"
rule my_rule
command = touch $out
my_var = foo
build out: my_rule
",
)?;
let out = space.run(&mut n2_command(vec!["out"]))?;
assert_stderr_contains(&out, "unexpected variable \"my_var\"");
Ok(())
}
#[cfg(unix)]
#[test]
fn deps_evaluate_build_bindings() -> anyhow::Result<()> {
let space = TestSpace::new()?;
space.write(
"build.ninja",
"
rule touch
command = touch $out
rule copy
command = cp $in $out
build foo: copy ${my_dep}
my_dep = bar
build bar: touch
",
)?;
space.run_expect(&mut n2_command(vec!["foo"]))?;
space.read("foo")?;
Ok(())
}
#[cfg(unix)]
#[test]
fn looks_up_values_from_build() -> anyhow::Result<()> {
let space = TestSpace::new()?;
space.write(
"build.ninja",
"
rule copy_rspfile
command = cp $out.rsp $out
rspfile = $out.rsp
build foo: copy_rspfile
rspfile_content = Hello, world!
",
)?;
space.run_expect(&mut n2_command(vec!["foo"]))?;
assert_eq!(space.read("foo")?, b"Hello, world!");
Ok(())
}
#[cfg(unix)]
#[test]
fn build_bindings_arent_recursive() -> anyhow::Result<()> {
let space = TestSpace::new()?;
space.write(
"build.ninja",
"
rule write_file
command = echo $my_var > $out
build foo: write_file
my_var = Hello,$my_var_2 world!
my_var_2 = my_var_2_value
",
)?;
space.run_expect(&mut n2_command(vec!["foo"]))?;
assert_eq!(space.read("foo")?, b"Hello, world!\n");
Ok(())
}
#[cfg(unix)]
#[test]
fn empty_variable_binding() -> anyhow::Result<()> {
let space = TestSpace::new()?;
space.write(
"build.ninja",
"
empty_var =
rule write_file
command = echo $my_var > $out
build foo: write_file
my_var = Hello,$empty_var world!
",
)?;
space.run_expect(&mut n2_command(vec!["foo"]))?;
assert_eq!(space.read("foo")?, b"Hello, world!\n");
Ok(())
}
#[cfg(unix)]
#[test]
fn empty_build_variable() -> anyhow::Result<()> {
let space = TestSpace::new()?;
space.write(
"build.ninja",
"
rule write_file
command = echo $my_var > $out
build foo: write_file
empty =
my_var = Hello, world!
",
)?;
space.run_expect(&mut n2_command(vec!["foo"]))?;
assert_eq!(space.read("foo")?, b"Hello, world!\n");
Ok(())
}