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

[BUG]: Console output doesn't display correct test execution time #646

Open
proxict opened this issue Nov 24, 2024 · 0 comments
Open

[BUG]: Console output doesn't display correct test execution time #646

proxict opened this issue Nov 24, 2024 · 0 comments

Comments

@proxict
Copy link

proxict commented Nov 24, 2024

Perhaps I'm using this framework wrong, but I can't figure out how to display the execution time of each test case correctly.
According to the --help section, the -d switch should display the duration for each test, but that's not the case.

Expected Behavior

When ran with -d or --durations, the framework should display the execution time for each test.

Actual Behavior

The time is only reported for tests that are in a non-global suite.

Steps to Reproduce the Problem

  1. Compile to binary:
constexpr auto sum(auto... args) { return (args + ...); }

int main() {
    using namespace boost::ut;

    "sum2"_test = [] { expect(sum(1, 2) == 3_i); };

    suite<"sum_suite">([] {
        "sum3"_test = [] { expect(sum(1, 2, 3) == 6_i); };
        "sum4"_test = [] { expect(sum(1, 2, 3, 4) == 10_i); };
    });
}
  1. Execute the binary with -s -d command line arguments

https://godbolt.org/z/d5rfWjhTb

Also note the missing line-endings in the output.

Furthermore, when displayed, the execution time seems to be wrong. To get higher time reporting precision, I modified the internal print_duration() function to this:

void print_duration(auto& printer) const noexcept {
  if (detail::cfg::show_duration) {
    const auto test_duration = active_scope_->run_stop - active_scope_->run_start;

    printer << " after ";
    if (auto time = std::chrono::duration_cast<std::chrono::seconds>(test_duration); time.count() != 0) {
      printer << time;
      return;
    }

    if (auto time = std::chrono::duration_cast<std::chrono::milliseconds>(test_duration); time.count() != 0) {
      printer << time;
      return;
    }

    if (auto time = std::chrono::duration_cast<std::chrono::microseconds>(test_duration); time.count() != 0) {
      printer << time;
      return;
    }

    printer << std::chrono::duration_cast<std::chrono::nanoseconds>(test_duration);
  }
}

after which I've noticed the reported time was negative, suggesting there is maybe something wrong with the test_end events?

Specifications

  • Version: v.2.1.1
  • Platform: Arch Linux
  • GCC version: 14.2.1 20240910
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

1 participant