[Libguestfs] [PATCH 3/5] mltools: add simple tests for external_command

Pino Toscano ptoscano at redhat.com
Wed Jan 16 14:17:33 UTC 2019


---
 common/mltools/tools_utils_tests.ml | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/common/mltools/tools_utils_tests.ml b/common/mltools/tools_utils_tests.ml
index 1489fe699..f3c39514d 100644
--- a/common/mltools/tools_utils_tests.ml
+++ b/common/mltools/tools_utils_tests.ml
@@ -28,6 +28,7 @@ let assert_equal_string = assert_equal ~printer:(fun x -> x)
 let assert_equal_int = assert_equal ~printer:(fun x -> string_of_int x)
 let assert_equal_int64 = assert_equal ~printer:(fun x -> Int64.to_string x)
 let assert_equal_intlist = assert_equal ~printer:(fun x -> "(" ^ (String.concat ";" (List.map string_of_int x)) ^ ")")
+let assert_equal_stringlist = assert_equal ~printer:(fun x -> "(" ^ (String.escaped (String.concat "," x)) ^ ")")
 
 (* Test Tools_utils.parse_size and Tools_utils.parse_resize. *)
 let test_parse_resize ctx =
@@ -156,6 +157,26 @@ let test_run_commands ctx =
   end;
   ()
 
+let test_external_command ctx =
+  assert_equal_stringlist [] (external_command "true");
+  assert_equal_stringlist ["out"] (external_command "echo out");
+  begin
+    let lines, code = external_command_code "true" in
+    assert_equal_int 0 code;
+    assert_equal_stringlist [] lines
+  end;
+  begin
+    let lines, code = external_command_code "false" in
+    assert_equal_int 1 code;
+    assert_equal_stringlist [] lines
+  end;
+  begin
+    let lines, code = external_command_code "echo out" in
+    assert_equal_int 0 code;
+    assert_equal_stringlist ["out"] lines
+  end;
+  ()
+
 (* Suites declaration. *)
 let suite =
   "mltools Tools_utils" >:::
@@ -164,6 +185,7 @@ let suite =
       "sizes.human_size" >:: test_human_size;
       "run_command" >:: test_run_command;
       "run_commands" >:: test_run_commands;
+      "external_command" >:: test_external_command;
     ]
 
 let () =
-- 
2.20.1




More information about the Libguestfs mailing list