Skip to content

Commit 897bcab

Browse files
committed
Result types, ignored failures, and more
1 parent 1ee1748 commit 897bcab

File tree

16 files changed

+263
-127
lines changed

16 files changed

+263
-127
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "include/cxx-prettyprint"]
22
path = include/cxx-prettyprint
33
url = https://github.com/louisdx/cxx-prettyprint.git
4+
[submodule "include/optional"]
5+
path = include/optional
6+
url = https://github.com/akrzemi1/Optional

include/class_description.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ class ClassDescription : public Description {
6363

6464
const bool has_subject = true;
6565

66-
bool it(std::string descr, std::function<void(ItCd<T>&)> body);
67-
bool it(std::function<void(ItCd<T>&)> body);
68-
bool context(T subject, block_t body);
69-
bool context(T& subject, block_t body);
70-
bool context(block_t body);
71-
bool run();
66+
Result it(std::string descr, std::function<void(ItCd<T>&)> body);
67+
Result it(std::function<void(ItCd<T>&)> body);
68+
Result context(T subject, block_t body);
69+
Result context(T& subject, block_t body);
70+
Result context(block_t body);
71+
Result run() override;
7272
};
7373

7474
template <class T>
7575
using ClassContext = ClassDescription<T>;
7676

7777
template <class T>
78-
bool ClassDescription<T>::context(T subject,
79-
std::function<void(ClassDescription&)> body) {
78+
Result ClassDescription<T>::context(T subject,
79+
std::function<void(ClassDescription&)> body) {
8080
ClassContext<T> context(subject, body);
8181
context.set_parent(this);
8282
context.before_eaches = this->before_eaches;
@@ -85,13 +85,13 @@ bool ClassDescription<T>::context(T subject,
8585
}
8686

8787
template <class T>
88-
bool ClassDescription<T>::context(T& subject,
88+
Result ClassDescription<T>::context(T& subject,
8989
std::function<void(ClassDescription&)> body) {
9090
return context(subject, body);
9191
}
9292

9393
template <class T>
94-
bool ClassDescription<T>::context(std::function<void(ClassDescription&)> body) {
94+
Result ClassDescription<T>::context(std::function<void(ClassDescription&)> body) {
9595
ClassContext<T> context(body);
9696
context.set_parent(this);
9797
context.before_eaches = this->before_eaches;
@@ -100,8 +100,8 @@ bool ClassDescription<T>::context(std::function<void(ClassDescription&)> body) {
100100
}
101101

102102
template <class T>
103-
bool Description::context(T subject,
104-
std::function<void(ClassDescription<T>&)> body) {
103+
Result Description::context(T subject,
104+
std::function<void(ClassDescription<T>&)> body) {
105105
ClassContext<T> context(body);
106106
context.subject = subject;
107107
context.set_parent(this);
@@ -117,7 +117,7 @@ bool Description::context(T subject,
117117
// }
118118

119119
template <class T, typename U>
120-
bool Description::context(std::initializer_list<U> init_list,
120+
Result Description::context(std::initializer_list<U> init_list,
121121
std::function<void(ClassDescription<T>&)> body) {
122122
ClassContext<T> context(T(init_list), body);
123123
context.set_parent(this);
@@ -148,10 +148,10 @@ bool Description::context(std::initializer_list<U> init_list,
148148
* @return the result of the test
149149
*/
150150
template <class T>
151-
bool ClassDescription<T>::it(std::string name,
151+
Result ClassDescription<T>::it(std::string name,
152152
std::function<void(ItCd<T>&)> body) {
153153
ItCd<T> it(*this, this->subject, name, body);
154-
bool result = it.run();
154+
Result result = it.run();
155155
exec_after_eaches();
156156
exec_before_eaches();
157157
return result;
@@ -179,20 +179,20 @@ bool ClassDescription<T>::it(std::string name,
179179
* @return the result of the test
180180
*/
181181
template <class T>
182-
bool ClassDescription<T>::it(std::function<void(ItCd<T>&)> body) {
182+
Result ClassDescription<T>::it(std::function<void(ItCd<T>&)> body) {
183183
ItCd<T> it(*this, this->subject, body);
184-
bool result = it.run();
184+
Result result = it.run();
185185
exec_after_eaches();
186186
exec_before_eaches();
187187
return result;
188188
}
189189

190190
template <class T>
191-
bool ClassDescription<T>::run() {
191+
Result ClassDescription<T>::run() {
192192
std::cout << padding() << descr << std::endl;
193193
body(*this);
194194
std::cout << std::endl;
195-
return this->get_status();
195+
return Result(this->get_status());
196196
}
197197

198198
template <class T>
@@ -203,14 +203,14 @@ Expectations::Expectation<T> ItCd<T>::is_expected() {
203203
}
204204

205205
template <class T>
206-
bool ItCd<T>::run() {
206+
Result ItCd<T>::run() {
207207
if (!this->needs_descr()) {
208208
std::cout << padding() << get_descr() << std::endl;
209209
}
210210
body(*this);
211211
auto cd = static_cast<ClassDescription<T>*>(this->get_parent());
212212
cd->reset_lets();
213-
return this->get_status();
213+
return Result(this->get_status());
214214
}
215215

216216
#endif /* CLASS_DESCRIPTION_H */

include/description.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ class Description : public Runnable {
3535
const bool has_subject = false;
3636

3737
// Spec functions
38-
bool it(std::string descr, std::function<void(ItD &)> body);
39-
bool it(std::function<void(ItD &)> body);
40-
bool context(std::string descr, block_t body);
38+
Result it(std::string descr, std::function<void(ItD &)> body);
39+
Result it(std::function<void(ItD &)> body);
40+
Result context(std::string descr, block_t body);
4141

4242
template <class T>
43-
bool context(T subject, std::function<void(ClassDescription<T> &)> body);
43+
Result context(T subject, std::function<void(ClassDescription<T> &)> body);
4444

4545
// template <class T>
4646
// bool context(T &subject, std::function<void(ClassDescription<T> &)> body);
4747

4848
template <class T, typename U>
49-
bool context(std::initializer_list<U> init_list,
50-
std::function<void(ClassDescription<T> &)> body);
49+
Result context(std::initializer_list<U> init_list,
50+
std::function<void(ClassDescription<T> &)> body);
5151

5252
// template <class T>
5353
// ClassDescription<T> subject(T subject);
@@ -67,32 +67,32 @@ class Description : public Runnable {
6767
void exec_after_eaches();
6868

6969
void let(std::string, Runnable &body);
70-
bool run();
70+
Result run() override;
7171
void reset_lets();
7272
Runnable *find_let(std::string);
7373
};
7474

7575
typedef Description Context;
7676

77-
bool Description::context(std::string name,
77+
Result Description::context(std::string name,
7878
std::function<void(Description &)> body) {
7979
Context context(*this, name, body);
8080
context.before_eaches = this->before_eaches;
8181
context.after_eaches = this->after_eaches;
8282
return context.run();
8383
}
8484

85-
bool Description::it(std::string name, std::function<void(ItD &)> body) {
85+
Result Description::it(std::string name, std::function<void(ItD &)> body) {
8686
ItD it(*this, name, body);
87-
bool result = it.run();
87+
Result result = it.run();
8888
exec_after_eaches();
8989
exec_before_eaches();
9090
return result;
9191
}
9292

93-
bool Description::it(std::function<void(ItD &)> body) {
93+
Result Description::it(std::function<void(ItD &)> body) {
9494
ItD it(*this, body);
95-
bool result = it.run();
95+
Result result = it.run();
9696
exec_after_eaches();
9797
exec_before_eaches();
9898
return result;
@@ -144,12 +144,12 @@ void Description::let(std::string name, Runnable &body) {
144144
lets.insert({name, &body});
145145
}
146146

147-
bool Description::run() {
147+
Result Description::run() {
148148
std::cout << padding() << descr << std::endl;
149149
body(*this);
150150
for (auto a : after_alls) a();
151151
std::cout << std::endl;
152-
return this->get_status();
152+
return Result(this->get_status());
153153
}
154154

155155
void Description::reset_lets() {
@@ -188,7 +188,7 @@ Expectations::Expectation<T> ItExpBase::expect(Let<T> let) {
188188
return expectation;
189189
}
190190

191-
bool ItD::run() {
191+
Result ItD::run() {
192192
if (!this->needs_descr()) {
193193
std::cout << padding() << get_descr() << std::endl;
194194
}
@@ -197,7 +197,7 @@ bool ItD::run() {
197197
auto parent = static_cast<Description *>(this->get_parent());
198198
parent->reset_lets();
199199

200-
return this->get_status();
200+
return Result(this->get_status());
201201
}
202202

203203
#endif /* DESCRIPTION_H */

0 commit comments

Comments
 (0)