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
5c773cd0
Commit
5c773cd0
authored
May 26, 2015
by
Matthias Vallentin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #307 from rvlm/pr/test-no-main
Add support for CAF_TEST_NO_MAIN Closes #305.
parents
c76e8ad4
04c3555d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
22 deletions
+42
-22
libcaf_test/README.md
libcaf_test/README.md
+7
-1
libcaf_test/caf/test/unit_test.hpp
libcaf_test/caf/test/unit_test.hpp
+9
-0
libcaf_test/caf/test/unit_test_impl.hpp
libcaf_test/caf/test/unit_test_impl.hpp
+26
-21
No files found.
libcaf_test/README.md
View file @
5c773cd0
...
...
@@ -2,6 +2,8 @@ CAF Unit Testing Framework
==========================
The CAF unit testing framework offers a simple API to write unit tests.
It offers features in a way compliant to Boost.Test library, with similar
concepts and API.
Concepts
--------
...
...
@@ -14,7 +16,7 @@ Example
-------
```
cpp
#include <caf/test/unit_test.h>
#include <caf/test/unit_test.h
pp
>
CAF_SUITE
(
"core"
)
...
...
@@ -30,3 +32,7 @@ CAF_TEST("divide")
CAF_CHECK
(
1
/
1
==
0
);
// fails
}
```
You can provide your own
`main`
function by defining
`CAF_TEST_NO_MAIN`
before including
`unit_test.hpp`
. In this case you may refer to the default
test-runner function as
`caf::test::main`
.
libcaf_test/caf/test/unit_test.hpp
View file @
5c773cd0
...
...
@@ -35,6 +35,15 @@ namespace caf {
class
message
;
namespace
test
{
/**
* Default test-running function.
* This function will be called automatically unless you define
* `CAF_TEST_NO_MAIN` before including `caf/test/unit_test.hpp`. In
* the latter case you will have to provide you own `main` function,
* where you may want to call `caf::test::main` from.
*/
int
main
(
int
argc
,
char
**
argv
);
/**
* A sequence of *checks*.
*/
...
...
libcaf_test/caf/test/unit_test_impl.hpp
View file @
5c773cd0
...
...
@@ -478,26 +478,9 @@ std::string engine::render(std::chrono::microseconds t) {
:
(
std
::
to_string
(
t
.
count
())
+
" us"
);
}
namespace
detail
{
expr
::
expr
(
test
*
parent
,
const
char
*
filename
,
size_t
lineno
,
bool
should_fail
,
const
char
*
expression
)
:
m_test
{
parent
},
m_filename
{
filename
},
m_line
{
lineno
},
m_should_fail
{
should_fail
},
m_expr
{
expression
}
{
assert
(
m_test
!=
nullptr
);
}
}
// namespace detail
}
// namespace test
}
// namespace caf
int
main
(
int
argc
,
char
**
argv
)
{
using
namespace
caf
;
// set path of executable
test
::
engine
::
path
(
argv
[
0
]);
engine
::
path
(
argv
[
0
]);
// default values.
int
verbosity_console
=
3
;
int
verbosity_file
=
3
;
...
...
@@ -539,7 +522,7 @@ int main(int argc, char** argv) {
}
if
(
res
.
opts
.
count
(
"available-suites"
)
>
0
)
{
std
::
cout
<<
"available suites:"
<<
std
::
endl
;
for
(
auto
&
s
:
test
::
engine
::
available_suites
())
{
for
(
auto
&
s
:
engine
::
available_suites
())
{
std
::
cout
<<
" - "
<<
s
<<
std
::
endl
;
}
return
0
;
...
...
@@ -551,12 +534,34 @@ int main(int argc, char** argv) {
}
auto
colorize
=
res
.
opts
.
count
(
"no-colors"
)
==
0
;
if
(
divider
<
argc
)
{
test
::
engine
::
args
(
argc
-
divider
-
1
,
argv
+
divider
+
1
);
engine
::
args
(
argc
-
divider
-
1
,
argv
+
divider
+
1
);
}
auto
result
=
test
::
engine
::
run
(
colorize
,
log_file
,
verbosity_console
,
auto
result
=
engine
::
run
(
colorize
,
log_file
,
verbosity_console
,
verbosity_file
,
max_runtime
,
suites
,
not_suites
,
tests
,
not_tests
);
return
result
?
0
:
1
;
}
namespace
detail
{
expr
::
expr
(
test
*
parent
,
const
char
*
filename
,
size_t
lineno
,
bool
should_fail
,
const
char
*
expression
)
:
m_test
{
parent
},
m_filename
{
filename
},
m_line
{
lineno
},
m_should_fail
{
should_fail
},
m_expr
{
expression
}
{
assert
(
m_test
!=
nullptr
);
}
}
// namespace detail
}
// namespace test
}
// namespace caf
#ifndef CAF_TEST_NO_MAIN
int
main
(
int
argc
,
char
**
argv
)
{
return
caf
::
test
::
main
(
argc
,
argv
);
}
#endif
#endif // CAF_TEST_UNIT_TEST_IMPL_HPP
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