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

add tests to make sure tty detection works #48

Open
cdepillabout opened this issue Aug 5, 2019 · 2 comments
Open

add tests to make sure tty detection works #48

cdepillabout opened this issue Aug 5, 2019 · 2 comments

Comments

@cdepillabout
Copy link
Owner

cdepillabout commented Aug 5, 2019

PR #47 changes functions like pPrint so that they check whether the output Handle is a TTY device or not. If it is not, then outputting in color is disabled by default. (Thanks @metiulekm!)

This works well, but it would be nice to have tests to make sure that outputting in color is getting enabled/disabled when it should.

Basically, the tests should open a pseudo terminal and try outputting to it with a function like pHPrint. The tests should also try opening a normal file and outputting to it with the same function. The tests should check that when outputting to a PTY, the output is in color, but when outputting to a normal file, output is not in color.

I'm not too familiar with how PTY works on Linux. It looks like there is a function for opening a PTY:

http://hackage.haskell.org/package/unix-2.7.2.2/docs/System-Posix-Terminal.html#v:openPseudoTerminal

As well as a function for converting an FD to a Handle:

http://hackage.haskell.org/package/unix-2.7.2.2/docs/System-Posix-IO.html#v:fdToHandle

However, I'm not sure how to use the master and slave PTY FDs.

This book apparently has a description of how to use PTYs in chapter 64:

https://nostarch.com/tlpi

Currently there is no test suite for unit tests in pretty-simple, so you'll have to add one. I suggest using tasty or hspec.

@cdepillabout
Copy link
Owner Author

I added a beginner-friendly label to this issue, since the Haskell code you have to write should be relatively simple. However, figuring how to to write to and read from a PTY might be a little complex.

@georgefst
Copy link
Collaborator

FWIW, pPrint currently doesn't use colour when invoked from a test suite with cabal test. pPrintOpt NoCheckColorTty defaultOutputOptionsDarkBg works successfully, so it would be nice if the library detected that it's possible.

Perhaps some relevant info here, though the story seems to have improved with cabal 3.

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

2 participants