Procházet zdrojové kódy

Updated unit tests for pstree

Lorenz Bung před 8 roky
rodič
revize
f937064802
2 změnil soubory, kde provedl 36 přidání a 2 odebrání
  1. 1
    1
      hw4/task1/src/pstree.rs
  2. 35
    1
      hw4/task1/src/unit_test_pstree.rs

+ 1
- 1
hw4/task1/src/pstree.rs Zobrazit soubor

21
         }
21
         }
22
     }
22
     }
23
 
23
 
24
-    fn me() -> Self {
24
+    pub fn me() -> Self {
25
         if let Ok(my_pid) = pid::stat_self() {
25
         if let Ok(my_pid) = pid::stat_self() {
26
             Process::new(my_pid.pid)
26
             Process::new(my_pid.pid)
27
         } else {
27
         } else {

+ 35
- 1
hw4/task1/src/unit_test_pstree.rs Zobrazit soubor

1
 #[cfg(test)]
1
 #[cfg(test)]
2
 mod tests {
2
 mod tests {
3
     use pstree::Process;
3
     use pstree::Process;
4
+    use pstree::print;
4
 
5
 
5
     #[test]
6
     #[test]
6
     #[should_panic]
7
     #[should_panic]
20
 
21
 
21
     #[test]
22
     #[test]
22
     fn hasparent_yes() {
23
     fn hasparent_yes() {
23
-
24
+        assert_eq!(true, Process::has_parent(&Process::me()));
24
     }
25
     }
25
 
26
 
26
     #[test]
27
     #[test]
28
     fn parent_not_existing() {
29
     fn parent_not_existing() {
29
         Process::parent(&Process::new(1));
30
         Process::parent(&Process::new(1));
30
     }
31
     }
32
+
33
+    #[test]
34
+    fn parent_existing() {
35
+        Process::parent(&Process::me());
36
+    }
37
+
38
+    #[test]
39
+    fn hasparent_with_pid_not_existing() {
40
+        assert_eq!(false, Process::has_parent_with_pid(&Process::me(), -1000));
41
+    }
42
+
43
+    #[test]
44
+    fn hasparent_with_pid_existing() {
45
+        assert_eq!(true, Process::me().has_parent_with_pid(1));
46
+    }
47
+
48
+    #[test]
49
+    fn print_not_existing() {
50
+        assert_eq!(false, print(-1000));
51
+    }
52
+
53
+    #[test]
54
+    fn print_existing() {
55
+        assert_eq!(true, print(1));
56
+    }
57
+
58
+    #[test]
59
+    fn print_recursive_existing_pid() {
60
+        let prc = Process::new(1);
61
+        let mut str = String::new();
62
+        prc.print_recursive(1, &mut str);
63
+        assert_eq!("systemd(1)", str);
64
+    }
31
 }
65
 }

Loading…
Zrušit
Uložit