-
Notifications
You must be signed in to change notification settings - Fork 107
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
Crashes unless stdout/err encoding is UTF-8 #110
Comments
^ so this is likely because the test executable is not being compiled with
^ this looks very similar to this problem #32 |
If anyone else lands here, adding this to hSetEncoding stdout utf8
hSetEncoding stderr utf8 |
What is your 'locale' command output?
…On Fri, 28 Jul 2017, 10:20 pm Nikos Baxevanis, ***@***.***> wrote:
Here's also a screenshot from a failing property:
[image: image]
<https://user-images.githubusercontent.com/287532/28736680-aac6e2d8-73f3-11e7-8e66-c018eca6a564.png>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#110 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABRjjb6bwHhegCSCR31L-Klusix2qQxks5sSlCVgaJpZM4OfVEq>
.
|
According to systeminfo it is en-us;English (United States). |
In bash,
|
I'm also seeing this problem. Runs okay on my machine, but fails on Travis CI. |
@chris-martin, you mean the output looks like the images above? |
@moodmosaic Output looks like this:
https://travis-ci.org/chris-martin/haskell-libraries/builds/259263874 |
@chris-martin, even after trying this workaround? |
@moodmosaic Ah, no, that workaround does seem to fix it. |
Wondering if this could be avoided by adding a main runner (as suggested in #97 ) that sets encoding accordingly? |
stack test
Actually, if I understand the issue right, a proper fix would be to do something like this: https://phabricator.haskell.org/D1153. It would be especially nice not only to transliterate Haskell identifiers, but also refrain from using all the utf-8 goodness when the terminal does not support it. |
@kirelagin I tried that on Win10 (phabricator.haskell.org/D1153) and seems to be doing a better job indeed: import Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
import GHC.IO.Encoding (mkTextEncoding, textEncodingName)
import System.IO (Handle, hGetEncoding, hSetEncoding, stderr,
stdout)
tests :: IO Bool
tests = do
hSetTranslit stdout
hSetTranslit stderr
checkParallel $$discover
-- | Change the character encoding of the given Handle to transliterate on
-- unsupported characters instead of throwing an exception.
-- https://phabricator.haskell.org/D1153
hSetTranslit :: Handle -> IO ()
hSetTranslit h = do
menc <- hGetEncoding h
case fmap textEncodingName menc of
Just name | '/' `notElem` name -> do
enc <- mkTextEncoding $ name ++ "//TRANSLIT"
hSetEncoding h enc
_ -> pure () |
So, the bare minimums to keep Windows happy are import System.IO (hSetEncoding, stdout, stderr, utf8)
main :: IO ()
main = do -- ^ or put those in your test runner's main
hSetEncoding stdout utf8
hSetEncoding stderr utf8
... You might have to change the active console code page to UTF-8 chcp 65001 -- |
hedgehog uses fancy unicode codepoints to point it's output; this is at odds with non-utf8 charsets and leads to GHC crashing with <stdout>: commitBuffer: invalid argument (invalid character) This change sets the stdout/stderr encoding to utf8 prior to running hedgehog tests via the `runTests` function. The relevant hedgehog issue is hedgehogqa/haskell-hedgehog#110
hedgehog uses fancy unicode codepoints to point it's output; this is at odds with non-utf8 charsets and leads to GHC crashing with <stdout>: commitBuffer: invalid argument (invalid character) This change sets the stdout/stderr encoding to utf8 prior to running hedgehog tests via the `runTests` function. The relevant hedgehog issue is hedgehogqa/haskell-hedgehog#110
hedgehog uses fancy unicode codepoints to point it's output; this is at odds with non-utf8 charsets and leads to GHC crashing with <stdout>: commitBuffer: invalid argument (invalid character) This change sets the stdout/stderr encoding to utf8 prior to running hedgehog tests via the `runTests` function. The relevant hedgehog issue is hedgehogqa/haskell-hedgehog#110
hedgehog uses fancy unicode codepoints to point it's output; this is at odds with non-utf8 charsets and leads to GHC crashing with <stdout>: commitBuffer: invalid argument (invalid character) This change sets the stdout/stderr encoding to utf8 prior to running hedgehog tests via the `runTests` function. The relevant hedgehog issue is hedgehogqa/haskell-hedgehog#110
hedgehog uses fancy unicode codepoints to point it's output; this is at odds with non-utf8 charsets and leads to GHC crashing with <stdout>: commitBuffer: invalid argument (invalid character) This change sets the stdout/stderr encoding to utf8 prior to running hedgehog tests via the `runTests` function. The relevant hedgehog issue is hedgehogqa/haskell-hedgehog#110
On Windows, unlike Unix, the console itself is not a stream of `bytes` but a spreadsheet of cells, each of which contains an UTF-16 character and a color attribute. That means if your application produces output using single-byte or multi-byte character sets (which are ANSI, OEM, UTF-8 and many others) the Windows converts that output to UTF-16 automatically regarding active codepage selected in your console (run chcp from console command prompt to check your active codepage). If you want to work with UTF-8 encoding you have to select UTF-8 as active console codepage. Just run chcp 65001 command to do that. Taken from: - https://conemu.github.io/en/UnicodeSupport.html - hedgehogqa#110 (comment)
/cc @angerman |
hedgehog uses fancy unicode codepoints to point it's output; this is at odds with non-utf8 charsets and leads to GHC crashing with <stdout>: commitBuffer: invalid argument (invalid character) This change sets the stdout/stderr encoding to utf8 prior to running hedgehog tests via the `runTests` function. The relevant hedgehog issue is hedgehogqa/haskell-hedgehog#110
We have to work around some encoding issue on certain environments. There's some issue with `hedgehog` tests and the encoding of STDOUT/STDERR: hedgehogqa/haskell-hedgehog#110. It's not really clear why this is always a problem with Haskell, nor is it really important. The only thing that matters if that we have to mess around with encodings in order to get things to work. The `Hedgehog.Main.defaultMain` seems like it should take care of this stuff, but it only messes with the buffering, not the encoding. In any case, we set the encoding so we can get these tests passing in other environments.
|
Thanks! Good to know that. |
Hedgehog uses Unicode's _check mark_ and _cross mark_ characters when presenting test results. Haskell is searching for system locale settings when writing text to a console and it crashes if the console encoding differs from the expected one [1]. As Hedgehog uses Unicode characters, it causes the exact issue [2]. Nix's locale default encoding is, apparently, non-compliant with UTF-8. This fix sets UTF-8 encoding explicitly, allowing Nix to run tests and build the whole derivation. [1] https://serokell.io/blog/haskell-with-utf8#haskell-defaults [2] hedgehogqa/haskell-hedgehog#110
One can arrive at this issue when running from
or to different appropriate path [see links ^]. |
I've seen this on two projects now. I'm not sure if it's a problem with stack, my terminal, or hedgehog - but let's start the discussion here:
Yet running the binary directly works fine.
The text was updated successfully, but these errors were encountered: