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
#![allow(non_camel_case_types)]
extern crate errno;
extern crate libc;
#[cfg(target_os = "windows")]
extern crate winapi;
mod integrations;
mod types;
pub use integrations::*;
pub use types::*;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn iterate_processes_info_works() {
for process_info in iterate_processes_info() {
println!("{:?}", process_info);
}
}
#[test]
fn get_processes_info_works() {
match get_processes_info() {
Result::Ok(processes_info) => {
for process_info in processes_info {
println!("{:?}", process_info);
}
}
Result::Err(err) => println!("{:?}", err),
}
}
#[test]
fn api_is_consistent() {
assert!(Result_(iterate_processes_info().collect()) == Result_(get_processes_info()));
struct Result_(Result<Vec<ProcessInfo>, Error>);
impl PartialEq<Result_> for Result_ {
fn eq(&self, other: &Result_) -> bool {
match (&self.0, &other.0) {
(Ok(ref xs), Ok(ref ys)) => {
xs.len() == ys.len()
&& xs.iter().zip(ys.iter()).all(|(x, y)| x.pid == y.pid)
}
_ => false,
}
}
}
}
}