Skip to content

Commit 29a5ae0

Browse files
committed
clean up annotations and test
1 parent c0f4c94 commit 29a5ae0

File tree

8 files changed

+58
-82
lines changed

8 files changed

+58
-82
lines changed

include/rsl/testing/_testing_impl/annotations.hpp

Lines changed: 0 additions & 57 deletions
This file was deleted.

include/rsl/testing/_testing_impl/discovery.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#endif
1212

1313
#include <rsl/testing/test.hpp>
14+
#include <rsl/testing/annotations.hpp>
1415

1516
#include "fixture.hpp"
16-
#include "annotations.hpp"
1717
#include "util.hpp"
1818

1919
namespace rsl::testing::_testing_impl {

include/rsl/testing/_testing_impl/expand.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#include <rsl/repr>
1010
#include <rsl/testing/assert.hpp>
1111

12+
#include <rsl/testing/annotations.hpp>
1213
#include <rsl/testing/result.hpp>
1314

1415
#include "fixture.hpp"
15-
#include "annotations.hpp"
1616

1717
namespace rsl::testing::_testing_impl {
1818
template <std::meta::info R, std::meta::info Target>

include/rsl/testing/_testing_impl/factory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <meta>
66
#include <unordered_map>
77

8-
#include "annotations.hpp"
8+
#include <rsl/testing/annotations.hpp>
99

1010
namespace rsl::testing::_testing_impl {
1111
template <class Base, class... Args>

include/rsl/testing/_testing_impl/util.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <cstdint>
33
#include <string_view>
44
#include <meta>
5+
#include <algorithm>
56

67
namespace rsl::testing::_testing_impl {
78
template <bool V>

include/rsl/testing/all.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace rsl {
1313
using testing::fixture;
1414
using testing::fuzz;
15-
using testing::property_test;
1615
using testing::test;
1716

1817
using testing::params;

include/rsl/testing/annotations.hpp

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
#include <type_traits>
32
#include <vector>
43
#include <initializer_list>
54
#include <meta>
@@ -11,16 +10,15 @@
1110
#include "_testing_impl/util.hpp"
1211
#include "_testing_impl/paramset.hpp"
1312

14-
namespace rsl::testing {
1513

14+
namespace rsl::testing {
1615
using _testing_impl::ParamSet;
1716

1817
namespace annotations {
1918
struct FixtureTag {};
2019

2120
// test kinds
2221
struct TestTag {};
23-
struct PropertyTag : TestTag {};
2422
struct FuzzTag : TestTag {};
2523

2624
// flags
@@ -98,7 +96,6 @@ struct Params {
9896
constexpr inline annotations::FixtureTag fixture;
9997

10098
constexpr inline annotations::TestTag test;
101-
constexpr inline annotations::PropertyTag property_test;
10299
constexpr inline annotations::FuzzTag fuzz;
103100

104101
constexpr inline annotations::ExpectFailureTag expect_failure;
@@ -108,4 +105,48 @@ constexpr inline annotations::Rename rename;
108105

109106
using tparams = annotations::TParams;
110107
using params = annotations::Params;
111-
} // namespace rsl::testing
108+
109+
namespace _testing_impl {
110+
struct Annotations { // consteval-only
111+
rsl::span<ParamSet const> targets;
112+
rsl::span<annotations::Params const> params;
113+
114+
bool expect_failure = false;
115+
bool (*skip)() = nullptr; // this is a function to support conditional skipping
116+
rsl::string_view name; // custom base name
117+
bool is_fuzz_test = false;
118+
119+
consteval explicit Annotations(std::meta::info fnc) {
120+
std::vector<ParamSet> tp_sets;
121+
std::vector<annotations::Params> p;
122+
123+
for (auto annotation : annotations_of(fnc)) {
124+
auto type = remove_cvref(type_of(annotation));
125+
if (type == ^^annotations::TParams) {
126+
tp_sets.append_range(extract<annotations::TParams>(constant_of(annotation)).value);
127+
} else if (type == ^^annotations::Params) {
128+
p.push_back(extract<annotations::Params>(constant_of(annotation)));
129+
} else if (type == ^^annotations::ExpectFailureTag) {
130+
constexpr_assert(!expect_failure, "Cannot annotate with expect_failure more than once.");
131+
expect_failure = true;
132+
} else if (type == ^^annotations::Skip) {
133+
// constexpr_assert(skip == nullptr, "Cannot have more than one skip annotation.");
134+
skip = extract<annotations::Skip>(constant_of(annotation)).value;
135+
} else if (type == ^^annotations::Rename) {
136+
constexpr_assert(name.empty(), "Cannot rename more than once.");
137+
name = extract<annotations::Rename>(constant_of(annotation)).value;
138+
} else if (type == ^^annotations::FuzzTag) {
139+
is_fuzz_test = true;
140+
}
141+
}
142+
143+
targets = define_static_array(tp_sets);
144+
params = define_static_array(p);
145+
146+
if (skip == nullptr) {
147+
skip = &constant_predicate<false>;
148+
}
149+
}
150+
};
151+
} // namespace rsl::testing::_testing_impl
152+
}

include/rsl/testing/test.hpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@
22
#include <string>
33
#include <functional>
44
#include <meta>
5-
#include <ranges>
65
#include <iterator>
76
#include <deque>
8-
#include <set>
9-
#include <algorithm>
107

118
#include "result.hpp"
129

1310
#include "_testing_impl/util.hpp"
1411
#include "_testing_impl/expand.hpp"
15-
#include "_testing_impl/fixture.hpp"
16-
#include "_testing_impl/annotations.hpp"
1712

13+
#include <rsl/testing/annotations.hpp>
1814
#include <rsl/testing/assert.hpp>
1915

20-
2116
namespace rsl::testing {
2217
struct TestCase {
2318
class Test const* test;
@@ -49,22 +44,19 @@ class Test {
4944
std::string_view preferred_name; // from annotations
5045
std::span<char const* const> full_name; // fully qualified name
5146

52-
bool expect_failure; // invert test checking
53-
bool (*skip)(); // function to support conditional skipping
54-
bool is_property_test; // expand missing args as fixtures if false,
55-
// otherwise parameterize with domain
47+
bool expect_failure; // invert test checking
48+
bool (*skip)(); // function to support conditional skipping
5649
bool is_fuzz_test;
5750

5851
Test() = delete;
5952
consteval explicit Test(std::meta::info test, std::meta::info annotation_anchor)
6053
: sloc(source_location_of(test))
6154
, name(define_static_string(identifier_of(test))) {
62-
auto ann = _testing_impl::Annotations(annotation_anchor);
63-
preferred_name = ann.name;
64-
expect_failure = ann.expect_failure;
65-
skip = ann.skip;
66-
is_property_test = ann.is_property_test;
67-
is_fuzz_test = ann.is_fuzz_test;
55+
auto ann = _testing_impl::Annotations(annotation_anchor);
56+
preferred_name = ann.name;
57+
expect_failure = ann.expect_failure;
58+
skip = ann.skip;
59+
is_fuzz_test = ann.is_fuzz_test;
6860

6961
get_tests_impl = extract<runner_type>(
7062
substitute(^^expand_test, {reflect_constant(test), std::meta::reflect_constant(ann)}));

0 commit comments

Comments
 (0)