1

I'm new to C++, and am developing for Arduino with PlatformIO & VS Code on MacOS 11.6.5.

Following the PlatformIO docs I have set up a simple test like this:

#include <unity.h>
#include <iostream>

void test_something()
{
    std::cout << "Test running..." << std::endl;
    TEST_ASSERT_TRUE(true);
}

int main(int argc, char **argv)
{
    UNITY_BEGIN();
    RUN_TEST(test_something);
    UNITY_END();
}

When I run platformio test --environment local I see the test results in the terminal, but not the output of std::cout.

(I found an example of printing to cout from tests when not using PlatformIO, and the PlatformIO repo has lots of test examples, but none of these seem to involve cout.)

Also VS Code IntelliSense complains 'cannot open source file "iostream"', but I'm guessing this is unrelated as PlatformIO seems to have no problems compiling it.

Any pointers appreciated!

Derek Hill
  • 5,965
  • 5
  • 55
  • 74
  • Check out what those (I guess) macros resolve to. That should give you the code and get you started. – Ulrich Eckhardt May 28 '22 at 10:35
  • Thanks @UlrichEckhardt. That helped me dig into the https://github.com/ThrowTheSwitch/Unity source and find out what was going on. Essentially I just need to specify `--verbose`. Appreciate your help! – Derek Hill May 28 '22 at 18:37

1 Answers1

1

Ok, thanks to @Ulrich Eckhardt's help it turns out I just needed to specify --verbose mode for Unity i.e.:

platformio test --environment local --verbose

Then there are a whole bunch of ways to write to the terminal:

cout << "Hello" << endl;
cout << "Hello\n";
fprintf(stdout, "Hello");
putchar('a');

There are also Unity print methods, not sure of the pros & cons of these:

UnityPrint("Hello");
UnityPrintLen("Print this, but not this", 10);
UNITY_OUTPUT_CHAR('a');
Derek Hill
  • 5,965
  • 5
  • 55
  • 74