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

ReadMe sample code crashes at run-time #178

Closed
ploeh opened this issue Apr 14, 2018 · 21 comments
Closed

ReadMe sample code crashes at run-time #178

ploeh opened this issue Apr 14, 2018 · 21 comments

Comments

@ploeh
Copy link

ploeh commented Apr 14, 2018

I'm trying to follow the code examples in the ReadMe file, but it throws an exception at run time:

*Q49343774 Q49343774> tests
*** Exception: <stdout>: hPutChar: invalid argument (invalid character)

FWIW, I tried to simplify the file even further in order to troubleshoot if something else could be the matter:

{-# LANGUAGE TemplateHaskell #-}
module Q49343774 where

import Hedgehog

prop_reverse :: Property
prop_reverse =
  property $ do
    True === True

tests :: IO Bool
tests =
  checkParallel $$(discover)

foo :: () -> String
foo () = "foo"

The reason I included the foo function was that I wanted to verify that there isn't something fundamentally wrong with the file, such as a non-printable character that GHCi would choke on. That doesn't seem to be the case:

*Q49343774 Q49343774> foo ()
"foo"

My environment:

  • Operating System: Windows 10 Pro x64, Version 1709, Build 16299.371
  • Stack: 1.6.3
  • GHC: 8.2.2

Am I doing anything wrong? Is there something I can do to troubleshoot?

@moodmosaic
Copy link
Member

See #110 (comment) for a workaround.

@moodmosaic
Copy link
Member

I've originally reported this in #32, and the discussion continues in #110 (which shows at least two workarounds).

I haven't investigated further what might be causing this, since I've moved to *nix since then. Perhaps we should close this in favor of #110(?)

@ploeh
Copy link
Author

ploeh commented Apr 14, 2018

Well, now, at least, it runs, but pretty it isn't:

*Q49343774 Q49343774> :m +System.IO
*Q49343774 Q49343774 System.IO> hSetEncoding stdout utf8
*Q49343774 Q49343774 System.IO> hSetEncoding stderr utf8
*Q49343774 Q49343774 System.IO> tests
ΓöüΓöüΓöü Q49343774 ΓöüΓöüΓöü
  Γ£ô prop_reverse passed 100 tests.
  Γ£ô 1 succeeded.
True

@moodmosaic
Copy link
Member

moodmosaic commented Apr 14, 2018

Hmm, perhaps you may also try this workaround as well: #110 (comment), and I think we should close this in favor of #110.


FTR, I even tried using the Windows Subsystem for Linux, but there I noticed that stack was really slow, so I ended up using a real *nix virtual machine (Ubuntu and Debian so far).

@ploeh
Copy link
Author

ploeh commented Apr 15, 2018

Thank you for your help 👍

The workarounds enable me to get code running, but this hardly seems like a satisfactory solution. While I grant that there's small issues with QuickCheck tests on Windows as well (or, at least, on my system), they're nowhere near as conspicuous as these.

ATM, it's not clear to me at all why this problem exists, but if I can do something to help address it, I'd like to offer to spend a few hours doing so, but I'm going to need some guidance.

Whether you want to close this issue in favour of another I have no opinion. Feel free to close this issue if you feel the other one better captures the problem; I can't evaluate whether or not that's the case.

@thumphries
Copy link
Member

Yeah, nobody who works on Hedgehog uses Windows right now, so it is hard for us to resolve. We'd love for someone to spend time on it, though. We might be able to add the transliteration hack to the library (it's good enough for GHC) - or follow one of the other avenues in #110.

Closing in favour of #110, where the workarounds are collected.

@moodmosaic
Copy link
Member

Well, now, at least, it runs, but pretty it isn't:

*Q49343774 Q49343774> :m +System.IO
*Q49343774 Q49343774 System.IO> hSetEncoding stdout utf8
*Q49343774 Q49343774 System.IO> hSetEncoding stderr utf8
*Q49343774 Q49343774 System.IO> tests
ΓöüΓöüΓöü Q49343774 ΓöüΓöüΓöü
 Γ£ô prop_reverse passed 100 tests.
 Γ£ô 1 succeeded.
True

@ploeh, if you execute chcp 65001 in the console the output should be fine. See #110 (comment).

@ploeh
Copy link
Author

ploeh commented Jun 16, 2018

Thanks, but

$ chcp 65001
bash: chcp: command not found

@moodmosaic
Copy link
Member

Weird... Are you using the Windows Subsystem for Linux or just the Git Bash?

@moodmosaic
Copy link
Member

You should enter this in a regular command prompt (cmd.exe) since it's a Windows command, and then start Git Bash from there - - or just use ConEmu which takes care of all this.

@ploeh
Copy link
Author

ploeh commented Jun 16, 2018

Turns out that it's a .com file, not an .exe. It can be called by writing chcp.com instead of just chcp. It makes the output of the test better, although still not good:

image

@moodmosaic
Copy link
Member

Did you also set stdout/err encoding to UTF-8 as per #110 (comment)?

@ploeh
Copy link
Author

ploeh commented Jun 16, 2018

I've tried with and without. It makes no difference.

@moodmosaic
Copy link
Member

moodmosaic commented Jun 16, 2018

When I have to use Windows, I use the stable version of https://conemu.github.io

In the gif I posted, I'm using the latest stable version of ConEmu.

Perhaps ConEmu deals with UTF-8 far better than cmd.exe

(There are other benefits of using ConEmu anyway.)

@ploeh
Copy link
Author

ploeh commented Jun 16, 2018

I just tried in cmd instead of Bash. Same problem. I wonder if it's just my system that behaves strangely.

I'll try on another machine...

@moodmosaic
Copy link
Member

I wonder if it's the Danish locale (but I'm using the Greek locale so it shouldn't matter).

Still, I'd be curious to see what happens if you try running a Git Bash from inside ConEmu on that machine...

@ploeh
Copy link
Author

ploeh commented Jun 16, 2018

Perhaps ConEmu deals with UTF-8 far better than cmd.exe

Most likely. Git bash handles this quite poorly, so it's unlikely to get much worse, one could hope. For the last many months, I haven't had the mental bandwidth to look into new tooling, but for the next month or so, I hope that'll change. If so, this is high on my list of things to look at.

I wonder if it's the Danish locale

I wonder the same 😄

@ploeh
Copy link
Author

ploeh commented Jun 16, 2018

Tried all the above variations on another machine. Same result 😢

Those two machines aren't that different, though. For instance, both run Danish locale. In many ways, I try to keep them in sync with each other...

@moodmosaic
Copy link
Member

So when I'm on Windows, I run ConEmu, GHCi, and a code editor, like this:

haskell-hedgehog-issue-110-b-speed

Notice that I run chcp from inside GHCi via :! chcp 65001, because I spend almost all my time in GHCi, so even things like git, hoogle, etcetera I run them from inside GHCi as well (e.g. :! git status). 😅

@moodmosaic
Copy link
Member

moodmosaic commented Jun 20, 2018

Perhaps ConEmu deals with UTF-8 far better than cmd.exe

Most likely.

Indeed, the built-in Windows command prompt (cmd.exe) has issues with UTF-8. ConEmu works fine though:

image


FTR, I've tried this with a rather old, but battle-tested, stable, version of ConEmu, v16.12.06. For a long time, this was the recommended, stable, version on their website.

Perhaps, newer versions of ConEmu (and even Cmder which derives from ConEmu) will work fine as well. You may also try the Windows Subsystem for Linux, but IME it's still not there yet.

@moodmosaic
Copy link
Member

moodmosaic commented Jun 21, 2018

@ploeh, even more interesting news.

As an alternative to the built-in Windows command prompt (cmd.exe), ConEmu and Cmder, one can simply use the terminal inside VSCode by setting it to a Git Bash:

image

moodmosaic added a commit to moodmosaic/haskell-hedgehog that referenced this issue Aug 20, 2018
moodmosaic added a commit to moodmosaic/haskell-hedgehog that referenced this issue Aug 21, 2018
erikd pushed a commit to erikd/haskell-hedgehog that referenced this issue Mar 2, 2020
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

3 participants