@@ -106,6 +106,55 @@ class UnitTest {
106
106
virtual void invoke (Arguments &arguments) = 0;
107
107
};
108
108
109
+ class UnitTestRunner : public SILFunctionTransform {
110
+ void printTestLifetime (bool begin, unsigned testIndex, unsigned testCount,
111
+ StringRef name, ArrayRef<StringRef> components) {
112
+ StringRef word = begin ? " begin" : " end" ;
113
+ llvm::errs () << word << " running test " << testIndex + 1 << " of "
114
+ << testCount << " on " << getFunction ()->getName () << " : "
115
+ << name << " with: " ;
116
+ for (unsigned long index = 0 , size = components.size (); index < size;
117
+ ++index) {
118
+ llvm::errs () << components[index];
119
+ if (index != size - 1 ) {
120
+ llvm::errs () << " , " ;
121
+ }
122
+ }
123
+ llvm::errs () << " \n " ;
124
+ }
125
+
126
+ template <typename Doit>
127
+ void withTest (StringRef name, Doit doit);
128
+
129
+ void runTest (StringRef name, Arguments &arguments) {
130
+ withTest (name, [&](auto *test) { test->invoke (arguments); });
131
+ }
132
+
133
+ void run () override {
134
+ llvm::SmallVector<std::string, 2 > testSpecifications;
135
+ getTestSpecifications (getFunction (), testSpecifications);
136
+ Arguments arguments;
137
+ SmallVector<StringRef, 4 > components;
138
+ for (unsigned long index = 0 , size = testSpecifications.size ();
139
+ index < size; ++index) {
140
+ components.clear ();
141
+ arguments.clear ();
142
+ auto testSpecification = testSpecifications[index];
143
+ test::parseTestArgumentsFromSpecification (
144
+ getFunction (), testSpecification, arguments, components);
145
+ auto name = arguments.takeString ();
146
+ ArrayRef<StringRef> argumentStrings = components;
147
+ argumentStrings = argumentStrings.drop_front ();
148
+ printTestLifetime (/* begin=*/ true , /* index=*/ index, /* size=*/ size, name,
149
+ argumentStrings);
150
+ runTest (name, arguments);
151
+ printTestLifetime (/* begin=*/ false , /* index=*/ index, /* size=*/ size, name,
152
+ argumentStrings);
153
+ }
154
+ }
155
+ friend class UnitTest ;
156
+ };
157
+
109
158
// Arguments:
110
159
// - string: list of characters, each of which specifies subsequent arguments
111
160
// - F: function
@@ -276,25 +325,8 @@ struct IsDeinitBarrierTest : UnitTest {
276
325
277
326
// / [new_tests] Add the new UnitTest subclass above this line.
278
327
279
- class UnitTestRunner : public SILFunctionTransform {
280
- void printTestLifetime (bool begin, unsigned testIndex, unsigned testCount,
281
- StringRef name, ArrayRef<StringRef> components) {
282
- StringRef word = begin ? " begin" : " end" ;
283
- llvm::errs () << word << " running test " << testIndex + 1 << " of "
284
- << testCount << " on " << getFunction ()->getName () << " : "
285
- << name << " with: " ;
286
- for (unsigned long index = 0 , size = components.size (); index < size;
287
- ++index) {
288
- llvm::errs () << components[index];
289
- if (index != size - 1 ) {
290
- llvm::errs () << " , " ;
291
- }
292
- }
293
- llvm::errs () << " \n " ;
294
- }
295
-
296
- template <typename Doit>
297
- void withTest (StringRef name, Doit doit) {
328
+ template <typename Doit>
329
+ void UnitTestRunner::withTest (StringRef name, Doit doit) {
298
330
#define ADD_UNIT_TEST_SUBCLASS (STRING, SUBCLASS ) \
299
331
if (name == STRING) { \
300
332
SUBCLASS it{this }; \
@@ -320,35 +352,7 @@ class UnitTestRunner : public SILFunctionTransform {
320
352
#undef ADD_UNIT_TEST_SUBCLASS
321
353
}
322
354
323
- void runTest (StringRef name, Arguments &arguments) {
324
- withTest (name, [&](auto *test) { test->invoke (arguments); });
325
- }
326
-
327
- void run () override {
328
- llvm::SmallVector<UnparsedSpecification, 2 > testSpecifications;
329
- getTestSpecifications (getFunction (), testSpecifications);
330
- Arguments arguments;
331
- SmallVector<StringRef, 4 > components;
332
- for (unsigned long index = 0 , size = testSpecifications.size ();
333
- index < size; ++index) {
334
- components.clear ();
335
- arguments.clear ();
336
- auto testSpecification = testSpecifications[index];
337
- test::parseTestArgumentsFromSpecification (
338
- getFunction (), testSpecification, arguments, components);
339
- auto name = arguments.takeString ();
340
- ArrayRef<StringRef> argumentStrings = components;
341
- argumentStrings = argumentStrings.drop_front ();
342
- printTestLifetime (/* begin=*/ true , /* index=*/ index, /* size=*/ size, name,
343
- argumentStrings);
344
- runTest (name, arguments);
345
- printTestLifetime (/* begin=*/ false , /* index=*/ index, /* size=*/ size, name,
346
- argumentStrings);
347
- }
348
- }
349
- friend class UnitTest ;
350
- };
351
-
355
+ llvm::SmallVector<std::string, 2 > testSpecifications;
352
356
template <typename Analysis>
353
357
Analysis *UnitTest::getAnalysis () {
354
358
return pass->getAnalysis <Analysis>();
0 commit comments