浏览代码

Adding examples, how to check shell prompt etc.

Michael Mächtel 8 年前
父节点
当前提交
9f2ea528e0
共有 1 个文件被更改,包括 55 次插入0 次删除
  1. 55
    0
      hw6/task2/src/unit_tests_shell.rs

+ 55
- 0
hw6/task2/src/unit_tests_shell.rs 查看文件

@@ -0,0 +1,55 @@
1
+#[cfg(test)]
2
+mod test {
3
+    use shell::Shell;
4
+
5
+    #[test]
6
+    fn test_prompt_in_memory_with_string() {
7
+        let input = b"echo";
8
+        let mut output = Vec::new();
9
+
10
+        let mut shell = Shell {
11
+            reader: &input[..],
12
+            writer: &mut output,
13
+            should_exit: false,
14
+            name: "bsys-shell".to_string(),
15
+        };
16
+
17
+        let output = shell.prompt().unwrap().unwrap();
18
+
19
+        assert_eq!("echo", output);
20
+    }
21
+
22
+    #[test]
23
+    fn test_loop_of_shell_which_wants_to_exit() {
24
+        let input = b"BlaBla";
25
+        let mut output = Vec::new();
26
+
27
+        let mut shell = Shell {
28
+            reader: &input[..],
29
+            writer: &mut output,
30
+            should_exit: true,
31
+            name: "bsys-shell".to_string(),
32
+        };
33
+
34
+        let output = shell.start().unwrap();
35
+
36
+        assert_eq!((), output);
37
+    }
38
+
39
+    #[test]
40
+    fn test_loop_with_exit_command() {
41
+        let input = b"exit";
42
+        let mut output = Vec::new();
43
+
44
+        let mut shell = Shell {
45
+            reader: &input[..],
46
+            writer: &mut output,
47
+            should_exit: false,
48
+            name: "bsys-shell".to_string(),
49
+        };
50
+
51
+        let output = shell.start().unwrap();
52
+
53
+        assert_eq!((), output);
54
+    }
55
+}

正在加载...
取消
保存