Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging not Working for me #227

Closed
Milerius opened this issue Apr 22, 2019 · 6 comments
Closed

Logging not Working for me #227

Milerius opened this issue Apr 22, 2019 · 6 comments

Comments

@Milerius
Copy link

Milerius commented Apr 22, 2019

Description

Write a simple log inside a test:

TEST_CASE ("asset_path not empty")
{
      INFO("hello"); //! print nothing
      auto result = nephtys::client::details::assets_real_path().string();
      INFO("appimage asset real path: " << result); //! print nothing
      CHECK_FALSE(result.empty());
}

Steps to reproduce

Write a simple test with logging

Extra information

  • doctest version: 2.3.1 (through conan)
  • Operating System: Linux
  • Compiler+version: gcc-8/gcc-9/clang-8 Linux
@Milerius
Copy link
Author

image

@Milerius
Copy link
Author

Even with the unit test from the source code nothing appear:

static int someTests() {
  int some_var = 42;
  INFO("lots of captures - some on heap: " << some_var << " " << some_var << " " << some_var << ";");
      FAIL_CHECK("forcing the many captures (including those on the heap) to be stringified");
  return some_var;
}

TEST_CASE("a test case that will end from an exception") {
  int some_var = someTests();
  INFO("someTests() returned: " << some_var); // note that we have to use a local variable - cannot pass a temporary
  INFO("this should be printed if an exception is thrown even if no assert has failed: " << some_var);
  {
    INFO("in a nested scope this should be printed as well: " << some_var);
    {
      INFO("this should not be printed");
      CAPTURE(some_var);
    }

        CHECK_MESSAGE(some_var == 666, "why is this not 666 ?!");
  }
}

@onqtam
Copy link
Member

onqtam commented Apr 22, 2019

logged context with INFO is shown only if an assert fails. In your first example it seems that the assert is successful - note that it isn't checking for a true condition, but for a false one - meaning that .empty() probably returns false, and since you are using a <TYPE_OF_ASSERT>_FALSE(expr) assert it would be a success if the expression evaluates to false (in contrast to the standard <TYPE_OF_ASSERT>(expr)).
Perhaps I should improve the documentation for _FALSE asserts .

As for the second example - I do get output and it looks like this (precisely what I would expect):

[doctest] doctest version is "2.3.1"
[doctest] run with "--help" for options
====================================================================
D:\doctest\scripts\playground\test.cpp(16):
TEST CASE:  a test case that will end from an exception

D:\doctest\scripts\playground\test.cpp(12): ERROR: forcing the many captures (including those on the heap) to be stringified
  logged: lots of captures - some on heap: 42 42 42;

D:\doctest\scripts\playground\test.cpp(27): ERROR: CHECK( some_var == 666 ) is NOT correct!
  values: CHECK( 42 == 666 )
  logged: someTests() returned: 42
          this should be printed if an exception is thrown even if no assert has failed: 42
          in a nested scope this should be printed as well: 42
          why is this not 666 ?!

====================================================================
[doctest] test cases:      1 |      0 passed |      1 failed |      0 skipped
[doctest] assertions:      2 |      0 passed |      2 failed |
[doctest] Status: FAILURE!

So... are you sure you aren't executing the binary from the second example with -tc="asset_path not empty" (like the first example)? Because the test is named "a test case that will end from an exception".

@Milerius
Copy link
Author

I just misunderstood the context, I think it's was permanent logging, I want a permanent logging for each run !

@onqtam
Copy link
Member

onqtam commented Apr 22, 2019

In that case you should make use of MESSAGE() - let me know if that is what you need.

@Milerius
Copy link
Author

Perfect, thank's a lot, the documentation was not evident for me !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants