haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
663 stars 96 forks source link

Unexpected output format in VSCode terminal #331

Open markpattison opened 5 years ago

markpattison commented 5 years ago

Using VSCode 1.35.1 on Windows 7 with Ionide 4.0.0.

The same issue happens with cmd or powershell terminal options.

To reproduce:

dotnet new -i Expecto.Template::*
dotnet new expecto -n exp
dotnet restore
dotnet run

Actual output (sample):

←[30;1mExpecto Running... ←[1000D←[0m←[?25l←[30;1mExpecto Running... ←[1000D←[0m←[?25l←[30;1mExpecto Running... 3/8 /←[1000D←[0m←[?25l                        ←[1000D←[?25h←[37m[←[37m16:05:35 ←[37mINF←[37m] ←[37mEXPECTO? Running tests...←[37m ←[37m<←[37mExpecto←[37m>←[37m
←[0m←[37m[←[37m16:05:35 ←[31mERR←[37m] ←[36msamples/I'm always fail (should fail)←[37m failed in ←[32m00:00:00.0110000←[37m. ←[36m
This was expected...
   at Tests.tests@19-3.Invoke(Unit _arg4) in E:\Prog\Source\test\Sample.fs:line 20
   at Expecto.Impl.execTestAsync@935-1.Invoke(Unit unitVar) in C:\Users\Anthony Lloyd\src\expecto\Expecto\Expecto.fs:line 939
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2)
   at <StartupCode$FSharp-Core>.$Async.StartChild@1641-5.Invoke(AsyncActivation`1 ctxt)
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction)←[37m ←[37m<←[37mExpecto←[37m>←[37m
←[0m←[37m[←[37m16:05:35 ←[31mERR←[37m] ←[36msamples/when true is not (should fail)←[37m failed in ←[32m00:00:00.0110000←[37m. ←[36m
I should fail because the subject is false. Actual value was false but had expected it to be true.
   at Tests.tests@12-1.Invoke(Unit _arg2) in E:\Prog\Source\test\Sample.fs:line 14
   at Expecto.Impl.execTestAsync@935-1.Invoke(Unit unitVar) in C:\Users\Anthony Lloyd\src\expecto\Expecto\Expecto.fs:line 939
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2)
   at <StartupCode$FSharp-Core>.$Async.StartChild@1641-5.Invoke(AsyncActivation`1 ctxt)
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction)←[37m ←[37m<←[37mExpecto←[37m>←[37m
←[0m←[37m[←[37m16:05:35 ←[31mERR←[37m] ←[36msamples/contains things (should fail)←[37m failed in ←[32m00:00:00.0350000←[37m. ←[36m

Expected output:

Something like this.

AnthonyLloyd commented 5 years ago

It looks like the terminal isn't supporting colours for some reason. Not sure why maybe a Windows 7 thing? To work around set --colours 0.

markpattison commented 5 years ago

The terminal colours do work from FAKE though...

AnthonyLloyd commented 5 years ago

It must not support ANSI colours and FAKE is using Console.ForegroundColor instead.

Colours are a bit of a pain to support and why we had to put in the --colours option. We could put in and option to use Console colours but they are not atomic and end up with bugs were the colour isn't reset correctly at the end.

haf commented 5 years ago

I would much prefer the check if it's a TTY or "is this Windows", or even "is this running on a super-old Windows". But I don't believe in mutilating the output of this library just so that a decade old operating system can avoid the above issues; especially since you @markpattison could install ANSI colours https://github.com/adoxa/ansicon and have it working.

haf commented 5 years ago

See https://github.com/haf/expecto/issues/315 for more discussions.

AnthonyLloyd commented 5 years ago

@haf It's such a mess and so difficult to test. I fear checking TTY takes us further down the rabbit hole. It would be good to have a solid example of covering multiple platforms and consoles.

haf commented 5 years ago

@AnthonyLloyd Perhaps then we start with https://docs.microsoft.com/en-us/dotnet/api/system.operatingsystem?view=netframework-4.8 ? Windows can default to 0 colours, otherwise 256?

Lanayx commented 5 years ago

Same issue in full Visual Studio plugin, makes it unusable :( image

AnthonyLloyd commented 5 years ago

@Lanayx use --colours 0 if that's possible via the plugin

Lanayx commented 5 years ago

@AnthonyLloyd Unfortunately there is no such option there

Lanayx commented 5 years ago

By the way, I have the same issue as topic starter when running dotnet test on windows 10 in regular console UPD: Also tried dotnet test -- --colours 0 , no effect

AnthonyLloyd commented 4 years ago

@Lanayx I think you need to raise with adamchester/expecto-adapter maybe they should offer config or just set to --colours 0 if VS doesn't support colours. For dotnet test it would be YoloDev/YoloDev.Expecto.TestSdk.

Michael-McD commented 4 years ago

There's also a stacktrace from Expecto itself that make it difficult to read. E.g.:

  at Expecto.Impl.execTestAsync@692-1.Invoke(Unit unitVar)
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 398
   at <StartupCode$FSharp-Core>.$Async.StartChild@1650-5.Invoke(AsyncActivation`1 ctxt) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 1650
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 109
rajee-a commented 3 years ago

As mentaioned by @haf https://github.com/haf/expecto/issues/331#issuecomment-507163272 ANSICON working fine for me.

To Setup ANSICON:

  1. Download ANSICON
  2. Then rename the folder to ANSICON and move it to C:\
  3. Modify the following in VSCode settings:
{
    ....

     "terminal.integrated.shell.windows": "C:\\Program Files\\ANSICON\\x64\\ansicon.exe",
     "terminal.integrated.shellArgs.windows": [
         "C:\\Program Files\\Git\\bin\\sh.exe",
         "--login",
         "-i"
     ]

}