expect_test tool: disable colorized output#1527
Conversation
|
I don't understand why this change is necessary, If TERM=dumb was set as with the previous Makefile, there should be no regression in the first place, so this PR shouldn't be necessary, Is TERM=dumb not set? Is it set somewhere but ineffective? @sliquister, how can I reproduce the issues you observed with color outputs? |
|
Gabriel Scherer (2017/12/13 08:01 +0000):
I don't understand why this change is necessary, If TERM=dumb was set
as with the previous Makefile, there should be no regression in the
first place,
Yep, I agree with you. And actually that's what I thought when I replied
to your question, yesterday.
But then, if you want to run a test through ocamltest manually, then you
will not benefit from the Makefile TERM setting and I suspect this is
the motivation behind @sliquister's request.
So, as I see it, it's not really that PR #1519 introduced a regression
for which the present PR would be a fix. It's just that this PR makes
possible something that was not really possible before, i.e. running
expect tests manually.
so this PR shouldn't be necessary, Is TERM=dumb not set? Is it set
somewhere but ineffective?
Well as explained in the PR and commit messages. If a tool expects
things to be configured in a certain way, and if, in addition, it has
the ability to configure things the way it wants them to be, then why
not make the configuration itself? Why shoudl that tool rely on the
outter world to setup a configuration it needs and can set by itself?
To me, the idea that expect_test should rely on TERM being set to dumb
is suboptimal and that's what this PR attempts to fix, almost
independently of #1519 which just revealed the issue.
@sliquister, how can I reproduce the issues you observed with color
outputs?
Yeah I'm curious about this, too, I have to say. It would allow to make
sure this PR effectively improves the situation.
|
|
Could someone explain or point to an explanation of the issue in question? It sounds like it would be better to fix the root cause rather than change the code so that the problem is not triggered. Personally, in general I think we should not be reducing the use of color, but rather increasing it, since it can be quite a useful aid to readability. |
|
Nicolás Ojeda Bär (2017/12/13 00:22 -0800):
Could someone explain or point to an explanation of the issue in
question?
I'll leave that one to @slquister.
Personally, in general I think we should not be reducing the use of
color, but rather increasing it, since it can be quite a useful aid to
readability.
For humans, yes. And not even all of them, I guess. :-)
But when it comes to compare results, perhaps it is indeed better to let
colors out of the game. But again, I guess @sliquister will tell us.
I am not particularly attached to this PR. I just wanted to address the
TERM issue in a better way but if it turns out there is an even better
way, fine with me.
What I do think, though, is that this PR is better than relying on the
outter world to setup TERM.
|
It was already possible to go in a specific test directory and run I have a preference for using Note that ocamltest could set this value in the environment globally for its invocation (this is what I had understood from your answer) instead of just locally for the expect_test invocation -- because it may be useful for other kinds of toplevel-based tests as well. @nojb: various parts of the compiler that are exercised by the tests depend on whether they have a "rich terminal" attached or not. When the tests are run in batch mode, the answer is always "no", but when the tests are run on a case-by-case basis, it can happen that you are in a setting where the answer is "yes", and then the output may differ from the reference file because of that -- because the toplevel tried to use curses-style location printing, or because color escape codes end up in the output, etc. Right now we don't have tests in the compiler for color in the compiler output. If/when we decide to add some, we would have to carefully understand how to test them and when to skip them, and they would be explicitly excluded from the general principles above. |
|
I haven't looked at the details, but generally colors are disabled when the output device is not a terminal, in particular when outputting to a |
|
Which brings us back to the original question: how can we reproduce the regression that @sliquister observed? |
|
Gabriel Scherer (2017/12/13 01:31 -0800):
> It's just that this PR makes possible something that was not really possible before, i.e. running expect tests manually.
It was already possible to go in a specific test directory and run
`make`, which I suppose is the workflow @sliquister tried to imitate,
and raised the issue?
Indeed, the directory-level granularity was possible. What was not
possible, I think, was to test just one file from the command-line.
I have a preference for using `TERM=dumb` rather than setting
`Clflags` because (1) it more closely mirrors the way the previous
code worked,
But suppose we come to think this way of doing things is subobtimal.
Would you still want to reflect it as closely as possible? :)
and thus reduces the chances of regressions and (2) the
TERM setting affect not only colors but also, for example, location
printing in Toploop.
Even if it is considered that setting the colors is not enough and that
expect really needs TERM=dumb, wouldn't it be better that the tool
itself defines the variable for itself, rather than relying on the rest
of the world doing it?
Or would it be too late to do this setting at the very beginning of the
main part of expect_test?
|
|
I would propose to wait until @sliquister lets us know how to reproduce the failure he found, because that may suggest at which level it is best to have a fix. |
|
Gabriel Scherer (2017/12/13 02:12 -0800):
I would propose to wait until @sliquister lets us know how to
reproduce the failure he found, because that may suggest at which
level it is best to have a fix.
Fully agreed.
|
|
Yeah, I was running ocamltest directly, without Makefile. I don't see how else to run a single test. There's this |
|
@sliquister I cannot reproduce the issue on my machine, in the current trunk, picking a random test directory that contains expect tests. [gasche@zigomar typing-misc (trunk)]$ pwd
/home/gasche/Prog/ocaml/github-trunk/testsuite/tests/typing-misc
[gasche@zigomar typing-misc (trunk)]$ ../../../ocamltest/ocamltest.opt *.ml
... testing 'constraints.ml' with 1 (expect) => passed
... testing 'labels.ml' with 1 (expect) => passed
... testing 'occur_check.ml' with 1 (expect) => passed
... testing 'polyvars.ml' with 1 (expect) => passed
... testing 'pr6939-flat-float-array.ml' with 1 (flat-float-array) => passed
... testing 'pr6939-flat-float-array.ml' with 1.1 (expect) => passed
... testing 'pr6939-no-flat-float-array.ml' with 1 (no-flat-float-array) => skipped
... testing 'pr6939-no-flat-float-array.ml' with 1.1 (expect) => skipped
... testing 'pr7103.ml' with 1 (expect) => passed
... testing 'pr7228.ml' with 1 (expect) => passed
... testing 'pr7668_bad.ml' with 1 (expect) => passed
... testing 'printing.ml' with 1 (expect) => passed
... testing 'records.ml' with 1 (expect) => passed
... testing 'variant.ml' with 1 (expect) => passed
... testing 'wellfounded.ml' with 1 (expect) => passed
[gasche@zigomar typing-misc (trunk)]$ echo $TERM
xterm-256color |
|
|
And to clarify a bit: I think it only affects certain tests because ocaml-expect has its own printing function for positions, so the problem shows up with error printing functions that print locations, which happens in includemod.ml and perhaps in very few other places. |
|
I think that it is just a matter of calling |
|
@nojb: Yes, that sounds right. |
|
(Edit: what follows is not right, see next message.) I checked: this error is not, as we first thought, a regression due to @shindere's work on migrating the expect tests to ocamltest. I can reproduce it also when using the old Makefile harness on top of the current trunk. I think that the regression is due to @Octachron's a035ee9 , which must have changed some of the ways expect_tests interacts with OCaml flag settings. |
|
Scrap that: I my message above is wrong because I tested the things the wrong way. With more testing, here is what I observe:
Surprisingly, if my testing is correct, then removing the TERM=dumb setting in the |
|
@nojb: thinking about this more (sorry for the back-and-forth), I don't think that |
|
Now that I can reproduce the issue, I still think that we should pass |
|
Gabriel Scherer (2017/12/14 08:54 +0000):
Now that I can reproduce the issue, I still think that we should pass
`TERM=dumb` to the expect_test invocation ( @shindere: do you know how
to do this? )
Sure
because this affects not only colors,
Just to improve my understanding: wuld you be able to elaborate on this
and explain precisely what exactly this affects?
As I already said, if expect needs a precise configuration, I really
believe it should set things up as it needs them to be, rather than
relying on the external world to do so, especially if configuring things
the required way can be achieved.
but I also think that it is safe and correct to forcefully set
`Cflags.color` in expect_test. But this should be done in `let main
()`, rather than `let ()`, so that it goes *after* command-line
parsing.
My intuition is that, if the configuration is done before command-line
parsing, then it makes it possible to override it by means of
command-line options, if that becomes necessary, one day.
The other way around, if this setting is done after the parsing of the
command-line, then the user might be in a situation where a command-line
option is silently discarded, which may be surprising and sounds a bit
counter-intuitive to me.
|
|
Gabriel Scherer (2017/12/14 00:44 -0800):
Scrap that: I my message above is wrong because I tested the things the wrong way. With more testing, here is what I observe:
- running the `typing-modules` test through the root testsuite makefile works correctly
(feature request: being able to run the tests from a single
directory, instead of having to run all new tests)
See PR #1530
|
|
Gabriel Scherer (2017/12/14 00:44 -0800):
- running `ocamltest` directly from the directory fails as @sliquister reports
```
cd testsuite/tests/typing-modules
../../../ocamltest/ocamltest.opt applicative_functor_type.ml
```
OK I could finally reproduce the problem. Thanks for testing, @gasche,
it helped. I pasted your command and the test failed. Then I used the
ocamltest script that I have in my path and the test passed. So I
examined my script and... it was setting TERM to dumb. :)
I got rid of that setting in my script.
- if I apply the change that @nojb suggests *and* I pass TERM=dumb,
- then the failure goes away
|
|
I apologize for the mess I produced this morning. I investigated the issue in more details now and I understand what is happening better. Here is the set of reasons that explain why we get color escape codes when running sliquister's new test:
Now, to your excellent questions/remarks:
From the point of view of an OCaml program, I don't think that it is safe to reason on when the
You can use
Yes, you are completely correct and my intuition was dead wrong. In fact, "one day" may come close as @nojb (I think?) is already questioning how we test color output -- answer: we don't. Testing color output can now be done "easily" by just passing . All in all, I am still of the opinion that setting TERM=dumb from ocamltest (or in a wrapper program that controls the expect_test invocation and is called by ocamltest) is the better fix, and that the proposed fix is incomplete and may not be what we want (I think that keeping the expect_test semantics close to what other OCaml drivers do would be wise, to not be surprised later by differences in behavior). |
|
Thanks a lot for your response, @gasche.
And no problem for this morning, it seems we are discussing a somewhat
hot and subtle topic, I wouldn't have thought! ;-)
All in all, I am still of the opinion that setting TERM=dumb from
ocamltest (or in a wrapper program that controls the expect_test
invocation and is called by ocamltest) is the better fix, and that the
proposed fix is incomplete and may not be what we want (I think that
keeping the expect_test semantics close to what other OCaml drivers do
would be wise, to not be surprised later by differences in behavior).
Well at the moment I disagree, but "Y a que les imbéciles qui ne
changent pas d'avis", so I'd really be happy to let myself convince.
Several small remarks.
1. It's easy to have ocamltest pass TERM=dumb, so that's really not an
issue.
2. In my understanding, the difficulties we encounter while trying to
understand the real problem are precisely coming form the use of TERR.
Here, the Makefiles were setting it while ocamltest does not and that
made the situation even more difficult to understand, because somehow it
introduced a discrepancy.
Now, it my opinion, what you are asking would introduce exactly the same
kind of discrepancy, this time between calling expect from ocamltest
(thus with TERM set to the expected value) and calling expect from the
command line. And it may very well happen that we want to call it
directly, for testing, debugging or whatever purpose and in this
situation we would have to think about setting TERM, and believe me, we
will forget. I will.
3. You say the proposed fix is not complete. Can you build an example
where this test is not enough?
|
|
sliquister (2017/12/14 02:15 +0000):
And to clarify a bit: I think it only affects certain tests because
ocaml-expect has its own printing function for positions, so the
problem shows up with error printing functions that print locations,
which happens in includemod.ml and perhaps in very few other places.
@sliquister Do you have an opinion about what the right way to fix this
would be?
|
Well, the discrepancy comes from the fact that:
As far as I know, no one used to run If you believe that it is important to set I am also worried that I am going above the time budget that it is reasonable to spend over how |
|
sliquister (2017/12/13 14:57 +0000):
Yeah, I was running ocamltest directly, without Makefile. I don't see
how else to run a single test. There's this `one` phony target in
testsuite, but I think that's just there to confuse the enemy.
No, actually this one target did work for the legacy tests and still
does, as far as I know.
It's just that, when I integrated the ability to run ocamltest-driven
tests to the testsuite, I didn't extend this rule, I don't know why I
didn't do that to be honest.
Anyway, there is now PR #1530 which repairs this. Sorry for the trouble.
|
|
@shindere I tried this pull request and it fixes the test breakage because of colors. Now, if making expect-test not rely on the environment is the right solution, then by the same logic, the TERM=dumb around the call ocamltest in testsuite/Makefile should be moved in ocamltest itself. So maybe we just need both changes, one to make ocamltest work the same with or without a Makefile (my problem), this one to make expect-test work the same regardless of whether it's called directly or by ocamltest. |
|
sliquister (2017/12/15 03:10 +0000):
@shindere I tried this pull request and it fixes the test breakage because of colors.
Now, if making expect-test not rely on the environment is the right
solution, then by the same logic, the TERM=dumb around the call
ocamltest in testsuite/Makefile should be moved in ocamltest itself.
Well this claim is a bit odd: it makes expect-test on being called by
ocamltest, right. :)
Of course if we do that, the initial problem is fixed without needing
to touch expect-tests.
True.
So maybe we just need both changes, one to make ocamltest work the
same with or without a Makefile (my problem), this one to make
expect-test work the same regardless of whether it's called directly
or by ocamltest.
The second fix superseeds the first one, IMO, but see PR #1532
|
|
I'm fine with merging this in addition to #1532, or closing it if you decide to not do both. Your decision! |
testsuite/tools/expect_test.ml
Outdated
| options are:" | ||
|
|
||
| let () = | ||
| Clflags.color := Some Never; |
There was a problem hiding this comment.
I think that Never would be nicer written Misc.Color.Never, as I think this module is not opened in scope.
|
Gabriel Scherer (2017/12/15 09:45 +0000):
I'm fine with merging this in addition to #1532, or closing it if you
decide to not do both. Your decision!
Let's merge then, please.
|
Colorized output prevents expect_test from working properly, so the tool requires that the output does not use colors. Before this commit, this was achieved by setting the TERM environment variable to "dumb" before calling expect_test. This commit disables colorized output from within the tool itself and thus removes the need of setting the TERM environment variable before calling it.
a9fcc99 to
de51a52
Compare
|
Gabriel Scherer (2017/12/15 01:46 -0800):
gasche commented on this pull request.
> @@ -398,6 +398,7 @@ let usage = "Usage: expect_test <options> [script-file [arguments]]\n\
options are:"
let () =
+ Clflags.color := Some Never;
I think that `Never` would be nicer written `Misc.Color.Never`, as I
think this module is not opened in scope.
Good idea, thanks. Done and rebase on latest trunk.
|
Colorized output prevents expect_test from working properly, so the tool
requires that the output does not use colors.
Before this PR, this was achieved by setting the TERM environment
variable to "dumb" before calling expect_test.
This PR disables colorized output from within the tool itself
and thus removes the need of setting the TERM environment variable
before calling it.
Cc @sliquister