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

Use coloured output by default when running INSIDE_DUNE #242

Merged
merged 4 commits into from
Jun 2, 2020

Conversation

craigfe
Copy link
Member

@craigfe craigfe commented May 17, 2020

This changes the default value of the --color flag to always rather than auto when the INSIDE_DUNE variable is set.

As discussed before (see #207 and ocaml/dune#145), Alcotest output is not coloured by default if run via dune runtest, since Dune's buffering mechanism keeps the test process from having direct access to the terminal.

We now have the ALCOTEST_COLOR variable for experienced users to override this behaviour, but I suspect the better solution is to default to always showing colours, so that new users are not surprised by this interaction. People who really don't want colours can still disable it with the environment variable or the command-line option.

Travis CI appears to filter out any ANSII colour codes in its logs (see https://travis-ci.org/github/mirage/irmin/jobs/686951739#L3684).

@craigfe
Copy link
Member Author

craigfe commented May 17, 2020

Appveyor handles this change just fine:

image

as does Travis:

image

as does OCaml-CI:

image

(well, no worse than usual there...)

@craigfe craigfe force-pushed the colors-by-default branch 2 times, most recently from 54c4906 to f86d621 Compare May 17, 2020 17:39
@talex5
Copy link
Contributor

talex5 commented May 18, 2020

The output in ocaml-ci is a bit hard to read, but I guess this was the error:

2.894 test_color test/e2e/alcotest/inside-dune/color-default.actual (exit 125)

(https://ci.ocamllabs.io:8100/job/2020-05-17/173931-ci-build-d08ed7)

I rebuilt the jobs and they passed the second time :-/

@craigfe
Copy link
Member Author

craigfe commented May 18, 2020

The errors on 4.03 and 4.04 seem repeatable at least. I can reproduce the diff on my machine. Here's an excerpt:

ᐅ diff <(xxd color-default.4.08) <(xxd color-default.4.03)

-00000000: 5465 7374 696e 6720 1b5b 316d 7465 7374  Testing .[1mtest
+00000000: 5465 7374 696e 6720 1b5b 3031 6d74 6573  Testing .[01mtes
-00000010: 5f63 6f6c 6f72 1b5b 306d 2e0a 5468 6973  _color.[0m..This
+00000010: 745f 636f 6c6f 721b 5b6d 2e0a 5468 6973  t_color.[m..This

So, the escape codes look to be the same modulo differences in ANSI escape resetting that have no bearing on the rendered output.

Sure enough, Fmt.0.8.7 (which dropped support for 4.03.0 and 4.04.0) contains a change that breaks compatibility of ANSI escapes: dbuenzli/fmt@594a1d7 (sadly not highlighted in the CHANGES).

I rebuilt the jobs and they passed the second time :-/

@talex5: No idea what's causing the flaky failures post 4.04.0 though; ran the tests 100 times or so on my machine and got only passes. OCaml-CI is caching a bit too aggressively for me to prod it further: shouldn't clicking rebuild invalidate the cache layer for the dune build @runtest stage?

@talex5
Copy link
Contributor

talex5 commented May 19, 2020

OCaml-CI is caching a bit too aggressively for me to prod it further: shouldn't clicking rebuild invalidate the cache layer for the dune build runtest stage?

Good idea - I've filed an issue here: ocurrent/ocaml-ci#186

@craigfe
Copy link
Member Author

craigfe commented May 19, 2020

I would suggest just dropping this test, but I have future improvements in mind that require heavier usage of the styled formatter (including styles that I now see weren't introduced until 0.8.7).

I think the options here are:

  • drop support for 4.03 and 4.04;
  • vendor the style formatters (or all of fmt);
  • use a different formatting dependency.

Does anyone have thoughts on this? (@samoht, @avsm)

@samoht
Copy link
Member

samoht commented May 19, 2020

It's fine to vendor fmt (as long as there is no name clashes when people will try to link them to their project).

@craigfe
Copy link
Member Author

craigfe commented May 19, 2020

I think I've tracked down all of the non-deterministic failures now. (At least, I've killed all the ones that I can reproduce on my machine...) Our handling of symlinks in alcotest.ml has race-conditions. When running the test suite, each case contends for the latest symlink, exposing those TOCTOU errors. I have a diff to fix that; will PR separately on Friday.

Our use of Cmdliner throws away helpful information that we should probably be logging somewhere (an `Exn being returned is almost always an internal error). I'll make a PR to fix that too.

craigfe added a commit to craigfe/alcotest that referenced this pull request May 22, 2020
This drops support for OCaml 4.03 and 4.04.

See discussion in mirage#242 (comment).
@craigfe
Copy link
Member Author

craigfe commented May 22, 2020

Now depends on #245.

craigfe added a commit to craigfe/alcotest that referenced this pull request May 22, 2020
This drops support for OCaml 4.03 and 4.04.

See discussion in mirage#242 (comment).
craigfe added a commit to craigfe/alcotest that referenced this pull request May 22, 2020
This drops support for OCaml 4.03 and 4.04.

See discussion in mirage#242 (comment).
craigfe added a commit to craigfe/alcotest that referenced this pull request May 22, 2020
This drops support for OCaml 4.03 and 4.04.

See discussion in mirage#242 (comment).
@craigfe
Copy link
Member Author

craigfe commented May 23, 2020

This can now be considered for merge.

Vendoring is slightly non-trivial as we export the Fmt.t type in our interface. It's possible to inline the definition of that type everywhere that it occurs, but I suspect it's more bother than it's worth. Happy to adjust if others disagree.

@craigfe craigfe mentioned this pull request May 25, 2020
@hannesm
Copy link
Member

hannesm commented May 25, 2020

I'm a bit sceptical of this change: it hardcodes behaviour of the output depending on other environment variables (INSIDE_DUNE), which makes it not very obvious (to me) when colours are used.

At least, the behaviour of coloured output should be documented in the documentation (and how it behaves depending on the environment variables and command-line arguments, esp. what the order of precedence is).

@craigfe
Copy link
Member Author

craigfe commented May 25, 2020

I'm a bit sceptical of this change: it hardcodes behaviour of the output depending on other environment variables (INSIDE_DUNE)

"hardcodes" seems a bit harsh to me. It changes the default behaviour, but never overrides behaviour requested explicitly by the user. This can be done in 4 different ways:

  1. --color command line option,
  2. ALCOTEST_COLOR environment variable,
  3. runtime ?argv option,
  4. Fmt.setup_std_outputs.

At least, the behaviour of coloured output should be documented in the documentation (and how it behaves depending on the environment variables and command-line arguments, esp. what the order of precedence is).

The man-page output is now:

       --color=WHEN (absent ALCOTEST_COLOR env)
           Colorize the output. WHEN must be one of `auto', `always' or
           `never'. Defaults to `always' when running inside Dune, otherwise
           defaults to `auto'.

This to me suggests the priority ordering --color > ALCOTEST_COLOR > [default as specified], but it's not very explicit. What do you think?

If by 'documentation' you mean the Odoc output, our explanation of the command-line arguments (and their run-time equivalents) is currently very lacking and could certainly do with some general improvement. (The priority ordering is also fairly untested.)

@hannesm
Copy link
Member

hannesm commented May 25, 2020

oh sorry I missed the man page update, thanks for doing that.

@craigfe craigfe requested a review from samoht May 25, 2020 14:19
craigfe added a commit to craigfe/alcotest that referenced this pull request May 28, 2020
This drops support for OCaml 4.03 and 4.04.

See discussion in mirage#242 (comment).
This changes the default value of the `--color` flag to `always` rather
than `auto` when the `INSIDE_DUNE` variable is set.

As discussed before (see mirage#207
and ocaml/dune#145), Alcotest output is not
coloured by default if run via `dune runtest`, since Dune's buffering
mechanism keeps the test process from having direct access to the
terminal.

We now have the `ALCOTEST_COLOR` variable for experienced users to
override this behaviour, but I suspect the better solution is to default
to _always_ showing colours, so that new users are not surprised by this
interaction. People who really don't want colours can still disable it
with the environment variable or the command-line option.

Travis CI appears to filter out any ANSII colour codes in its logs (see
https://travis-ci.org/github/mirage/irmin/jobs/686951739#L3684).
This drops support for OCaml 4.03 and 4.04.

See discussion in mirage#242 (comment).
@craigfe
Copy link
Member Author

craigfe commented Jun 1, 2020

Rebased. Will merge this tomorrow if there are no outstanding comments / objections.

@craigfe craigfe merged commit a677a62 into mirage:master Jun 2, 2020
craigfe added a commit to craigfe/opam-repository that referenced this pull request Jul 13, 2020
…age (1.2.0)

CHANGES:

- Add an `alcotest-mirage` package, allowing the construction of MirageOS
  unikernels that run Alcotest test suites. (mirage/alcotest#238, @hannesm @linse)

- Add `Alcotest.check'`, a variant of `Alcotest.check` with labeled arguments.
  (mirage/alcotest#239, @hartmut27)

- Add a testable for the `bytes` type. (mirage/alcotest#253, @mefyl)

- Many assorted improvements to Alcotest output formatting. (mirage/alcotest#246, @craigfe)

- Default to `--color=always` when running inside Dune (mirage/alcotest#242, @craigfe). The
  value can be overridden by setting the `ALCOTEST_COLOR` variable in a `dune`
  file, for example:

```dune
(env
 (_
  (env-vars
   (ALCOTEST_COLOR auto))))
```

- Support all UTF-8 characters in test names and suite names, by normalising
  them for file-system interactions. (mirage/alcotest#249, @gs0510; mirage/alcotest#246, @craigfe)

- Fix various crashes when using non-filesystem-safe characters in test suite
  names (these break Alcotest when attempting to generate a corresponding log
  file). (mirage/alcotest#241, @mefyl; mirage/alcotest#246 @craigfe)
@craigfe craigfe deleted the colors-by-default branch August 18, 2020 14:16
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

Successfully merging this pull request may close these issues.

None yet

4 participants