Coder Social home page Coder Social logo

Comments (2)

horenmar avatar horenmar commented on June 7, 2024

Some design notes for this

  • There should be a new listener event for generators.
  • To simplify the work to create a custom reporter, we should be sending paired start ... end events. This enables reporters to keep track of active generators without having to do the bookkeeping of tracking each generator's parent section.
    • The name generatorStarting is symmetric with the existing events, and also terrible, because it does not match the actual semantics of GENERATE. generatorEnded is even worse.
    • Current consideration: generatorActivated ... generatorDeactivated.
  • The starting event should be sent whenever we visit an expression with GENERATE in it.
    • The ending event can only be sent when the parent section's tracker is closing. We have to ensure that the generator trackers emit the ending events in the proper LIFO order.
  • The starting event should pass either the generator interface, or something similar, that allows both getting the index of the current element in the generator, and getting the string representation of that element.
    • The ending event should not send these, as the generator might no longer be valid when the event is fired. Or we have to codify the semantics that the event is always sent before the generator can be deallocated, and make it clear that the generator-interface-pointer should never ever be stored.
    • We should also consider sending in the "index" of the generator that is (de)activated. It is not important, but it might simplify some things... but users will have to maintain their own stack anyway, maybe it is not worth it?
    • Unlike sections, generators do not have user-facing names, so we cannot use those.
  • We want to keep backwards compatibility with the existing -c, --section path filtering. To avoid overcomplicating the CLI option, we will support two exclusive path specification modes, so the users can either use -c ... as they do now, or they can use -p, --path in the future, but not both at the same time.
    • The --path specifier will accept compound arguments, such as --path g:2 or --path c:"foo bar" for generator index or section name respectively.
      • Should we use 'c' or 's' (or both) for the section filter? 'c' is consistent with -c argument, -s makes more sense. We can also use both, but that risks user confusion.
      • Should we also allow long names, so that g:2 and generator:2 are equivalent? Also should the long names be fully explicit, e.g. generator-index:2, section-name:"foo bar"?

Example event semantics

This sample test case

TEST_CASE() {
    SECTION("A") { ... }
    auto _ = GENERATE(...);
    SECTION("B") { ... }
}

should emit

testCaseStarting
  testCasePartialStarting -> #0
    sectionStarting -> "test"
      sectionStarting -> "A"
      sectionEnded -> "A"
      generatorActivated
      generatorDeactivated
    sectionEnded -> "test"
  testCasePartialEnded -> #0
  testCasePartialStarting -> #1
    sectionStarting -> "test"
      generatorActivated
        sectionStarting -> "B"
        sectionEnded -> "B"
      generatorDeactivated
    sectionEnded -> "test"
  testCasePartialEnded -> #1
  ... repeated for each generator element ...
testCaseEnded

from catch2.

mjerabek avatar mjerabek commented on June 7, 2024

Also, we may want something like

auto foo = NAMED_GENERATE("foo", ...);

for avoiding common patterns

auto foo = GENERATE(...);
CAPTURE(foo);

This will also present the generator name to reporters, so that in cases when we are generating something that we care to be named, we will see a reasonable name there.

from catch2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.