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

Pino Toscano ptoscano at redhat.com
Thu Jan 17 10:25:58 UTC 2019


On Wednesday, 16 January 2019 15:32:57 CET Richard W.M. Jones wrote:
> 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.

I added them there like I did in other tests, mostly to group each
block representing a different thing to check in the test case.

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190117/334552da/attachment.sig>


More information about the Libguestfs mailing list