summaryrefslogtreecommitdiff
path: root/vendor/bandit/bandit/context.h
diff options
context:
space:
mode:
authorManoj Srivastava <srivasta@debian.org>2020-05-22 19:57:41 -0700
committerManoj Srivastava <srivasta@debian.org>2020-05-22 20:02:19 -0700
commitc3d2579ad8d7eb33059aa8fdbaf5b564411a57f2 (patch)
tree1570cda0676fdcf4171a69a7fe313c1b89a52b0c /vendor/bandit/bandit/context.h
parent986b7742bf244b4073ecca0723615f70be8a1ab6 (diff)
parent4e9b9c402ed95bf9a17fd6d795bc49bb4128a6fa (diff)
Merge branch 'upstream' into debian-cmake-fixes
Diffstat (limited to 'vendor/bandit/bandit/context.h')
-rw-r--r--vendor/bandit/bandit/context.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/vendor/bandit/bandit/context.h b/vendor/bandit/bandit/context.h
new file mode 100644
index 00000000..71194253
--- /dev/null
+++ b/vendor/bandit/bandit/context.h
@@ -0,0 +1,97 @@
+#ifndef BANDIT_CONTEXT_H
+#define BANDIT_CONTEXT_H
+
+namespace bandit {
+ namespace detail {
+
+ class context
+ {
+ public:
+ virtual ~context() {}
+ virtual const std::string& name() = 0;
+ virtual void execution_is_starting() = 0;
+ virtual void register_before_each(voidfunc_t func) = 0;
+ virtual void register_after_each(voidfunc_t func) = 0;
+ virtual void run_before_eaches() = 0;
+ virtual void run_after_eaches() = 0;
+ virtual bool hard_skip() = 0;
+ };
+
+ class bandit_context : public context
+ {
+ public:
+ bandit_context(const char* desc, bool hard_skip_a)
+ : desc_(desc), hard_skip_(hard_skip_a), is_executing_(false)
+ {}
+
+ const std::string& name()
+ {
+ return desc_;
+ }
+
+ void execution_is_starting()
+ {
+ is_executing_ = true;
+ }
+
+ void register_before_each(voidfunc_t func)
+ {
+ if(is_executing_)
+ {
+ throw test_run_error("before_each was called after 'describe' or 'it'");
+ }
+
+ before_eaches_.push_back(func);
+ }
+
+ void register_after_each(voidfunc_t func)
+ {
+ if(is_executing_)
+ {
+ throw test_run_error("after_each was called after 'describe' or 'it'");
+ }
+
+ after_eaches_.push_back(func);
+ }
+
+ void run_before_eaches()
+ {
+ run_all(before_eaches_);
+ }
+
+ void run_after_eaches()
+ {
+ run_all(after_eaches_);
+ }
+
+ bool hard_skip()
+ {
+ return hard_skip_;
+ }
+
+ private:
+ void run_all(const std::list<voidfunc_t>& funcs)
+ {
+ auto call_func = [](voidfunc_t f){ f(); };
+
+ for_each(funcs.begin(), funcs.end(), call_func);
+ }
+
+ private:
+ std::string desc_;
+ bool hard_skip_;
+ bool is_executing_;
+ std::list<voidfunc_t> before_eaches_;
+ std::list<voidfunc_t> after_eaches_;
+ };
+ typedef std::deque<context*> contextstack_t;
+
+ inline contextstack_t& context_stack()
+ {
+ static contextstack_t contexts;
+ return contexts;
+ }
+ }
+}
+
+#endif