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
39546432
Unverified
Commit
39546432
authored
Aug 15, 2023
by
Shariar Azad Riday
Committed by
GitHub
Aug 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add requirement_failed exception
parent
16b40d40
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
1 deletion
+81
-1
libcaf_test/CMakeLists.txt
libcaf_test/CMakeLists.txt
+1
-0
libcaf_test/caf/test/requirement_error.cpp
libcaf_test/caf/test/requirement_error.cpp
+27
-0
libcaf_test/caf/test/requirement_error.hpp
libcaf_test/caf/test/requirement_error.hpp
+49
-0
libcaf_test/caf/test/runnable.hpp
libcaf_test/caf/test/runnable.hpp
+2
-1
libcaf_test/caf/test/runner.cpp
libcaf_test/caf/test/runner.cpp
+2
-0
No files found.
libcaf_test/CMakeLists.txt
View file @
39546432
...
...
@@ -30,6 +30,7 @@ caf_add_component(
caf/test/nesting_error.cpp
caf/test/registry.cpp
caf/test/reporter.cpp
caf/test/requirement_error.cpp
caf/test/runnable.cpp
caf/test/runner.cpp
caf/test/scenario.cpp
...
...
libcaf_test/caf/test/requirement_error.cpp
0 → 100644
View file @
39546432
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#include "caf/test/requirement_error.hpp"
#include "caf/detail/format.hpp"
namespace
caf
::
test
{
std
::
string
requirement_error
::
message
()
const
{
return
detail
::
format
(
"requirement failed at {}:{}"
,
loc_
.
file_name
(),
loc_
.
line
());
}
[[
noreturn
]]
void
requirement_error
::
raise_impl
(
const
detail
::
source_location
&
loc
)
{
#ifdef CAF_ENABLE_EXCEPTIONS
throw
requirement_error
{
loc
};
#else
auto
msg
=
requirement_error
{
loc
}.
message
();
fprintf
(
stderr
,
"[FATAL] critical error: %s
\n
"
,
msg
.
c_str
());
abort
();
#endif
}
}
// namespace caf::test
libcaf_test/caf/test/requirement_error.hpp
0 → 100644
View file @
39546432
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#pragma once
#include "caf/detail/source_location.hpp"
#include "caf/detail/test_export.hpp"
#include <string>
namespace
caf
::
test
{
/// Thrown when a requirement check fails. When `CAF_ENABLE_EXCEPTIONS` is off,
/// the `raise` functions terminate the program instead.
class
CAF_TEST_EXPORT
requirement_error
{
public:
constexpr
requirement_error
(
const
requirement_error
&
)
noexcept
=
default
;
constexpr
requirement_error
&
operator
=
(
const
requirement_error
&
)
noexcept
=
default
;
/// Returns a human-readable error message.
std
::
string
message
()
const
;
/// Returns the source location of the error.
constexpr
const
detail
::
source_location
&
location
()
const
noexcept
{
return
loc_
;
}
/// Throws a `requirement_error` to indicate that requirement check failed.
[[
noreturn
]]
static
void
raise
(
const
detail
::
source_location
&
loc
=
detail
::
source_location
::
current
())
{
raise_impl
(
loc
);
}
private:
constexpr
explicit
requirement_error
(
const
detail
::
source_location
&
loc
)
noexcept
:
loc_
(
loc
)
{
// nop
}
[[
noreturn
]]
static
void
raise_impl
(
const
detail
::
source_location
&
loc
);
detail
::
source_location
loc_
;
};
}
// namespace caf::test
libcaf_test/caf/test/runnable.hpp
View file @
39546432
...
...
@@ -8,6 +8,7 @@
#include "caf/test/block_type.hpp"
#include "caf/test/fwd.hpp"
#include "caf/test/reporter.hpp"
#include "caf/test/requirement_error.hpp"
#include "caf/config.hpp"
#include "caf/deep_to_string.hpp"
...
...
@@ -53,7 +54,7 @@ public:
}
else
{
reporter
::
instance
().
fail
(
fwl
.
value
,
fwl
.
location
);
}
CAF_RAISE_ERROR
(
std
::
logic_error
,
"requirement failed: abort test"
);
requirement_error
::
raise
(
fwl
.
location
);
}
/// Generates a message with the INFO severity level.
...
...
libcaf_test/caf/test/runner.cpp
View file @
39546432
...
...
@@ -170,6 +170,8 @@ int runner::run(int argc, char** argv) {
}
catch
(
const
nesting_error
&
ex
)
{
default_reporter
->
unhandled_exception
(
ex
.
message
(),
ex
.
location
());
default_reporter
->
end_test
();
}
catch
(
const
requirement_error
&
ex
)
{
default_reporter
->
end_test
();
}
catch
(
const
std
::
exception
&
ex
)
{
default_reporter
->
unhandled_exception
(
ex
.
what
());
default_reporter
->
end_test
();
...
...
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