-
Notifications
You must be signed in to change notification settings - Fork 499
/
interrupts.rs
90 lines (74 loc) · 1.48 KB
/
interrupts.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
use {
super::*,
std::time::{Duration, Instant},
};
fn kill(process_id: u32) {
unsafe {
libc::kill(process_id.try_into().unwrap(), libc::SIGINT);
}
}
fn interrupt_test(arguments: &[&str], justfile: &str) {
let tmp = tempdir();
let mut justfile_path = tmp.path().to_path_buf();
justfile_path.push("justfile");
fs::write(justfile_path, unindent(justfile)).unwrap();
let start = Instant::now();
let mut child = Command::new(executable_path("just"))
.current_dir(&tmp)
.args(arguments)
.spawn()
.expect("just invocation failed");
while start.elapsed() < Duration::from_millis(500) {}
kill(child.id());
let status = child.wait().unwrap();
let elapsed = start.elapsed();
assert!(
elapsed <= Duration::from_secs(2),
"process returned too late: {elapsed:?}"
);
assert!(
elapsed >= Duration::from_millis(100),
"process returned too early : {elapsed:?}"
);
assert_eq!(status.code(), Some(130));
}
#[test]
#[ignore]
fn interrupt_shebang() {
interrupt_test(
&[],
"
default:
#!/usr/bin/env sh
sleep 1
",
);
}
#[test]
#[ignore]
fn interrupt_line() {
interrupt_test(
&[],
"
default:
@sleep 1
",
);
}
#[test]
#[ignore]
fn interrupt_backtick() {
interrupt_test(
&[],
"
foo := `sleep 1`
default:
@echo {{foo}}
",
);
}
#[test]
#[ignore]
fn interrupt_command() {
interrupt_test(&["--command", "sleep", "1"], "");
}