OTest2
A C++ testing framework
lib
runcode.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2018 Ondrej Starek
3
*
4
* This file is part of OTest2.
5
*
6
* OTest2 is free software: you can redistribute it and/or modify it under
7
* the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License,
9
* or (at your option) any later version.
10
*
11
* OTest2 is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14
* License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#include "
runcode.h
"
21
22
#include <exception>
23
#include <sstream>
24
#include <string>
25
26
#include <
context.h
>
27
#include <
exccatcher.h
>
28
#include <
internalerror.h
>
29
#include <
semanticstack.h
>
30
31
namespace
OTest2
{
32
33
bool
runUserCode
(
34
const
Context
& context_,
35
std::function<
void
(
const
Context
&)> ftor_) noexcept {
36
/* -- prepare the return value */
37
context_.
semantic_stack
->
push
(
true
);
38
39
/* -- run the functor */
40
std::string message_;
41
if
(context_.
exception_catcher
->
catchException
(context_, ftor_, message_))
42
internalError
(context_, message_);
43
44
/* -- handle the return value */
45
bool
retval_(context_.
semantic_stack
->
top
());
46
context_.
semantic_stack
->
popAnd
();
47
48
return
retval_;
49
}
50
51
}
/* -- namespace OTest2 */
OTest2::SemanticStack::popAnd
void popAnd()
AND last two values and replace them by the result.
Definition:
semanticstack.cpp:86
OTest2::SemanticStack::push
void push(bool value_)
Push a value.
Definition:
semanticstack.cpp:65
internalerror.h
OTest2::internalError
void internalError(const Context &context_, const std::string &message_) noexcept
Fail the running test because of an internal error.
Definition:
internalerror.cpp:28
semanticstack.h
OTest2
Definition:
assertbean.h:25
OTest2::runUserCode
bool runUserCode(const Context &context_, std::function< void(const Context &)> ftor_) noexcept
Definition:
runcode.cpp:33
OTest2::Context::semantic_stack
SemanticStack *const semantic_stack
Definition:
context.h:41
exccatcher.h
runcode.h
context.h
OTest2::Context::exception_catcher
ExcCatcher *const exception_catcher
Definition:
context.h:44
OTest2::Context
OTest2 runtime context.
Definition:
context.h:38
OTest2::ExcCatcher::catchException
virtual bool catchException(const Context &context_, std::function< void(const Context &)> ftor_, std::string &message_) noexcept=0
Catch unexpected exceptions.
OTest2::SemanticStack::top
bool top() const
Get top value.
Definition:
semanticstack.cpp:70
Generated by
1.8.17