5

I use GoogleTest extensively and the output in the cosole looks like this:

GoogleTest console output

When I run the same from within Eclipse (using Eclipse Mars latest as of today) I get the following output with no colors and junk characters (are not visible just pasting the output here):

Running main() from gtest_main.cc
[0;32m[==========] [mRunning 3 tests from 1 test case.
[0;32m[----------] [mGlobal test environment set-up.
[0;32m[----------] [m3 tests from NloptAdapterSuite
[0;32m[ RUN      ] [mNloptAdapterSuite.testQuadraticFunction1
[0;32m[       OK ] [mNloptAdapterSuite.testQuadraticFunction1 (1 ms)
[0;32m[ RUN      ] [mNloptAdapterSuite.testQuadraticFunction1WithNoise
[0;32m[       OK ]     [mNloptAdapterSuite.testQuadraticFunction1WithNoise (1 ms)
[0;32m[ RUN      ] [mNloptAdapterSuite.testQuadraticFunction2
[0;32m[       OK ] [mNloptAdapterSuite.testQuadraticFunction2 (1 ms)
[0;32m[----------] [m3 tests from NloptAdapterSuite (3 ms total)

[0;32m[----------] [mGlobal test environment tear-down
[0;32m[==========] [m3 tests from 1 test case ran. (3 ms total)
[0;32m[  PASSED  ] [m3 tests.

How can this be fixed to have the same output?

SkyWalker
  • 13,729
  • 18
  • 91
  • 187
  • 4
    The 'junk' character are the ANSI commands to set console colors. The Eclipse console does not support these by default. There is at least [one plugin](http://marketplace.eclipse.org/content/ansi-escape-console) in the Eclipse Marketplace which claims to add this support. – greg-449 Jul 30 '15 at 09:05
  • Yes installing this ANSI escape in console plugin produces identical output as in the console. Thank you! Post as answer and will accept. – SkyWalker Jul 30 '15 at 09:27
  • Answers which are essentially just a link are not acceptable on SO. – greg-449 Jul 30 '15 at 09:31

1 Answers1

5

The ANSI Escape in Console plugin that greg-449 linked above worked great for me. After installing it, the gtest output looks like:

gtest console output

I'm on Neon.2 (Eclipse 4.6.2).

BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
  • 1
    I had to add `--gtest_color=yes` to my test binary arguments to get the color to display – donturner Sep 17 '17 at 10:36
  • @don - did you also need that when running from command line? – BeeOnRope Sep 17 '17 at 20:14
  • No. I am on OSX 10.12.6. Using the default terminal app the colors showed up fine without any extra command line arguments. – donturner Sep 18 '17 at 13:54
  • @donturner well, apparently googletest has code to detect if output is going to a terminal type that accepts colored output and disables it by default if that's not the case. Perhaps the detection in the Eclipse case is different on OSX or perhaps it changed everywhere due to a chnage to the terminal whitelist in newer versions of gtest. – BeeOnRope Sep 19 '17 at 00:32