atilaneves / unit-threaded

Advanced unit test framework for D
BSD 3-Clause "New" or "Revised" License
122 stars 38 forks source link

Implement BDD/Gherkin style output. #271

Closed FeepingCreature closed 2 years ago

FeepingCreature commented 2 years ago

Annotate your tests with given/when/then steps. Failing steps will be shown in red; successful steps in green.

The goal of this PR is to imitate the output of Python's behave or Node's cucumber.js.

However, instead of defining a library of steps that a feature file is parsed from, it merely adds a set of functions that generate given/when/then lines in the output.

This is (relatively) isolated to its own module behave.d, which defines a stateful output class that keeps track of what the last step was, and erases it (with ANSI codes) if non-behave output is required.

There is also a hefty refactoring of ANSI formatting that replaces the string-based codes with a token stream. The reason for this is that it is otherwise awkward to "turn (intense) formatting back off", because you need to know which format codes are "on" at that point.

Example from some internal code I used to try it:

import unit_threaded.behave;
...
unittest {
    ...
    then("an `expected track change` is published");
    int i; assert(i > 0);

Screenshot_20220809_161517

FeepingCreature commented 2 years ago

Staring at the Wikipedia page on ANSI, I just noticed that you can turn intense SGR back off without erasing the foreground color. That would be a lot easier... I'll change that tomorrow.

atilaneves commented 2 years ago

There is also a hefty refactoring of ANSI formatting

That should be its own PR.

FeepingCreature commented 2 years ago

I'll remove it tomorrow anyhow.

FeepingCreature commented 2 years ago

Alright, ansi.d is gone, now the change in ansi formatting is limited to changing escCodes a bit and adding gray and intense effects. Do you still want it in a separate PR?

FeepingCreature commented 2 years ago

hooray!