douglasg14b / BetterConsoleTables

Faster, colorable, more configurable, and more robust console colors & tables for C# console applications
GNU Lesser General Public License v3.0
92 stars 16 forks source link

Weird quirck #31

Closed atari-monk closed 1 year ago

atari-monk commented 2 years ago

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 ┌──────┬───────────┐
│  Id  │  Name  │ ├──────┼───────────┤
│ 1291 │ Christine │ └──────┴───────────┘
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 commented 2 years ago

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

douglasg14b commented 2 years ago

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

atari-monk commented 2 years ago

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.

douglasg14b commented 2 years ago

Looks like they are different

VSCode RunAllTests:

Dotnet Test

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.

atari-monk commented 2 years ago

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.

douglasg14b commented 2 years ago

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.

atari-monk commented 2 years ago

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.

douglasg14b commented 2 years ago

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 commented 1 year ago

Do you still need he;p with this problem?

atari-monk commented 1 year ago

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.