Переглянути джерело

Updated unit tests for pstree

Lorenz Bung 8 роки тому
джерело
коміт
f937064802
2 змінених файлів з 36 додано та 2 видалено
  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 Переглянути файл

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

+ 35
- 1
hw4/task1/src/unit_test_pstree.rs Переглянути файл

@@ -1,6 +1,7 @@
1 1
 #[cfg(test)]
2 2
 mod tests {
3 3
     use pstree::Process;
4
+    use pstree::print;
4 5
 
5 6
     #[test]
6 7
     #[should_panic]
@@ -20,7 +21,7 @@ mod tests {
20 21
 
21 22
     #[test]
22 23
     fn hasparent_yes() {
23
-
24
+        assert_eq!(true, Process::has_parent(&Process::me()));
24 25
     }
25 26
 
26 27
     #[test]
@@ -28,4 +29,37 @@ mod tests {
28 29
     fn parent_not_existing() {
29 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
 }

Завантаження…
Відмінити
Зберегти