Skip to content

assert_command foutput of OUnit 2.2.6 #93

Description

@akr

I found OUnit 2.2.6 changes the type of foutput option for assert_command.
9345a47

The sequence is created by seq_forever (same as Seq.forever for OCaml 4.14) which returns an infinite sequence.
The end of the sequence is notified by End_of_file exception raised by input_char.

It is different from OUnit 2.2.5 which creates a finite channel by Stream.of_channel.

The difference between "finite" and "infinite" causes us to need to catch End_of_file exception.

We can write as follows in OUnit 2.2.5.

open OUnit2

let test_foo (ctxt : test_ctxt) : unit =
  assert_command
    ~foutput:(fun stream -> Stream.iter (fun ch -> ignore ch) stream)
    ~ctxt
    "echo" ["foo"]

let () =
  run_test_tt_main ("foo" >:: test_foo)

We need to rewrite it as follows with OUnit 2.2.6.
It needs try-with addition to modifying from Stream.iter to Seq.iter.

open OUnit2

let test_foo (ctxt : test_ctxt) : unit =
  assert_command 
    ~foutput:(fun seq -> try 
                           Seq.iter (fun ch -> ignore ch) seq
                         with End_of_file ->
                           ())
    ~ctxt
    "echo" ["foo"]

let () =
  run_test_tt_main ("foo" >:: test_foo)

I'm not sure why Stream.t is changed to Seq.t.

Even if Seq.t has a good reason,
I think it is better to catch End_of_file exception in OUnit and produce a finite sequence as OUnit 2.2.5.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions