This repository was archived by the owner on Nov 18, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathexit_status.rs
110 lines (102 loc) · 2.75 KB
/
exit_status.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
use ty::Type;
use crate::{status::LinkExit, value::Value};
#[derive(Debug)]
pub enum ExitStatus {
/// All codes are reduced.
Returned,
/// The process is halted with the reason.
Halted {
ty: Type,
reason: Value,
},
/// The process is crashed with the error.
/// any crash equals to any crash in PartialEq.
Crashed(anyhow::Error),
HaltedByLink(LinkExit),
}
impl PartialEq for ExitStatus {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(ExitStatus::Returned, ExitStatus::Returned) => true,
(
ExitStatus::Halted {
ty: ty1,
reason: reason1,
},
ExitStatus::Halted {
ty: ty2,
reason: reason2,
},
) => ty1 == ty2 && reason1 == reason2,
(ExitStatus::Crashed(_), ExitStatus::Crashed(_)) => true,
_ => false,
}
}
}
#[cfg(test)]
mod tests {
use ty::Type;
use super::*;
#[test]
fn exit_status_equals() {
assert_eq!(ExitStatus::Returned, ExitStatus::Returned);
assert_eq!(
ExitStatus::Halted {
ty: Type::Real,
reason: Value::String("a".into())
},
ExitStatus::Halted {
ty: Type::Real,
reason: Value::String("a".into())
},
);
assert_eq!(
ExitStatus::Crashed(anyhow::anyhow!("a")),
ExitStatus::Crashed(anyhow::anyhow!("b")),
);
}
#[test]
fn exit_status_not_equals() {
assert_ne!(
ExitStatus::Returned,
ExitStatus::Halted {
ty: Type::Real,
reason: Value::String("a".into())
}
);
assert_ne!(
ExitStatus::Returned,
ExitStatus::Crashed(anyhow::anyhow!(""))
);
assert_ne!(
ExitStatus::Halted {
ty: Type::Real,
reason: Value::String("a".into())
},
ExitStatus::Crashed(anyhow::anyhow!(""))
);
}
#[test]
fn halted_not_equals() {
assert_ne!(
ExitStatus::Halted {
ty: Type::Real,
reason: Value::String("a".into())
},
ExitStatus::Halted {
ty: Type::String,
reason: Value::String("a".into())
}
);
assert_ne!(
ExitStatus::Halted {
ty: Type::Real,
reason: Value::String("a".into())
},
ExitStatus::Halted {
ty: Type::Real,
reason: Value::String("b".into())
}
);
}
}