Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
b618678f
Unverified
Commit
b618678f
authored
Aug 01, 2023
by
Shariar Azad Riday
Committed by
GitHub
Aug 01, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing check predicates
parent
dabbb358
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
9 deletions
+125
-9
libcaf_test/caf/test/runnable.hpp
libcaf_test/caf/test/runnable.hpp
+96
-4
libcaf_test/caf/test/test.test.cpp
libcaf_test/caf/test/test.test.cpp
+29
-5
No files found.
libcaf_test/caf/test/runnable.hpp
View file @
b618678f
...
...
@@ -58,10 +58,7 @@ public:
bool
check_eq
(
const
T0
&
lhs
,
const
T1
&
rhs
,
const
detail
::
source_location
&
location
=
detail
::
source_location
::
current
())
{
if
(
std
::
is_integral_v
<
T0
>
&&
std
::
is_integral_v
<
T1
>
)
{
static_assert
(
std
::
is_signed_v
<
T0
>
==
std
::
is_signed_v
<
T1
>
,
"comparing signed and unsigned integers is unsafe"
);
}
assert_save_comparison
<
T0
,
T1
>
();
if
(
lhs
==
rhs
)
{
reporter
::
instance
->
pass
(
location
);
return
true
;
...
...
@@ -71,6 +68,81 @@ public:
return
false
;
}
/// Checks whether `lhs` and `rhs` are unequal.
template
<
class
T0
,
class
T1
>
bool
check_ne
(
const
T0
&
lhs
,
const
T1
&
rhs
,
const
detail
::
source_location
&
location
=
detail
::
source_location
::
current
())
{
assert_save_comparison
<
T0
,
T1
>
();
if
(
lhs
!=
rhs
)
{
reporter
::
instance
->
pass
(
location
);
return
true
;
}
reporter
::
instance
->
fail
(
binary_predicate
::
ne
,
stringify
(
lhs
),
stringify
(
rhs
),
location
);
return
false
;
}
/// Checks whether `lhs` is less than `rhs`.
template
<
class
T0
,
class
T1
>
bool
check_lt
(
const
T0
&
lhs
,
const
T1
&
rhs
,
const
detail
::
source_location
&
location
=
detail
::
source_location
::
current
())
{
assert_save_comparison
<
T0
,
T1
>
();
if
(
lhs
<
rhs
)
{
reporter
::
instance
->
pass
(
location
);
return
true
;
}
reporter
::
instance
->
fail
(
binary_predicate
::
lt
,
stringify
(
lhs
),
stringify
(
rhs
),
location
);
return
false
;
}
/// Checks whether `lhs` less than or equal to `rhs`.
template
<
class
T0
,
class
T1
>
bool
check_le
(
const
T0
&
lhs
,
const
T1
&
rhs
,
const
detail
::
source_location
&
location
=
detail
::
source_location
::
current
())
{
assert_save_comparison
<
T0
,
T1
>
();
if
(
lhs
<=
rhs
)
{
reporter
::
instance
->
pass
(
location
);
return
true
;
}
reporter
::
instance
->
fail
(
binary_predicate
::
le
,
stringify
(
lhs
),
stringify
(
rhs
),
location
);
return
false
;
}
/// Checks whether `lhs` is greater than `rhs`.
template
<
class
T0
,
class
T1
>
bool
check_gt
(
const
T0
&
lhs
,
const
T1
&
rhs
,
const
detail
::
source_location
&
location
=
detail
::
source_location
::
current
())
{
assert_save_comparison
<
T0
,
T1
>
();
if
(
lhs
>
rhs
)
{
reporter
::
instance
->
pass
(
location
);
return
true
;
}
reporter
::
instance
->
fail
(
binary_predicate
::
gt
,
stringify
(
lhs
),
stringify
(
rhs
),
location
);
return
false
;
}
/// Checks whether `lhs` greater than or equal to `rhs`.
template
<
class
T0
,
class
T1
>
bool
check_ge
(
const
T0
&
lhs
,
const
T1
&
rhs
,
const
detail
::
source_location
&
location
=
detail
::
source_location
::
current
())
{
assert_save_comparison
<
T0
,
T1
>
();
if
(
lhs
>=
rhs
)
{
reporter
::
instance
->
pass
(
location
);
return
true
;
}
reporter
::
instance
->
fail
(
binary_predicate
::
ge
,
stringify
(
lhs
),
stringify
(
rhs
),
location
);
return
false
;
}
bool
check
(
bool
value
,
const
detail
::
source_location
&
location
=
detail
::
source_location
::
current
());
...
...
@@ -103,6 +175,18 @@ public:
}
#endif
template
<
class
Expr
>
void
should_fail
(
Expr
&&
expr
,
const
caf
::
detail
::
source_location
&
location
=
caf
::
detail
::
source_location
::
current
())
{
auto
*
rep
=
reporter
::
instance
;
auto
before
=
rep
->
test_stats
();
expr
();
auto
after
=
rep
->
test_stats
();
check_eq
(
before
.
passed
,
after
.
passed
,
location
);
if
(
check_eq
(
before
.
failed
+
1
,
after
.
failed
,
location
))
rep
->
test_stats
({
before
.
passed
+
1
,
before
.
failed
});
}
protected:
context_ptr
ctx_
;
std
::
string_view
description_
;
...
...
@@ -110,6 +194,14 @@ protected:
detail
::
source_location
loc_
;
private:
template
<
class
T0
,
class
T1
>
static
void
assert_save_comparison
()
{
if
constexpr
(
std
::
is_integral_v
<
T0
>
&&
std
::
is_integral_v
<
T1
>
)
{
static_assert
(
std
::
is_signed_v
<
T0
>
==
std
::
is_signed_v
<
T1
>
,
"comparing signed and unsigned integers is unsafe"
);
}
}
template
<
class
T
>
std
::
string
stringify
(
const
T
&
value
)
{
if
constexpr
(
std
::
is_convertible_v
<
T
,
std
::
string
>
)
{
...
...
libcaf_test/caf/test/test.test.cpp
View file @
b618678f
...
...
@@ -7,13 +7,37 @@
using
caf
::
test
::
block_type
;
TEST
(
"tests can contain checks"
)
{
TEST
(
"tests can contain
different types of
checks"
)
{
auto
*
rep
=
caf
::
test
::
reporter
::
instance
;
for
(
int
i
=
0
;
i
<
3
;
++
i
)
check_eq
(
i
,
i
);
auto
stats
=
rep
->
test_stats
();
check_eq
(
stats
.
passed
,
3u
);
check_eq
(
stats
.
failed
,
0u
);
SECTION
(
"check_ne checks for inequality"
)
{
check_ne
(
0
,
1
);
should_fail
([
this
]()
{
check_ne
(
0
,
0
);
});
}
SECTION
(
"check_eq checks for equality"
)
{
check_eq
(
1
,
1
);
should_fail
([
this
]()
{
check_eq
(
1
,
0
);
});
}
SECTION
(
"check_ge checks that lhs is greater than or equal to rhs"
)
{
check_ge
(
0
,
0
);
check_ge
(
2
,
1
);
should_fail
([
this
]()
{
check_ge
(
1
,
2
);
});
}
SECTION
(
"check_gt checks that lhs is greater than rhs"
)
{
check_gt
(
2
,
1
);
should_fail
([
this
]()
{
check_gt
(
0
,
0
);
});
should_fail
([
this
]()
{
check_gt
(
1
,
2
);
});
}
SECTION
(
"check_le checks that lhs is less than or equal to rhs"
)
{
check_le
(
0
,
0
);
check_le
(
1
,
2
);
should_fail
([
this
]()
{
check_le
(
2
,
1
);
});
}
SECTION
(
"check_lt checks that lhs is less than rhs"
)
{
check_lt
(
1
,
2
);
should_fail
([
this
]()
{
check_lt
(
1
,
1
);
});
should_fail
([
this
]()
{
check_lt
(
2
,
1
);
});
}
info
(
"this test had {} checks"
,
rep
->
test_stats
().
total
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment