Skip to content

Commit 0c32853

Browse files
committed
✅ Use STATIC_REQUIRE instead of static_assert
Problem: - Using static_assert does not report the check in Catch2. Solution: - Use STATIC_REQUIRE so that the check is reported.
1 parent aea809c commit 0c32853

File tree

10 files changed

+157
-143
lines changed

10 files changed

+157
-143
lines changed

test/config.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,35 @@ TEST_CASE("fields inside a register", "[config]") {
2525
using F = groov::field<"field", std::uint32_t, 0, 0>;
2626
using R = groov::reg<"reg", std::uint32_t, 0, groov::w::replace, F>;
2727
using X = groov::get_child<R, "field">;
28-
static_assert(std::same_as<F, X>);
28+
STATIC_REQUIRE(std::same_as<F, X>);
2929
}
3030

3131
TEST_CASE("registers in a group", "[config]") {
3232
using R = groov::reg<"reg", std::uint32_t, 0>;
3333
using G = groov::group<"group", bus, R>;
3434
using X = groov::get_child<G, "reg">;
35-
static_assert(std::same_as<R, X>);
35+
STATIC_REQUIRE(std::same_as<R, X>);
3636
}
3737

3838
TEST_CASE("subfields inside a field", "[config]") {
3939
using SubF = groov::field<"subfield", std::uint32_t, 0, 0>;
4040
using F =
4141
groov::field<"field", std::uint32_t, 0, 0, groov::w::replace, SubF>;
4242
using X = groov::get_child<F, "subfield">;
43-
static_assert(std::same_as<SubF, X>);
43+
STATIC_REQUIRE(std::same_as<SubF, X>);
4444
}
4545

4646
TEST_CASE("field can be extracted from register value", "[config]") {
4747
constexpr std::uint32_t value{0b11};
4848
using F = groov::field<"field", std::uint32_t, 0, 0>;
49-
static_assert(F::extract(value) == 1);
49+
STATIC_REQUIRE(F::extract(value) == 1);
5050
}
5151

5252
TEST_CASE("field can resolve a path", "[config]") {
5353
using namespace groov::literals;
5454
using F = groov::field<"field", std::uint32_t, 0, 0>;
5555
constexpr auto r = groov::resolve(F{}, "field"_f);
56-
static_assert(std::is_same_v<decltype(r), F const>);
56+
STATIC_REQUIRE(std::is_same_v<decltype(r), F const>);
5757
}
5858

5959
TEST_CASE("field containing subfields can resolve a path", "[config]") {
@@ -62,7 +62,7 @@ TEST_CASE("field containing subfields can resolve a path", "[config]") {
6262
using F =
6363
groov::field<"field", std::uint32_t, 0, 0, groov::w::replace, SubF>;
6464
constexpr auto r = groov::resolve(F{}, "field.subfield"_f);
65-
static_assert(std::is_same_v<decltype(r), SubF const>);
65+
STATIC_REQUIRE(std::is_same_v<decltype(r), SubF const>);
6666
}
6767

6868
TEST_CASE("field can resolve an unambiguous subpath", "[config]") {
@@ -71,23 +71,23 @@ TEST_CASE("field can resolve an unambiguous subpath", "[config]") {
7171
using F =
7272
groov::field<"field", std::uint32_t, 0, 0, groov::w::replace, SubF>;
7373
constexpr auto r = groov::resolve(F{}, "subfield"_f);
74-
static_assert(std::is_same_v<decltype(r), SubF const>);
74+
STATIC_REQUIRE(std::is_same_v<decltype(r), SubF const>);
7575
}
7676

7777
TEST_CASE("register can resolve a path", "[config]") {
7878
using namespace groov::literals;
7979
using F = groov::field<"field", std::uint32_t, 0, 0>;
8080
using R = groov::reg<"reg", std::uint32_t, 0, groov::w::replace, F>;
8181
constexpr auto r = groov::resolve(R{}, "reg"_r);
82-
static_assert(std::is_same_v<decltype(r), R const>);
82+
STATIC_REQUIRE(std::is_same_v<decltype(r), R const>);
8383
}
8484

8585
TEST_CASE("register can resolve an unambiguous subpath", "[config]") {
8686
using namespace groov::literals;
8787
using F = groov::field<"field", std::uint32_t, 0, 0>;
8888
using R = groov::reg<"reg", std::uint32_t, 0, groov::w::replace, F>;
8989
constexpr auto r = groov::resolve(R{}, "field"_f);
90-
static_assert(std::is_same_v<decltype(r), F const>);
90+
STATIC_REQUIRE(std::is_same_v<decltype(r), F const>);
9191
}
9292

9393
TEST_CASE("register can resolve an unambiguous nested subpath", "[config]") {
@@ -97,15 +97,15 @@ TEST_CASE("register can resolve an unambiguous nested subpath", "[config]") {
9797
groov::field<"field", std::uint32_t, 0, 0, groov::w::replace, SubF>;
9898
using R = groov::reg<"reg", std::uint32_t, 0, groov::w::replace, F>;
9999
constexpr auto r = groov::resolve(R{}, "subfield"_f);
100-
static_assert(std::is_same_v<decltype(r), SubF const>);
100+
STATIC_REQUIRE(std::is_same_v<decltype(r), SubF const>);
101101
}
102102

103103
TEST_CASE("invalid path gives invalid resolution", "[config]") {
104104
using namespace groov::literals;
105105
using F = groov::field<"field", std::uint32_t, 0, 0>;
106106
using R = groov::reg<"reg", std::uint32_t, 0, groov::w::replace, F>;
107-
static_assert(std::is_same_v<groov::invalid_t,
108-
decltype(groov::resolve(R{}, "invalid"_f))>);
107+
STATIC_REQUIRE(std::is_same_v<groov::invalid_t,
108+
decltype(groov::resolve(R{}, "invalid"_f))>);
109109
}
110110

111111
TEST_CASE("ambiguous subpath gives ambiguous resolution", "[config]") {
@@ -116,8 +116,8 @@ TEST_CASE("ambiguous subpath gives ambiguous resolution", "[config]") {
116116
using F1 =
117117
groov::field<"field1", std::uint32_t, 1, 1, groov::w::replace, SubF>;
118118
using R = groov::reg<"reg", std::uint32_t, 0, groov::w::replace, F0, F1>;
119-
static_assert(std::is_same_v<groov::ambiguous_t,
120-
decltype(groov::resolve(R{}, "subfield"_f))>);
119+
STATIC_REQUIRE(std::is_same_v<groov::ambiguous_t,
120+
decltype(groov::resolve(R{}, "subfield"_f))>);
121121
}
122122

123123
TEST_CASE("group can resolve a path", "[config]") {
@@ -126,13 +126,13 @@ TEST_CASE("group can resolve a path", "[config]") {
126126
using R = groov::reg<"reg", std::uint32_t, 0, groov::w::replace, F>;
127127
using G = groov::group<"group", bus, R>;
128128
constexpr auto r = groov::resolve(G{}, "reg.field"_f);
129-
static_assert(std::is_same_v<decltype(r), F const>);
129+
STATIC_REQUIRE(std::is_same_v<decltype(r), F const>);
130130
}
131131

132132
TEST_CASE("all fields inside a register with no fields", "[config]") {
133133
using namespace groov::literals;
134134
using R = groov::reg<"reg", std::uint32_t, 0>;
135-
static_assert(
135+
STATIC_REQUIRE(
136136
std::is_same_v<groov::detail::all_fields_t<boost::mp11::mp_list<R>>,
137137
boost::mp11::mp_list<R>>);
138138
}
@@ -142,7 +142,7 @@ TEST_CASE("all fields inside a register with fields", "[config]") {
142142
using F0 = groov::field<"field0", std::uint32_t, 0, 0>;
143143
using F1 = groov::field<"field1", std::uint32_t, 1, 1>;
144144
using R = groov::reg<"reg", std::uint32_t, 0, groov::w::replace, F0, F1>;
145-
static_assert(
145+
STATIC_REQUIRE(
146146
std::is_same_v<groov::detail::all_fields_t<boost::mp11::mp_list<R>>,
147147
boost::mp11::mp_list<F0, F1>>);
148148
}
@@ -156,7 +156,7 @@ TEST_CASE("all fields inside a register with fields and subfields",
156156
SubF00, SubF01>;
157157
using F1 = groov::field<"field1", std::uint32_t, 2, 2>;
158158
using R = groov::reg<"reg", std::uint32_t, 0, groov::w::replace, F0, F1>;
159-
static_assert(
159+
STATIC_REQUIRE(
160160
std::is_same_v<groov::detail::all_fields_t<boost::mp11::mp_list<R>>,
161161
boost::mp11::mp_list<SubF00, SubF01, F1>>);
162162
}

test/identity.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,54 @@
77
#include <type_traits>
88

99
TEST_CASE("all specs except none fulfil identity_spec", "[identity]") {
10-
static_assert(not groov::identity_spec<groov::id::none>);
11-
static_assert(groov::identity_spec<groov::id::zero>);
12-
static_assert(groov::identity_spec<groov::id::one>);
13-
static_assert(groov::identity_spec<groov::id::any>);
10+
STATIC_REQUIRE(not groov::identity_spec<groov::id::none>);
11+
STATIC_REQUIRE(groov::identity_spec<groov::id::zero>);
12+
STATIC_REQUIRE(groov::identity_spec<groov::id::one>);
13+
STATIC_REQUIRE(groov::identity_spec<groov::id::any>);
1414
}
1515

1616
TEST_CASE("zero id spec returns a zeroed identity", "[identity]") {
1717
constexpr auto i = groov::id::zero::identity<std::uint8_t, 7, 0>();
18-
static_assert(i == 0);
18+
STATIC_REQUIRE(i == 0);
1919
}
2020

2121
TEST_CASE("one id spec returns a identity with ones", "[identity]") {
2222
constexpr auto i = groov::id::one::identity<std::uint8_t, 7, 0>();
23-
static_assert(i == 0xffu);
23+
STATIC_REQUIRE(i == 0xffu);
2424
}
2525

2626
TEST_CASE("any id spec returns a zeroed identity", "[identity]") {
2727
constexpr auto i = groov::id::any::identity<std::uint8_t, 7, 0>();
28-
static_assert(i == 0);
28+
STATIC_REQUIRE(i == 0);
2929
}
3030

3131
TEST_CASE("replace write function has no identity", "[identity]") {
32-
static_assert(groov::write_function<groov::w::replace>);
33-
static_assert(std::is_same_v<groov::w::replace::id_spec, groov::id::none>);
32+
STATIC_REQUIRE(groov::write_function<groov::w::replace>);
33+
STATIC_REQUIRE(std::is_same_v<groov::w::replace::id_spec, groov::id::none>);
3434
}
3535

3636
TEST_CASE("read_only write function has any identity", "[identity]") {
37-
static_assert(groov::write_function<groov::w::read_only>);
38-
static_assert(std::is_same_v<groov::w::read_only::id_spec, groov::id::any>);
37+
STATIC_REQUIRE(groov::write_function<groov::w::read_only>);
38+
STATIC_REQUIRE(
39+
std::is_same_v<groov::w::read_only::id_spec, groov::id::any>);
3940
}
4041

4142
TEST_CASE("write one to set/clear write function has zero identity",
4243
"[identity]") {
43-
static_assert(groov::write_function<groov::w::one_to_set>);
44-
static_assert(groov::write_function<groov::w::one_to_clear>);
45-
static_assert(
44+
STATIC_REQUIRE(groov::write_function<groov::w::one_to_set>);
45+
STATIC_REQUIRE(groov::write_function<groov::w::one_to_clear>);
46+
STATIC_REQUIRE(
4647
std::is_same_v<groov::w::one_to_set::id_spec, groov::id::zero>);
47-
static_assert(
48+
STATIC_REQUIRE(
4849
std::is_same_v<groov::w::one_to_clear::id_spec, groov::id::zero>);
4950
}
5051

5152
TEST_CASE("write zero to set/clear write function has one identity",
5253
"[identity]") {
53-
static_assert(groov::write_function<groov::w::zero_to_set>);
54-
static_assert(groov::write_function<groov::w::zero_to_clear>);
55-
static_assert(
54+
STATIC_REQUIRE(groov::write_function<groov::w::zero_to_set>);
55+
STATIC_REQUIRE(groov::write_function<groov::w::zero_to_clear>);
56+
STATIC_REQUIRE(
5657
std::is_same_v<groov::w::zero_to_set::id_spec, groov::id::one>);
57-
static_assert(
58+
STATIC_REQUIRE(
5859
std::is_same_v<groov::w::zero_to_clear::id_spec, groov::id::one>);
5960
}

test/path.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,91 +7,91 @@
77
TEST_CASE("register literal", "[path]") {
88
using namespace groov::literals;
99
constexpr auto r = "reg"_r;
10-
static_assert(std::is_same_v<decltype(r), groov::path<"reg"> const>);
10+
STATIC_REQUIRE(std::is_same_v<decltype(r), groov::path<"reg"> const>);
1111
}
1212

1313
TEST_CASE("field literal", "[path]") {
1414
using namespace groov::literals;
1515
constexpr auto f = "field"_f;
16-
static_assert(std::is_same_v<decltype(f), groov::path<"field"> const>);
16+
STATIC_REQUIRE(std::is_same_v<decltype(f), groov::path<"field"> const>);
1717
}
1818

1919
TEST_CASE("dot-separated literal", "[path]") {
2020
using namespace groov::literals;
2121
constexpr auto f = "a.b.c.d"_f;
22-
static_assert(
22+
STATIC_REQUIRE(
2323
std::is_same_v<decltype(f), groov::path<"a", "b", "c", "d"> const>);
2424
}
2525

2626
TEST_CASE("path concatenation with /", "[path]") {
2727
using namespace groov::literals;
2828
constexpr auto p = "reg"_r / "field"_f;
29-
static_assert(p == "reg.field"_f);
29+
STATIC_REQUIRE(p == "reg.field"_f);
3030
}
3131

3232
TEST_CASE("path can resolve itself", "[path]") {
3333
using namespace groov::literals;
3434
constexpr auto p = "a"_r;
35-
static_assert(groov::is_resolvable_v<decltype(p), decltype(p)>);
35+
STATIC_REQUIRE(groov::is_resolvable_v<decltype(p), decltype(p)>);
3636
}
3737

3838
TEST_CASE("path resolves itself to empty path", "[path]") {
3939
using namespace groov::literals;
4040
constexpr auto p = "a"_r;
4141
constexpr auto r = groov::resolve(p, p);
42-
static_assert(std::is_same_v<decltype(r), groov::path<> const>);
42+
STATIC_REQUIRE(std::is_same_v<decltype(r), groov::path<> const>);
4343
}
4444

4545
TEST_CASE("path resolves a shorter path", "[path]") {
4646
using namespace groov::literals;
4747
constexpr auto p = "a.b.c"_r;
4848
constexpr auto r1 = groov::resolve(p, "a"_r);
49-
static_assert(r1 == "b.c"_r);
49+
STATIC_REQUIRE(r1 == "b.c"_r);
5050
constexpr auto r2 = groov::resolve(p, "a.b"_r);
51-
static_assert(r2 == "c"_r);
51+
STATIC_REQUIRE(r2 == "c"_r);
5252
}
5353

5454
TEST_CASE("path doesn't resolve a non-path", "[path]") {
5555
using namespace groov::literals;
5656
constexpr auto p = "a.b.c"_r;
57-
static_assert(not groov::can_resolve<decltype(p), int>);
57+
STATIC_REQUIRE(not groov::can_resolve<decltype(p), int>);
5858
}
5959

6060
TEST_CASE("mismatched path gives invalid resolution", "[path]") {
6161
using namespace groov::literals;
6262
constexpr auto p = "a.b.c"_r;
63-
static_assert(std::is_same_v<groov::mismatch_t,
64-
decltype(groov::resolve(p, "invalid"_r))>);
63+
STATIC_REQUIRE(std::is_same_v<groov::mismatch_t,
64+
decltype(groov::resolve(p, "invalid"_r))>);
6565
}
6666

6767
TEST_CASE("too-long path gives invalid resolution", "[path]") {
6868
using namespace groov::literals;
6969
constexpr auto p = "a.b"_r;
70-
static_assert(std::is_same_v<groov::too_long_t,
71-
decltype(groov::resolve(p, "a.b.c"_r))>);
70+
STATIC_REQUIRE(std::is_same_v<groov::too_long_t,
71+
decltype(groov::resolve(p, "a.b.c"_r))>);
7272
}
7373

7474
TEST_CASE("root of a path", "[path]") {
7575
using namespace groov::literals;
7676
constexpr auto p = "a.b.c"_r;
77-
static_assert(root(p) == stdx::ct_string{"a"});
77+
STATIC_REQUIRE(root(p) == stdx::ct_string{"a"});
7878
}
7979

8080
TEST_CASE("path without its root", "[path]") {
8181
using namespace groov::literals;
8282
constexpr auto p = "a.b.c"_r;
83-
static_assert(without_root(p) == "b.c"_r);
83+
STATIC_REQUIRE(without_root(p) == "b.c"_r);
8484
}
8585

8686
TEST_CASE("empty path predicate", "[path]") {
8787
using P = groov::path<>;
88-
static_assert(std::empty(P{}));
88+
STATIC_REQUIRE(std::empty(P{}));
8989
using Q = groov::path<"hello">;
90-
static_assert(not std::empty(Q{}));
90+
STATIC_REQUIRE(not std::empty(Q{}));
9191
}
9292

9393
TEST_CASE("path is pathlike", "[path]") {
9494
using namespace groov::literals;
95-
static_assert(groov::pathlike<decltype("reg"_r / "field"_f)>);
96-
static_assert(not groov::valued_pathlike<decltype("reg"_r / "field"_f)>);
95+
STATIC_REQUIRE(groov::pathlike<decltype("reg"_r / "field"_f)>);
96+
STATIC_REQUIRE(not groov::valued_pathlike<decltype("reg"_r / "field"_f)>);
9797
}

test/read_spec.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ constexpr auto grp = G{};
3939
TEST_CASE("read_spec is made by combining group and paths", "[read_spec]") {
4040
using namespace groov::literals;
4141
auto spec = grp("reg0"_r);
42-
static_assert(
42+
STATIC_REQUIRE(
4343
stdx::is_specialization_of_v<decltype(spec), groov::read_spec>);
4444
}
4545

4646
TEST_CASE("valid paths are captured", "[read_spec]") {
4747
using namespace groov::literals;
4848
auto p = "reg0"_r;
4949
auto spec = grp(p);
50-
static_assert(std::is_same_v<decltype(spec)::paths_t,
51-
boost::mp11::mp_list<decltype(p)>>);
50+
STATIC_REQUIRE(std::is_same_v<decltype(spec)::paths_t,
51+
boost::mp11::mp_list<decltype(p)>>);
5252
}
5353

5454
TEST_CASE("multiple paths can be passed", "[read_spec]") {
5555
using namespace groov::literals;
5656
auto p = "reg0"_r;
5757
auto q = "reg1"_r;
5858
auto spec = grp(p, q);
59-
static_assert(
59+
STATIC_REQUIRE(
6060
std::is_same_v<decltype(spec)::paths_t,
6161
boost::mp11::mp_list<decltype(p), decltype(q)>>);
6262
}
@@ -65,6 +65,6 @@ TEST_CASE("operator/ is overloaded to make read_spec", "[read_spec]") {
6565
using namespace groov::literals;
6666
auto p = "reg0"_r;
6767
auto spec = grp / p;
68-
static_assert(std::is_same_v<decltype(spec)::paths_t,
69-
boost::mp11::mp_list<decltype(p)>>);
68+
STATIC_REQUIRE(std::is_same_v<decltype(spec)::paths_t,
69+
boost::mp11::mp_list<decltype(p)>>);
7070
}

test/tools/test_regs.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
def test_parse(t):
2-
return {'test_regs':
3-
groov.Group('test_regs', [
4-
groov.Register('test', 0x0, [
5-
groov.Field('test', 'groov::w::replace', 0, 0)])])}
2+
return {
3+
"test_regs": groov.Group(
4+
"test_regs",
5+
[
6+
groov.Register(
7+
"test", 0x0, [groov.Field("test", "groov::w::replace", 0, 0)]
8+
)
9+
],
10+
)
11+
}

0 commit comments

Comments
 (0)