-
Notifications
You must be signed in to change notification settings - Fork 4
/
lib.rs
72 lines (62 loc) · 1.77 KB
/
lib.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
//! The bigbro crate.
//!
//! This allows you to track file accesses by child processes.
extern crate nix;
use std::path;
use std::collections::HashSet;
pub struct ExitStatus {
exit_code: Option<i32>,
}
impl ExitStatus {
pub fn code(&self) -> Option<i32> {
self.exit_code
}
}
pub struct Accesses {
pub status: ExitStatus,
pub read_files: HashSet<path::PathBuf>,
pub wrote_files: HashSet<path::PathBuf>,
}
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
pub use linux::shell;
#[cfg(any(not(target_os = "linux"), test))]
mod generic;
#[cfg(not(target_os = "linux"))]
pub use generic::shell;
#[test]
fn test_true() {
let a = shell("true").unwrap();
assert!(a.status.code() == Some(0));
}
#[test]
fn test_mktempdir() {
if std::fs::create_dir_all("tmp").is_err() {
println!("Unable to create directory 'tmp' perhaps due to race condition.");
}
let a = shell("mkdir -p tmp/dir").unwrap();
assert!(a.status.code() == Some(0));
}
#[test]
fn test_echo_to_file() {
if std::fs::create_dir_all("tmp").is_err() {
println!("Unable to create directory 'tmp' perhaps due to race condition.");
}
let a = shell("echo foo > tmp/foo").unwrap();
assert!(a.status.code() == Some(0));
// if cfg!(target_os = "linux") {
// assert!(a.read_files.contains(&path::PathBuf::from("tmp/foo")));
// }
}
#[test]
fn test_generic_echo_to_file() {
if std::fs::create_dir_all("tmp").is_err() {
println!("Unable to create directory 'tmp' perhaps due to race condition.");
}
let a = generic::shell("echo foo > tmp/foo").unwrap();
assert!(a.status.code() == Some(0));
// if cfg!(target_os = "linux") {
// assert!(a.read_files.contains(&path::PathBuf::from("tmp/foo")));
// }
}