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

cabal test --test-show-details=streaming should support colour output #1963

Closed
mietek opened this issue Jun 26, 2014 · 9 comments
Closed

cabal test --test-show-details=streaming should support colour output #1963

mietek opened this issue Jun 26, 2014 · 9 comments

Comments

@mietek
Copy link
Contributor

mietek commented Jun 26, 2014

As discussed in #1601 (comment)

Paging @ttuegel, @dag.

@mietek mietek changed the title Support color output in cabal test --show-details=streaming Support color output in 'cabal test --show-details=streaming' Jun 26, 2014
@ttuegel
Copy link
Member

ttuegel commented Jun 26, 2014

I investigated this when I originally implemented test log streaming. Here is what I discovered:

  • On Unix-like platforms, you need to use a PTY instead of a pipe to communicate with the child process. Libraries for doing color terminal output detect if they're connected to a pipe and disable color.
  • Windows has no notion of a PTY or anything like it. I do not even know if this can be done on Windows.
  • Assuming you have the child process connected to a PTY, Cabal would need to emulate the terminfo of the terminal it's connected to in case the child process uses features besides just ANSI color.
  • Finally, to write the log file, you have to remove the control codes yourself. But, that's not enough: if the test output used control codes that change the contents of the screen, the log file will be garbled.

Of course, this is all dictated by the logging requirement. If we abandon logging test suite results for --show-details=streaming, we can just passthrough stdout and stderr. I opted not to drop the test logs because that would be a significant departure from the way Cabal has worked until now, but we can use this issue to discuss that option.

@Rufflewind
Copy link
Member

There is an easier workaround via the script utility, which does all the tricky TTY emulation and stuff. (It doesn't fix all the problems though; color codes will still get recorded to file, but you could argue that's a "feature" too: you can view the colored output using less -R.)

To make it work, there needs to be a way to invoke the test executable via a wrapper of some kind. This would have applications beyond colored output and should be relatively easy to implement.

Therefore, the easiest way to get colored output is if Cabal supported a way to indirectly invoke the test executable via a flag or .cabal setting (or both?), e.g.

cabal test --test-runner=./faketty.sh --test-option=opt1

which would call the test executable like this:

./faketty.sh dist/build/test/mytest opt1

You can then put this in faketty.sh:

#!/bin/sh
p="s/'/'\\\\''/g"
cmd=
for arg; do
    cmd="$cmd '"`printf "%s" "$arg" | sed "$p"; printf "'"`
done
exec script -e -q -c "$cmd" /dev/null 2>/dev/null

@ttuegel
Copy link
Member

ttuegel commented Sep 29, 2015

To make it work, there needs to be a way to invoke the test executable via a wrapper of some kind. This would have applications beyond colored output and should be relatively easy to implement.

Not yet, but your contribution would be welcome!

For this particular case, I think it would be best if this worked out-of-the-box. If we added script to the list of configurable programs, we could build this function into the test runner (while having the ability to fallback to something else if script isn't available).

@23Skidoo 23Skidoo modified the milestones: Cabal 1.24, Cabal 1.26 Feb 21, 2016
@ezyang ezyang removed this from the Cabal 2.0 milestone Aug 16, 2016
@chshersh
Copy link
Member

Does this issue affect cabal new-test as well? I don't see colored test output with cabal new-test (Cabal version: 2.1.0.0, testing framework: tasty, os: Ubuntu 16.04). Though with stack build tool I see colored test output. In practice it's really useful to see colors in output. When tests are failing it's much easier to find red test results rather than searching for FAIL keyword.

@erikd
Copy link
Member

erikd commented Jun 5, 2019

Does this issue affect cabal new-test as well?

Yes it does!

I have dug into the stack source code and it too uses a pipe (via createSource from typed-process) but I can't see that its doing anything special to get the colour coming through

@erikd
Copy link
Member

erikd commented Jul 8, 2019

Colored test output works with cabal test --test-show-details=direct.

See also: #6129

@mietek mietek changed the title Support color output in 'cabal test --show-details=streaming' cabal test --test-show-details=streaming should support colour output Jul 8, 2019
@yaitskov
Copy link

Why command line flag is so long? I would expect something like -d

@gbaz
Copy link
Collaborator

gbaz commented Apr 21, 2022

Given that we have direct does this ticket really still make sense?

@Mikolaj
Copy link
Member

Mikolaj commented Apr 22, 2022

@gbaz: no, the ticket seems to be outdated. Let's close.

@yaitskov: you can set test-show-details: direct in your cabal.project file and then the length no longer hurts. But feel free to review our commandline options and propose a sensible scheme of one-letter counterparts for all (most?) in a new ticket, especially if you'd like to implement that. That may be ripe for some overhaul.

@Mikolaj Mikolaj closed this as completed Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants