-
Notifications
You must be signed in to change notification settings - Fork 81
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
Fix reporting terminal dimensions #381
Conversation
dace603
to
d25192a
Compare
f3c9b07
to
1eb8a29
Compare
@OlivierNicole has done a nice review for this PR, thanks. |
- simplify macro dance; - enable size detection on macOS; - use CAML_NAME_SPACE before OCaml 5.0.
This allows the library to report the correct size even when test are run buffered with `dune runtest`, as it changes the standard output of the executable. The correct size was reported when the test was run unbuffered (e.g., with `dune exec -- test.exe`).
In some platforms, incorrect reporting would lead to a division by zero.
Even though we had the C stubs, it was disabled in OCaml code.
1eb8a29
to
846cf88
Compare
|
||
CAMLprim value ocaml_alcotest_get_terminal_dimensions(value unit) | ||
{ | ||
CAMLparam1(unit); | ||
CAMLlocal2(result, pair); | ||
struct winsize ws; | ||
int z = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws); | ||
if (z == 0) | ||
int fd = open("/dev/tty", O_RDONLY | O_NONBLOCK | O_CLOEXEC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case someone else is looking at this and doesn't know why STDOUT_FILENO
was replaced by "/dev/tty"
(like I was), the difference is when the output of alcotest is piped (say through a grep): stdout wouldn't have a size so the formatting would be different (and probably be confusing to users?), while the tty always return the same size (... I don't have strong opinion regarding this change, in general it's weird for piped programs to respect terminal size but it seems fine for alcotest)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM even if I don't really like the allocation on the C side (return -1
is a possibility for the None
case but it's not related to this PR).
CHANGES: - Add `match_raises`, a generalized version of `check_raises` (mirage/alcotest#88, mirage/alcotest#386, @JoanThibault) - Update JaneStreet core and async to v0.16 (mirage/alcotest#390 @tmcgilchrist) - Fix division by zero when size of the terminal is incorrectly reported as zero. (fix mirage/alcotest#356, mirage/alcotest#381, @MisterDA) - Enable terminal size reporting on macOS and Windows. Also report the terminal size even when the test is run buffered by Dune. (mirage/alcotest#381, mirage/alcotest#396, @MisterDA) - Allow overriding the number of columns with `ALCOTEST_COLUMNS` env var. (mirage/alcotest#322, mirage/alcotest#381, @MisterDA) - Be able to allocate and use user's formatters for stdout/stderr (mirage/alcotest#399, @dinosaure) - Stop detecting ocamlci specifically, since there's nothing specific about it. Simply use the `CI` env var to detect CIs. Improve CI detection. (mirage/alcotest#397, @MisterDA)
CHANGES: - Add `match_raises`, a generalized version of `check_raises` (mirage/alcotest#88, mirage/alcotest#386, @JoanThibault) - Update JaneStreet core and async to v0.16 (mirage/alcotest#390 @tmcgilchrist) - Fix division by zero when size of the terminal is incorrectly reported as zero. (fix mirage/alcotest#356, mirage/alcotest#381, @MisterDA) - Enable terminal size reporting on macOS and Windows. Also report the terminal size even when the test is run buffered by Dune. (mirage/alcotest#381, mirage/alcotest#396, @MisterDA) - Allow overriding the number of columns with `ALCOTEST_COLUMNS` env var. (mirage/alcotest#322, mirage/alcotest#381, @MisterDA) - Be able to allocate and use user's formatters for stdout/stderr (mirage/alcotest#399, @dinosaure) - Stop detecting ocamlci specifically, since there's nothing specific about it. Simply use the `CI` env var to detect CIs. Improve CI detection. (mirage/alcotest#397, @MisterDA)
CHANGES: - Add `match_raises`, a generalized version of `check_raises` (mirage/alcotest#88, mirage/alcotest#386, @JoanThibault) - Update JaneStreet core and async to v0.16 (mirage/alcotest#390 @tmcgilchrist) - Fix division by zero when size of the terminal is incorrectly reported as zero. (fix mirage/alcotest#356, mirage/alcotest#381, @MisterDA) - Enable terminal size reporting on macOS and Windows. Also report the terminal size even when the test is run buffered by Dune. (mirage/alcotest#381, mirage/alcotest#396, @MisterDA) - Allow overriding the number of columns with `ALCOTEST_COLUMNS` env var. (mirage/alcotest#322, mirage/alcotest#381, @MisterDA) - Be able to allocate and use user's formatters for stdout/stderr (mirage/alcotest#399, @dinosaure) - Stop detecting ocamlci specifically, since there's nothing specific about it. Simply use the `CI` env var to detect CIs. Improve CI detection. (mirage/alcotest#397, @MisterDA)
Fix division by zero when size of the terminal is incorrectly reported as zero. (fix Random crashes when running tests in a non-standard terminal #356, Fix reporting terminal dimensions #381, @MisterDA)
Enable terminal size reporting on macOS and Windows. Also report the terminal size even when the test is run buffered by Dune.
(Fix reporting terminal dimensions #381, @MisterDA)
Allow overriding the number of columns with
ALCOTEST_COLUMNS
env var. (Manually set output width #322, Fix reporting terminal dimensions #381, @MisterDA)My intent was to use a bigger default than 80 columns when the CI is detected. Sadly, this would seem to require too big of a refactoring to communicate the default size to the
Pp
module, which is also why I haven't made the number of columns configurable programmatically, and exposed it only via an environment variable to fix reproducibility issues for the Unix platform.Oddly enough, communicating the bounds to the
Format
module withFormat.set_margin
hides the first[OK]
,[FAIL]
, etc tag. I've haven't dug why.I've tested that this on macOS, Windows FreeBSD, and Linux.