@@ -18,40 +18,49 @@ class ClassDescription : public Description {
18
18
typedef std::function<void (ClassDescription<T>&)> block_t ;
19
19
block_t body;
20
20
bool first;
21
+ std::string type = " " ;
21
22
22
23
public:
23
24
T subject; // subject field public for usage in `expect([self.]subject)`
24
25
25
26
// Constructor
26
27
// if there's no explicit subject given, then use
27
28
// the default constructor of the given type as the implicit subject.
28
- ClassDescription<T>(block_t body) : Description(), body(body), subject(T()) {
29
- this ->descr = Pretty::to_word_type (subject);
29
+ ClassDescription<T>(block_t body)
30
+ : Description(),
31
+ body (body),
32
+ type(" : " + Util::demangle(typeid (T).name())),
33
+ subject(T()) {
34
+ this ->descr = Pretty::to_word (subject);
30
35
};
31
36
32
37
ClassDescription<T>(std::string descr, block_t body)
33
38
: Description(descr), body(body), subject(T()){};
34
39
35
40
ClassDescription (T subject, block_t body)
36
- : Description(Pretty::to_word_type (subject)),
41
+ : Description(Pretty::to_word (subject)),
37
42
body (body),
43
+ type(" : " + Util::demangle(typeid (T).name())),
38
44
subject(subject){};
39
45
40
46
ClassDescription (std::string descr, T subject, block_t body)
41
47
: Description(descr), body(body), subject(subject){};
42
48
43
49
ClassDescription (T& subject, block_t body)
44
- : Description(Pretty::to_word_type (subject)),
50
+ : Description(Pretty::to_word (subject)),
45
51
body(body),
52
+ type(" : " + Util::demangle(typeid (T).name())),
46
53
subject(subject){};
47
54
48
55
ClassDescription (std::string descr, T& subject, block_t body)
49
56
: Description(descr), body(body), subject(subject){};
50
57
51
58
template <typename U>
52
59
ClassDescription (std::initializer_list<U> init_list, block_t body)
53
- : body(body), subject(T(init_list)) {
54
- this ->descr = Pretty::to_word_type (subject);
60
+ : body(body),
61
+ type(" : " + Util::demangle(typeid (T).name())),
62
+ subject(T(init_list)) {
63
+ this ->descr = Pretty::to_word (subject);
55
64
};
56
65
57
66
template <typename U>
@@ -68,7 +77,9 @@ class ClassDescription : public Description {
68
77
Result context (T subject, block_t body);
69
78
Result context (T& subject, block_t body);
70
79
Result context (block_t body);
71
- Result run () override ;
80
+ Result run (BasePrinter& printer) override ;
81
+ virtual std::string get_descr () override ;
82
+ virtual const std::string get_descr () const override ;
72
83
};
73
84
74
85
template <class T >
@@ -81,7 +92,7 @@ Result ClassDescription<T>::context(
81
92
context.set_parent (this );
82
93
context.before_eaches = this ->before_eaches ;
83
94
context.after_eaches = this ->after_eaches ;
84
- return context.run ();
95
+ return context.run (this -> get_printer () );
85
96
}
86
97
87
98
template <class T >
@@ -97,7 +108,7 @@ Result ClassDescription<T>::context(
97
108
context.set_parent (this );
98
109
context.before_eaches = this ->before_eaches ;
99
110
context.after_eaches = this ->after_eaches ;
100
- return context.run ();
111
+ return context.run (this -> get_printer () );
101
112
}
102
113
103
114
template <class T >
@@ -108,7 +119,7 @@ Result Description::context(T subject,
108
119
context.set_parent (this );
109
120
context.before_eaches = this ->before_eaches ;
110
121
context.after_eaches = this ->after_eaches ;
111
- return context.run ();
122
+ return context.run (this -> get_printer () );
112
123
}
113
124
114
125
// template <class T>
@@ -124,7 +135,7 @@ Result Description::context(std::initializer_list<U> init_list,
124
135
context.set_parent (this );
125
136
context.before_eaches = this ->before_eaches ;
126
137
context.after_eaches = this ->after_eaches ;
127
- return context.run ();
138
+ return context.run (this -> get_printer () );
128
139
}
129
140
130
141
/* *
@@ -152,7 +163,7 @@ template <class T>
152
163
Result ClassDescription<T>::it(std::string name,
153
164
std::function<void (ItCd<T>&)> body) {
154
165
ItCd<T> it (*this , this ->subject , name, body);
155
- Result result = it.run ();
166
+ Result result = it.run (this -> get_printer () );
156
167
exec_after_eaches ();
157
168
exec_before_eaches ();
158
169
return result;
@@ -182,19 +193,39 @@ Result ClassDescription<T>::it(std::string name,
182
193
template <class T >
183
194
Result ClassDescription<T>::it(std::function<void (ItCd<T>&)> body) {
184
195
ItCd<T> it (*this , this ->subject , body);
185
- Result result = it.run ();
196
+ Result result = it.run (this -> get_printer () );
186
197
exec_after_eaches ();
187
198
exec_before_eaches ();
188
199
return result;
189
200
}
190
201
191
202
template <class T >
192
- Result ClassDescription<T>::run() {
193
- std::cout << padding () << descr << std::endl;
203
+ Result ClassDescription<T>::run(BasePrinter& printer) {
204
+ if (not this ->has_printer ()) this ->set_printer (printer);
205
+ printer.print (*this );
194
206
body (*this );
195
- std::cout << std::endl;
207
+ for (auto a : after_alls) a ();
208
+ if (this ->get_parent () == nullptr ) printer.flush ();
196
209
return this ->get_status () ? Result::success : Result::failure;
197
210
}
211
+ template <class T >
212
+ std::string ClassDescription<T>::get_descr() {
213
+ if (this ->get_printer ().mode == BasePrinter::Mode::TAP) {
214
+ return descr;
215
+ } else {
216
+ return descr + type;
217
+ }
218
+ }
219
+
220
+ template <class T >
221
+ const std::string ClassDescription<T>::get_descr() const {
222
+ if (const_cast <ClassDescription<T>*>(this )->get_printer ().mode ==
223
+ BasePrinter::Mode::TAP) {
224
+ return descr;
225
+ } else {
226
+ return descr + type;
227
+ }
228
+ }
198
229
199
230
template <class T >
200
231
Expectations::Expectation<T> ItCd<T>::is_expected() {
@@ -204,11 +235,18 @@ Expectations::Expectation<T> ItCd<T>::is_expected() {
204
235
}
205
236
206
237
template <class T >
207
- Result ItCd<T>::run() {
208
- if (!this ->needs_descr ()) {
209
- std::cout << padding () << get_descr () << std::endl ;
238
+ Result ItCd<T>::run(BasePrinter& printer ) {
239
+ if (!this ->needs_descr () && printer. mode == BasePrinter::Mode::verbose ) {
240
+ printer. print (* this ) ;
210
241
}
242
+
211
243
body (*this );
244
+
245
+ if (printer.mode == BasePrinter::Mode::TAP ||
246
+ printer.mode == BasePrinter::Mode::terse) {
247
+ printer.print (*this );
248
+ }
249
+
212
250
auto cd = static_cast <ClassDescription<T>*>(this ->get_parent ());
213
251
cd->reset_lets ();
214
252
return this ->get_status () ? Result::success : Result::failure;
0 commit comments