2

I am similar issue to expect script capturing garbage characters - need to remove. Logs and console output contain these ANSI escape sequences and messing up with the resulting output. It became difficult to understand what is going on in actual process. We are using Centos:7 and we are running dotnet test in a docker container. We are building and testing dotnet application. All the logs are visible and perfect but during dotnet test command we receive multiple garbage characters and it also messing up the result as well. It looks like these characters also contain something which makes logs to start from the start of terminal without clearing the old logs and that also messes up the logs.

output

Run test [sample_test]
Test Run Successful.ding projects
Total tests: 1
     Passed: 1
 Total time: 1.9039 Seconds
Installing trx2junit
You can invoke the tool using the following command: trx2junit
Tool 'trx2junit' (version '1.2.6') was successfully installed.
trx2junit (c) gfoidl -- v1.2.6sion 16.3.0+0f4c62fea for .NET Core
https://github.com/gfoidl/trx2junit. All rights reserved.

....
...

./build/xunit-results/sss.Test.trx
./build/xunit-results/junit-results/sss.Test.xml
~/testError(s)

Test done!ed 00:00:05.11
zzz:~/git/testproject$ ;1R;9R;1R;9R;1R;9R

........

Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.
Results File: /tmp/tmp.Lr3H7XaRyB/build/xunit-results/sss.Test.trx
^[[40;1R^[[40;9R

This issue is faced while running the dotnet test in the docker container with --tty or -t option. If we run the same dotnet test in the docker container with -it option it works perfectly fine without any unwanted characters.

I think some issue with the combination of dotnet test in docker container with --tty option.

Any help and suggestion would be appreciated.

pmunshi
  • 21
  • 4

1 Answers1

0

The solution I found for this problem was to pipe the output through tr to strip control characters:

# Strip control characters from output except `\t\n\r`.
dotnet test | tr -d '\000-\010\013\014\016-\037'

Copied from this SO comment: Removing Control Characters from a File. That thread has a number of other solutions to the same problem.