Skip to content

Commit

Permalink
🆕 🎨 [core] Support for tagging tests
Browse files Browse the repository at this point in the history
Problem:
- Only skip tag is supported but the concept is more generic than that.
- Pipe operator is using for skipping tests which is also used for parameterized tests.

Solution:
- Add support for multiple, different tagging with `tag(name)`.
- Replace `|` with `>>` for tagging.
- Make skip just a `tag("skip")`.
  • Loading branch information
kris-jusiak authored and krzysztof-jusiak committed Jun 15, 2020
1 parent 9590225 commit c6c6975
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 67 deletions.
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Sounds intriguing/interesting? Learn more at
* Macro-free ([How does it work?](#how-it-works))
* Easy to use ([Minimal API](#api) - `test, suite, operators, literals, [expect]`)
* Fast to compile/execute ([Benchmarks](#benchmarks))
* Features ([Assertions](example/expect.cpp), [Suites](example/suite.cpp), [Tests](example/skip.cpp), [Sections](example/section.cpp), [Parameterized](example/parameterized.cpp), [BDD](example/BDD.cpp), [Gherkin](example/gherkin.cpp), [Spec](example/spec.cpp), [Matchers](example/matcher.cpp), [Logging](example/log.cpp), [Runners](example/cfg/runner.cpp), [Reporters](example/cfg/reporter.cpp), [...](example))
* Features ([Assertions](example/expect.cpp), [Suites](example/suite.cpp), [Tests](example/test.cpp), [Sections](example/section.cpp), [Parameterized](example/parameterized.cpp), [BDD](example/BDD.cpp), [Gherkin](example/gherkin.cpp), [Spec](example/spec.cpp), [Matchers](example/matcher.cpp), [Logging](example/log.cpp), [Runners](example/cfg/runner.cpp), [Reporters](example/cfg/reporter.cpp), [...](example))
* Integrations ([ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp/releases/tag/v.7.0.0))

> `*` - Limitations may apply
Expand Down Expand Up @@ -631,15 +631,15 @@ asserts: 24 | 22 passed | 2 failed
<details open><summary>&nbsp;&nbsp;&nbsp;&nbsp;Tests</summary>
<p>

<details open><summary>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Run/Skip</summary>
<details open><summary>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Run/Skip/Tag</summary>
<p>

```cpp
"run UDL"_test = [] {
expect(42_i == 42);
};

skip | "don't run UDL"_test = [] {
skip >> "don't run UDL"_test = [] {
expect(42_i == 43) << "should not fire!";
};
```
Expand All @@ -654,7 +654,7 @@ test("run function") = [] {
expect(42_i == 42);
};

skip | test("don't run function") = [] {
skip >> test("don't run function") = [] {
expect(42_i == 43) << "should not fire!";
};
```
Expand All @@ -664,7 +664,28 @@ All tests passed (1 asserts in 1 tests)
1 tests skipped
```
> https://godbolt.org/z/2drJGq
```cpp
tag("nightly") >> tag("slow") >>
"performance"_test= [] {
expect(42_i == 42);
};
tag("slow") >>
"run slowly"_test= [] {
expect(42_i == 43) << "should not fire!";
};
```

```
cfg<override> = {.tag = {"nightly"}};
```

```
All tests passed (1 asserts in 1 tests)
1 tests skipped
```

> https://godbolt.org/z/X3_kG4
</p>
</details>
Expand Down Expand Up @@ -1189,13 +1210,19 @@ namespace boost::ut::inline v1_1_7 {
* @example "parameterized"_test = [](auto arg) {} | std::tuple{1, 2, 3};
*/
constexpr auto operator|;
/**
* Creates tags
* @example tag("slow") >> tag("nightly") >> "perf"_test = []{};
*/
constexpr auto operator>>;
} // namespace operators
/**
* Creates skippable test object
* @example skip | "don't run"_test = [] { };
* @example skip >> "don't run"_test = [] { };
*/
struct { } skip{};
constexpr auto skip = tag("skip");
struct {
/**
Expand Down
2 changes: 2 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ example(should should)
example(skip skip)
example(spec spec)
example(suite suite)
example(tag tag)
example(terse terse)
example(test _test)
example(tmp tmp)
Expand All @@ -80,6 +81,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
example(expect expect_cpp17)
example(test test_cpp17)
example(suite suite_cpp17)
example(tag tag_cpp17)
example(terse terse_cpp17)
example(section section_cpp17)
example(should should_cpp17)
Expand Down
8 changes: 4 additions & 4 deletions example/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
namespace benchmark {
struct benchmark : boost::ut::detail::test {
template <class TName>
constexpr explicit benchmark(const TName& name)
explicit benchmark(const TName& name)
: boost::ut::detail::test{"benchmark", name} {}

template <class Test>
constexpr auto operator=(Test test) {
auto operator=(Test test) {
static_cast<boost::ut::detail::test&>(*this) = [&test, this] {
const auto start = std::chrono::high_resolution_clock::now();
test();
Expand All @@ -29,8 +29,8 @@ struct benchmark : boost::ut::detail::test {
}
};

[[nodiscard]] constexpr auto operator""_benchmark(const char* name,
decltype(sizeof("")) size) {
[[nodiscard]] auto operator""_benchmark(const char* name,
decltype(sizeof("")) size) {
return ::benchmark::benchmark{boost::ut::utility::string_view{name, size}};
}

Expand Down
7 changes: 5 additions & 2 deletions example/skip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
int main() {
using namespace boost::ut;

skip | "don't run"_test = [] {
// clang-format off
skip >>
"don't run"_test = [] {
expect(42_i == 43) << "should not fire!";
expect(false) << "should fail!";
};

skip | test("don't run") = [] {
skip >> test("don't run") = [] {
expect(42_i == 43) << "should not fire!";
expect(false) << "should fail!";
};
// clang-format on
}
35 changes: 35 additions & 0 deletions example/tag.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright (c) 2019-2020 Kris Jusiak (kris at jusiak dot net)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/ut.hpp>

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

cfg<override> = {.filter = "tag", .tag = {"execute"}};

// clang-format off
tag("execute") >> skip >>
"tag"_test = [] {
expect(42_i == 43) << "should not fire!";
expect(false) << "should fail!";
};

tag("execute") >> "tag"_test= [] {
expect(42_i == 42);
};

tag("not executed") >> "tag"_test= [] {
expect(43_i == 42);
};

tag("not executed") >> tag("execute") >>
"tag"_test= [] {
expect(42_i == 42);
};
// clang-format on
}

0 comments on commit c6c6975

Please sign in to comment.