-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwatching_with_non_block_flag.rs
200 lines (162 loc) · 6.26 KB
/
watching_with_non_block_flag.rs
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
use std::collections::HashMap;
use std::io::prelude::*;
use crate::setup::CLEAR_SCREEN;
#[path = "./common/lib.rs"]
mod setup;
#[test]
fn test_it_cancel_current_running_task_when_something_change() {
setup::with_example(
setup::Options {
output_file: "test_it_cancel_current_running_task_when_something_change.log",
example_file: "examples/tasks-with-long-running-commands.yaml",
},
|fzz_cmd, mut output_log| {
let mut child = fzz_cmd
.arg("--non-block")
.spawn()
.expect("failed to spawn child");
defer!({
child.kill().expect("failed to kill child");
});
let mut output = String::new();
wait_until!(
{
output_log
.read_to_string(&mut output)
.expect("failed to read from file");
output.contains("Running on init commands")
&& output.contains("Started task long 2")
},
"No task in the example was configured with run_on_init {}",
output
);
write_to_file!("examples/workdir/trigger-watcher.txt");
// This should not trigger another restart
write_to_file!("examples/workdir/another_ignored_file.foo");
wait_until!(
{
output_log
.read_to_string(&mut output)
.expect("failed to read from file");
// See it in `examples/longtask.sh`
// and also in `src/stdout.rs`
output.match_indices(CLEAR_SCREEN).count() == 1
},
"Failed to find a clear screen sign: {}",
output
);
write_to_file!("examples/workdir/trigger-watcher.txt");
wait_until!(
{
output_log
.read_to_string(&mut output)
.expect("failed to read from file");
// See it in `examples/longtask.sh`
// and also in `src/stdout.rs`
output.match_indices(CLEAR_SCREEN).count() == 2
},
"Failed to find 2 clear screen signs: {}",
output
);
let expected = "Funzzy: Running on init commands.
Funzzy: bash examples/longtask.sh long 2
Started task long 2
Long task running... 0
[2J
Funzzy: bash examples/longtask.sh long 1
Started task long 1
Long task running... 0
[2J
Funzzy: bash examples/longtask.sh long 1
Started task long 1
Long task running... 0
";
assert_eq!(
output, expected,
"Output:\n{} ------ \n\nExpected:\n{}",
output, expected,
);
},
);
}
#[test]
fn test_it_cancel_current_running_task_when_something_change_with_env() {
setup::with_env(
HashMap::from([("FUNZZY_NON_BLOCK".to_string(), "true".to_string())]),
|| {
setup::with_example(
setup::Options {
output_file:
"test_it_cancel_current_running_task_when_something_change_with_env.log",
example_file: "examples/tasks-with-long-running-commands.yaml",
},
|fzz_cmd, mut output_log| {
let mut child = fzz_cmd.spawn().expect("failed to spawn child");
defer!({
child.kill().expect("failed to kill child");
});
let mut output = String::new();
wait_until!(
{
output_log
.read_to_string(&mut output)
.expect("failed to read from file");
output.contains("Running on init commands")
&& output.contains("Started task long 2")
},
"No task in the example was configured with run_on_init {}",
output
);
write_to_file!("examples/workdir/trigger-watcher.txt");
// This should not trigger another restart
write_to_file!("examples/workdir/another_ignored_file.foo");
wait_until!(
{
output_log
.read_to_string(&mut output)
.expect("failed to read from file");
// See it in `examples/longtask.sh`
// and also in `src/stdout.rs`
output.match_indices(CLEAR_SCREEN).count() == 1
},
"Failed to find a clear screen sign: {}",
output
);
write_to_file!("examples/workdir/trigger-watcher.txt");
wait_until!(
{
output_log
.read_to_string(&mut output)
.expect("failed to read from file");
// See it in `examples/longtask.sh`
// and also in `src/stdout.rs`
output.match_indices(CLEAR_SCREEN).count() == 2
},
"Failed to find 2 clear screen signs: {}",
output
);
let expected = "Funzzy: Running on init commands.
Funzzy: bash examples/longtask.sh long 2
Started task long 2
Long task running... 0
[2J
Funzzy: bash examples/longtask.sh long 1
Started task long 1
Long task running... 0
[2J
Funzzy: bash examples/longtask.sh long 1
Started task long 1
Long task running... 0
";
assert_eq!(
output, expected,
"Output:\n{} ------ \n\nExpected:\n{}",
output, expected,
);
},
);
Ok(())
},
)
.expect("failed to set env");
}