Skip to content

GENERATE macro causes assertion failure if used after a SECTION #1938

@sdutoit

Description

@sdutoit

Describe the bug

Using GENERATE after a SECTION causes an assertion failure on tracker.isOpen().

Expected behavior
The following code:

TEST_CASE("repro generator bug") {
  SECTION("foo") {}
  auto m = GENERATE(1);
}

runs cleanly.

Actual behavior

An assertion failure occurs during the GENERATE code:

repro: single_include/catch2/catch.hpp:12662: virtual Catch::IGeneratorTracker& Catch::RunContext::acquireGeneratorTracker(const Catch::SourceLineInfo&): Assertion `tracker.isOpen()' failed.

Commenting out the SECTION("foo") {} line causes the test to succeed.

Reproduction steps

$ cat repro.cc
#define CATCH_CONFIG_MAIN
#include "single_include/catch2/catch.hpp"
TEST_CASE("repro generator bug") {
  SECTION("foo") {}
  auto m = GENERATE(1);
}
$ g++-9 -std=c++17 -o repro repro.cc -g && ./repro
repro: single_include/catch2/catch.hpp:12662: virtual Catch::IGeneratorTracker& Catch::RunContext::acquireGeneratorTracker(const Catch::SourceLineInfo&): Assertion `tracker.isOpen()' failed.

Platform information:

  • OS: Linux 4.14.97
  • Compiler+version: gcc 9.2.1
  • Catch version: v2.12.2

Additional context
Not sure if this is expected to work (would be nice if it did though!), but if not, it would be great if the message was friendlier!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions