alcotest icon indicating copy to clipboard operation
alcotest copied to clipboard

Random crashes when running tests in a non-standard terminal

Open Sventimir opened this issue 3 years ago • 2 comments

I sometimes execute our test written with Alcotest in Emacs. Recently I have seen them to crash with the following exception:

main.exe: internal error, uncaught exception:
          Division_by_zero
          Raised at Alcotest_engine__Pp.Make.event in file "src/alcotest-engine/pp.ml", line 165, characters 11-59
          Called from Alcotest_engine__Core.Make.perform_test in file "src/alcotest-engine/core.ml", line 237, characters 4-45
          Called from Alcotest_engine__Monad.Extend.Syntax.(>|=).(fun) in file "src/alcotest-engine/monad.ml", line 32, characters 46-51
          Called from Alcotest_engine__Monad.Extend.List.fold_map_s.inner in file "src/alcotest-engine/monad.ml", line 44, characters 26-34
          Called from Alcotest_engine__Core.Make.perform_tests in file "src/alcotest-engine/core.ml", line 252, characters 6-276
          Called from Alcotest_engine__Core.Make.result in file "src/alcotest-engine/core.ml", line 302, characters 19-44
          Called from Alcotest_engine__Core.Make.run_tests in file "src/alcotest-engine/core.ml", line 356, characters 8-27
          Called from Alcotest_engine__Core.Make.run_with_args' in file "src/alcotest-engine/core.ml", line 390, characters 6-304
          Called from Cmdliner_term.app.(fun) in file "cmdliner_term.ml", line 24, characters 19-24
          Called from Cmdliner_eval.run_parser in file "cmdliner_eval.ml", line 34, characters 37-44

It appears that the 0 comes from the call to ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws), which Emacs apparently sometimes reports badly. It would be nice to make Alcotest resistant to this kind of error and perhaps assume some standard value for the width of the window.

Sventimir avatar Jun 27 '22 11:06 Sventimir

Maybe

  let stdout_columns () =
    if Sys.win32 then None
    else
      match Terminal.get_dimensions () with
-      | Some { columns; _ } -> Some columns
+      | Some { columns; _ } -> if columns <= 0 then None else Some columns
      | None -> None

hhugo avatar Jun 27 '22 11:06 hhugo

Actually a guard when columns > 0 should be sufficient.

Sventimir avatar Jun 27 '22 11:06 Sventimir