BetterConsoleTables icon indicating copy to clipboard operation
BetterConsoleTables copied to clipboard

Weird quirck

Open atari-monk opened this issue 3 years ago • 8 comments

Hi @douglasg14b

I found somethig weird in my testing I compare table printout to expected string in my integration test. When i run test from Visual Studio all is fine. When i run test in dotnet test cli command it sqrews up printout. Speciffically it adds whitespaces and test failes ┌──────┬───────────┐
│ [38;2;250;250;210m Id [0m │ [38;2;0;128;0m Name [0m │ ├──────┼───────────┤
│ [38;2;250;250;210m1291[0m │ [38;2;0;128;0mChristine[0m │ └──────┴───────────┘
Look at the space after ┌──────┬───────────┐ There id plenty of whitespaces there. They show up only when test is run thrue dotnet test Can you comment that ?

atari-monk avatar Aug 22 '22 10:08 atari-monk

I cleaned this up in test so it can pass just letting you know about it if u didnt encoutered it

atari-monk avatar Aug 22 '22 10:08 atari-monk

Can you provide a formatted (three backticks, code block) example of the output for the VS run and the dotnet cli run for comparison?

douglasg14b avatar Aug 22 '22 15:08 douglasg14b

Sorry i dont know this formating thing. This is output to txt file from VSCode run test VSCode-RunAllTests.zip This is output from dotnet test Dotnet test.zip I use notepad++ with endline switch on or this https://www.diffchecker.com/. To compare it. My test table looks like this

[17:57:14 INF] Read Item
┌──────┬───────────┐
│  Id  │    Name   │
├──────┼───────────┤
│ 1639 │ Christine │
└──────┴───────────┘

I add code like this, to clean white spaces so test will pass

var linesOut = outputText!.Split(EOL).ToList();
        var length = linesOut[0].IndexOf("┐") + 1;
        linesOut[0] = linesOut[0].Substring(0, length);
        linesOut[2] = linesOut[2].Substring(0, length);
        linesOut[4] = linesOut[4].Substring(0, length);
        PrintToFile(expected, linesOut);
        outputText = string.Join(EOL, linesOut);
        Assert.Equal(expected, outputText);

Not a big deal, still learning to use this lib.

atari-monk avatar Aug 22 '22 16:08 atari-monk

Looks like they are different

VSCode RunAllTests:

  • Expected: 839dc8c1e298ab9b30b90fe0ef018859deb7dfb2b8aee18f502dc8ffb4ee354d
  • Actual: 839dc8c1e298ab9b30b90fe0ef018859deb7dfb2b8aee18f502dc8ffb4ee354d

Dotnet Test

  • Expected: cf64b2fefc18c9464e1aaddf82ef4b90bb7a938722a57e9c54911d836ea979fd
  • Actual: fe4b8563de8560584489246a53ddf4d0cfe66637a7fdd7053e8d7abceaadbcd9

Are either of these being ran in a terminal or with a console available at runtime, or are they being ran headless?

The dotnet test one is padding the end of the output with whitespace, which is behavior I would expect if Console is available at runtime.

douglasg14b avatar Aug 22 '22 16:08 douglasg14b

sorry i dont know I just use Link in class test to run tests from VSCode and in VSCode terminal i type dotnet test to run theese. i dont know how this affects stuff. I also use CommandDotNet lib It was just something weird for me so i wanted to show it to better coder. I'am implementing rest of the columns and it;s not a problem.

atari-monk avatar Aug 22 '22 16:08 atari-monk

Unfortunately I would need to know if Console is available to further help debug this and/or a repro that I can run.

You can test this by asserting if the console is or is not available during your tests.

douglasg14b avatar Aug 29 '22 15:08 douglasg14b

Code is in my repos (inventory-min-cli-app), it's difficult to build thow since it consists of many separate projects. I dont know how to assert this. Will google this.

atari-monk avatar Aug 29 '22 19:08 atari-monk

You can see how I'm checking for the console here:

https://github.com/douglasg14b/BetterConsoleTables/blob/020fbe1c402760353277d560c3daf062f8be7a70/BetterConsoles.Tables/Common/PlatformInfo.cs#L66

This can throw an exception, so wrap in try/catch block. Exception probably means no console available, that's what I assume anyways.

You can always assign this to a variable, debug your tests, and see if that variable is true/false.

douglasg14b avatar Aug 29 '22 22:08 douglasg14b

Do you still need he;p with this problem?

douglasg14b avatar Jan 10 '23 19:01 douglasg14b

No i dont. It worked then in 2022. Probably still works. Not using this app at the moment. I like library. It works fine for me. You can close, thx.

atari-monk avatar Jan 10 '23 20:01 atari-monk