On Wed, Jan 16, 2019 at 03:17:33PM +0100, Pino Toscano wrote:
--- 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;
begin..end isn't really necessary here, but it doesn't matter.
+ () + (* 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; ]
ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW