Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert_command foutput of OUnit 2.2.6 #93

Open
akr opened this issue Jun 8, 2022 · 1 comment
Open

assert_command foutput of OUnit 2.2.6 #93

akr opened this issue Jun 8, 2022 · 1 comment

Comments

@akr
Copy link

akr commented Jun 8, 2022

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.

@akr
Copy link
Author

akr commented Jun 20, 2022

I found the reason to avoid Stream.t:
OCaml 4.14.0 deprecated Stream.
https://ocaml.org/releases/4.14.0

I still think that it is better to avoid End_of_file exception for foutput.
I'm happy if I can adapt newer OCaml and OUnit by just changing Stream.iter to Seq.iter without try-with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant