Skip to content

Commit a009545

Browse files
committed
refactor test structure, implement annotation surrogates, implement skip, prepare for property testing and fuzz testing
1 parent cf7026f commit a009545

File tree

20 files changed

+483
-317
lines changed

20 files changed

+483
-317
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ target_link_libraries(rsltest_main PUBLIC rsltest)
2626

2727
find_package(rsl-config REQUIRED)
2828
find_package(rsl-serialize REQUIRED)
29+
find_package(rsl-assert REQUIRED)
2930

31+
target_link_libraries(rsltest PUBLIC rsl::assert)
3032
target_link_libraries(rsltest PUBLIC rsl::config)
3133
target_link_libraries(rsltest PUBLIC rsl::serialize)
3234

conanfile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def requirements(self):
4040
self.requires("libassert/2.1.5", transitive_headers=True, transitive_libs=True)
4141
self.requires("rsl-config/0.1", transitive_headers=False, transitive_libs=True)
4242
self.requires("rsl-serialize/0.1", transitive_headers=False, transitive_libs=True)
43-
43+
self.requires("rsl-assert/0.1", transitive_headers=True, transitive_libs=True)
44+
4445
def layout(self):
4546
cmake_layout(self)
4647

@@ -67,6 +68,7 @@ def package(self):
6768
cmake.install()
6869

6970
def package_info(self):
71+
self.cpp_info.set_property("cmake_file_name", "rsl-test")
7072
self.cpp_info.components["test"].set_property("cmake_target_name", "rsl::test")
7173
self.cpp_info.components["test"].includedirs = ["include"]
7274
self.cpp_info.components["test"].libdirs = ["lib"]
@@ -76,7 +78,7 @@ def package_info(self):
7678
self.cpp_info.components["test_main"].set_property("cmake_target_name", "rsl::test_main")
7779
self.cpp_info.components["test_main"].includedirs = ["include"]
7880
self.cpp_info.components["test_main"].libdirs = ["lib"]
79-
self.cpp_info.components["test_main"].requires = ["test", "rsl-config::config", "rsl-serialize::serialize"] # depend on primary component
81+
self.cpp_info.components["test_main"].requires = ["test", "rsl-config::config", "rsl-serialize::serialize", "rsl-assert::assert"] # depend on primary component
8082
self.cpp_info.components["test_main"].libs = ["rsltest_main"]
8183

8284

example/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ target_sources(example_test PRIVATE
33
tparams.cpp
44
params.cpp
55
fixtures.cpp
6-
)
6+
)
7+
8+
add_executable(params_debug params_debug.cpp)
9+
target_link_libraries(params_debug PUBLIC rsltest)

example/always_passes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ void always_passes() {
1111
void always_fails() {
1212
ASSERT(false, "oh no");
1313
}
14-
} // namespace testing
14+
} // namespace testing

example/params.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ std::vector<std::tuple<char, int>> make_params() {
88
}
99

1010
[[=rsl::test]]
11-
[[=rsl::params({std::tuple{'a', 10}, {'c', 12}})]]
12-
[[=rsl::params(rsl::cartesian_product({'a', 'c'}, {10, 15, 20}))]]
11+
[[=rsl::params({{'a', 10}, {'c', 12}})]]
12+
// [[=rsl::params(rsl::cartesian_product({'a', 'c'}, {10, 15, 20}))]]
1313
[[=rsl::params(make_params)]]
1414
void test_with_params(char foo, int bar){
1515
ASSERT(bar > 5);

example/params_debug.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <rsl/testing/all.hpp>
2+
#include <iostream>
3+
4+
std::vector<std::tuple<int, char>> bar() { return {{42, 'd'}, {2, 'c'}}; }
5+
6+
consteval std::vector<rsl::testing::ParamSet> foo() { return {{42, '3'}}; }
7+
8+
[[= rsl::tparams{{^^int, 3}}]]
9+
[[= rsl::params{foo}]]
10+
constexpr static auto test =
11+
[]
12+
<typename T, int V>
13+
(int, char) static { };
14+
15+
namespace Zoinks {
16+
template <typename T, int V>
17+
void foo(int, char) {
18+
std::cout << "\ntest\n";
19+
}
20+
}
21+
22+
23+
24+
25+
int main() {
26+
// auto runs = expand_test<^^Zoinks::foo, ^^test>();
27+
// std::cout << '\n' << runs.size();
28+
// for (auto r : runs) {
29+
// std::cout << r.name << '\n';
30+
// }
31+
}

example/tparams.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
namespace demo::params {
55

6-
consteval std::vector<std::tuple<std::meta::info, int>> make_tparams() {
6+
consteval std::vector<rsl::testing::ParamSet> make_tparams() {
77
return {{^^double, 13}, {^^short, 14}};
88
}
99

1010
[[=rsl::test]]
1111
[[=rsl::tparams(make_tparams)]]
12-
[[=rsl::tparams({std::tuple{^^int, 10}, {^^float, 21}})]]
13-
[[=rsl::params({std::tuple{42, 'c'}, {12, 'b'}})]]
12+
[[=rsl::tparams({{^^int, 10}, {^^float, 21}})]]
13+
[[=rsl::params({{42, 'c'}, {12, 'b'}})]]
1414
constexpr inline auto tparam_gt_5 = []<typename T, int I>(int a, char b) static {
1515
ASSERT(I > 5);
1616
};

include/rsl/testing/_impl/params.hpp

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

include/rsl/testing/_impl/util.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,22 @@ constexpr std::uint32_t fnv1a(std::string_view str) {
3535
return fnv1a(str.begin(), str.size());
3636
}
3737

38+
consteval bool has_parent(std::meta::info R) {
39+
// HACK remove this once `std::meta::has_parent` is supported in libc++
40+
return R != ^^::;
41+
}
42+
43+
consteval std::vector<std::string_view> get_fully_qualified_name(std::meta::info R) {
44+
std::vector<std::string_view> name{identifier_of(R)};
45+
auto current = R;
46+
while (has_parent(current)) {
47+
current = parent_of(current);
48+
if (!has_identifier(current)) {
49+
continue;
50+
}
51+
name.emplace_back(define_static_string(identifier_of(current)));
52+
}
53+
std::ranges::reverse(name);
54+
return name;
55+
}
3856
} // namespace rsl::_testing_impl

include/rsl/testing/all.hpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#include <rsl/testing/util.hpp>
1010

1111
namespace rsl {
12-
using testing::annotations::fixture;
13-
using testing::annotations::test;
14-
using testing::annotations::expect_failure;
15-
using testing::annotations::params;
16-
using testing::annotations::tparams;
12+
using testing::fixture;
13+
using testing::test;
14+
using testing::expect_failure;
15+
using testing::params;
16+
using testing::tparams;
1717

1818
} // namespace rsl::testing
1919

@@ -39,4 +39,22 @@ using testing::annotations::tparams;
3939
namespace RSL_TEST_NAMESPACE {}
4040
#endif
4141

42-
#define RSLTEST_ENABLE RSLTEST_ENABLE_NS(RSL_TEST_NAMESPACE)
42+
#define RSLTEST_ENABLE RSLTEST_ENABLE_NS(RSL_TEST_NAMESPACE)
43+
44+
namespace rsl::testing {
45+
template <typename T, T V>
46+
requires (!std::is_reference_v<T>)
47+
struct Anchor {
48+
constexpr static auto value =
49+
std::is_object_v<T> ? std::meta::reflect_constant(V) : std::meta::reflect_function(*V);
50+
};
51+
52+
template <std::meta::info V>
53+
struct Anchor <std::meta::info, V>{ constexpr static auto value = V; };
54+
}
55+
56+
#define RSLTEST_ANCHOR_IMPL(TYPE, VALUE) \
57+
consteval std::meta::info _rsl_test_anchor(rsl::testing::Anchor<TYPE, VALUE> anchor={}) { return anchor.value; }
58+
59+
#define RSLTEST_ANCHOR(...) RSLTEST_ANCHOR_IMPL(std::meta::info, (^^__VA_ARGS__))
60+
#define RSLTEST_ANCHOR_OVERLOAD(TYPE, VALUE) RSLTEST_ANCHOR_IMPL(TYPE, VALUE)

0 commit comments

Comments
 (0)