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
c4c211f6
Commit
c4c211f6
authored
May 12, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fixture support to unit test framework
parent
c9d38369
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
14 deletions
+24
-14
libcaf_test/caf/test/unit_test.hpp
libcaf_test/caf/test/unit_test.hpp
+18
-4
libcaf_test/caf/test/unit_test_impl.hpp
libcaf_test/caf/test/unit_test_impl.hpp
+6
-10
No files found.
libcaf_test/caf/test/unit_test.hpp
View file @
c4c211f6
...
...
@@ -70,6 +70,8 @@ class test {
size_t
m_bad
;
};
struct
dummy_fixture
{
};
namespace
detail
{
// thrown when a required check fails
...
...
@@ -217,12 +219,14 @@ class engine {
*/
static
char
*
path
();
using
test_generator
=
std
::
function
<
std
::
unique_ptr
<
test
>
()
>
;
/**
* Adds a test to the engine.
* @param name The name of the suite.
* @param t The test to register.
*/
static
void
add
(
const
char
*
name
,
std
::
unique_ptr
<
test
>
t
);
static
void
add
(
const
char
*
name
,
test_generator
generator
);
/**
* Invokes tests in all suites.
...
...
@@ -292,7 +296,7 @@ class engine {
const
char
*
m_check_file
=
"<none>"
;
size_t
m_check_line
=
0
;
test
*
m_current_test
=
nullptr
;
std
::
map
<
std
::
string
,
std
::
vector
<
std
::
unique_ptr
<
test
>
>>
m_suites
;
std
::
map
<
std
::
string
,
std
::
vector
<
test_generator
>>
m_suites
;
};
namespace
detail
{
...
...
@@ -300,7 +304,7 @@ namespace detail {
template
<
class
T
>
struct
adder
{
adder
(
char
const
*
name
)
{
engine
::
add
(
name
,
std
::
unique_ptr
<
T
>
{
new
T
});
engine
::
add
(
name
,
[]
{
return
std
::
unique_ptr
<
T
>
{
new
T
};
});
}
};
...
...
@@ -530,6 +534,9 @@ private:
}
// namespace test
}
// namespace caf
// on the global namespace so that it can hidden via namespace-scoping
using
caf_test_case_auto_fixture
=
caf
::
test
::
dummy_fixture
;
#define CAF_TEST_PR(level, msg) \
::caf::test::logger::instance(). level () \
<< ::caf::test::engine::color(::caf::test::yellow) \
...
...
@@ -591,7 +598,8 @@ private:
#define CAF_TEST(name) \
namespace { \
struct CAF_UNIQUE(test) : public ::caf::test::test { \
struct CAF_UNIQUE(test) : public ::caf::test::test, \
public caf_test_case_auto_fixture { \
CAF_UNIQUE(test)() : test{CAF_XSTR(name)} { } \
void run() final; \
}; \
...
...
@@ -601,6 +609,12 @@ private:
}
/* namespace <anonymous> */
\
void CAF_UNIQUE(test)::run()
#define CAF_TEST_FIXTURE_SCOPE(scope_name, fixture_name) \
namespace scope_name { using caf_test_case_auto_fixture = fixture_name ;
#define CAF_TEST_FIXTURE_SCOPE_END() \
} // close namespace
// Boost Test compatibility macro
#define CAF_CHECK_EQUAL(x, y) CAF_CHECK(x == y)
#define CAF_MESSAGE(msg) CAF_TEST_VERBOSE(msg)
...
...
libcaf_test/caf/test/unit_test_impl.hpp
View file @
c4c211f6
...
...
@@ -241,15 +241,10 @@ char* engine::path() {
return
instance
().
m_path
;
}
void
engine
::
add
(
const
char
*
name
,
std
::
unique_ptr
<
test
>
t
)
{
auto
&
suite
=
instance
().
m_suites
[
std
::
string
{
name
?
name
:
""
}];
for
(
auto
&
x
:
suite
)
{
if
(
x
->
name
()
==
t
->
name
())
{
std
::
cout
<<
"duplicate test name: "
<<
t
->
name
()
<<
'\n'
;
std
::
abort
();
}
}
suite
.
emplace_back
(
std
::
move
(
t
));
void
engine
::
add
(
const
char
*
cstr_name
,
test_generator
generator
)
{
std
::
string
name
=
cstr_name
?
cstr_name
:
""
;
auto
&
suite
=
instance
().
m_suites
[
name
];
suite
.
emplace_back
(
std
::
move
(
generator
));
}
bool
engine
::
run
(
bool
colorize
,
...
...
@@ -349,7 +344,8 @@ bool engine::run(bool colorize,
auto
pad
=
std
::
string
((
bar
.
size
()
-
suite_name
.
size
())
/
2
,
' '
);
bool
displayed_header
=
false
;
size_t
tests_ran
=
0
;
for
(
auto
&
t
:
p
.
second
)
{
for
(
auto
&
generator
:
p
.
second
)
{
auto
t
=
generator
();
if
(
!
enabled
(
tests
,
not_tests
,
t
->
name
()))
{
continue
;
}
...
...
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