@@ -107,6 +107,55 @@ class UnitTest {
107
107
virtual void invoke (Arguments &arguments) = 0;
108
108
};
109
109
110
+ class UnitTestRunner : public SILFunctionTransform {
111
+ void printTestLifetime (bool begin, unsigned testIndex, unsigned testCount,
112
+ StringRef name, ArrayRef<StringRef> components) {
113
+ StringRef word = begin ? " begin" : " end" ;
114
+ llvm::errs () << word << " running test " << testIndex + 1 << " of "
115
+ << testCount << " on " << getFunction ()->getName () << " : "
116
+ << name << " with: " ;
117
+ for (unsigned long index = 0 , size = components.size (); index < size;
118
+ ++index) {
119
+ llvm::errs () << components[index];
120
+ if (index != size - 1 ) {
121
+ llvm::errs () << " , " ;
122
+ }
123
+ }
124
+ llvm::errs () << " \n " ;
125
+ }
126
+
127
+ template <typename Doit>
128
+ void withTest (StringRef name, Doit doit);
129
+
130
+ void runTest (StringRef name, Arguments &arguments) {
131
+ withTest (name, [&](auto *test) { test->invoke (arguments); });
132
+ }
133
+
134
+ void run () override {
135
+ llvm::SmallVector<UnparsedSpecification, 2 > testSpecifications;
136
+ getTestSpecifications (getFunction (), testSpecifications);
137
+ Arguments arguments;
138
+ SmallVector<StringRef, 4 > components;
139
+ for (unsigned long index = 0 , size = testSpecifications.size ();
140
+ index < size; ++index) {
141
+ components.clear ();
142
+ arguments.clear ();
143
+ auto testSpecification = testSpecifications[index];
144
+ test::parseTestArgumentsFromSpecification (
145
+ getFunction (), testSpecification, arguments, components);
146
+ auto name = arguments.takeString ();
147
+ ArrayRef<StringRef> argumentStrings = components;
148
+ argumentStrings = argumentStrings.drop_front ();
149
+ printTestLifetime (/* begin=*/ true , /* index=*/ index, /* size=*/ size, name,
150
+ argumentStrings);
151
+ runTest (name, arguments);
152
+ printTestLifetime (/* begin=*/ false , /* index=*/ index, /* size=*/ size, name,
153
+ argumentStrings);
154
+ }
155
+ }
156
+ friend class UnitTest ;
157
+ };
158
+
110
159
// Arguments:
111
160
// - string: list of characters, each of which specifies subsequent arguments
112
161
// - A: (block) argument
@@ -314,25 +363,8 @@ struct ShrinkBorrowScopeTest : UnitTest {
314
363
315
364
// / [new_tests] Add the new UnitTest subclass above this line.
316
365
317
- class UnitTestRunner : public SILFunctionTransform {
318
- void printTestLifetime (bool begin, unsigned testIndex, unsigned testCount,
319
- StringRef name, ArrayRef<StringRef> components) {
320
- StringRef word = begin ? " begin" : " end" ;
321
- llvm::errs () << word << " running test " << testIndex + 1 << " of "
322
- << testCount << " on " << getFunction ()->getName () << " : "
323
- << name << " with: " ;
324
- for (unsigned long index = 0 , size = components.size (); index < size;
325
- ++index) {
326
- llvm::errs () << components[index];
327
- if (index != size - 1 ) {
328
- llvm::errs () << " , " ;
329
- }
330
- }
331
- llvm::errs () << " \n " ;
332
- }
333
-
334
- template <typename Doit>
335
- void withTest (StringRef name, Doit doit) {
366
+ template <typename Doit>
367
+ void UnitTestRunner::withTest (StringRef name, Doit doit) {
336
368
#define ADD_UNIT_TEST_SUBCLASS (STRING, SUBCLASS ) \
337
369
if (name == STRING) { \
338
370
SUBCLASS it{this }; \
@@ -359,34 +391,6 @@ class UnitTestRunner : public SILFunctionTransform {
359
391
#undef ADD_UNIT_TEST_SUBCLASS
360
392
}
361
393
362
- void runTest (StringRef name, Arguments &arguments) {
363
- withTest (name, [&](auto *test) { test->invoke (arguments); });
364
- }
365
-
366
- void run () override {
367
- llvm::SmallVector<UnparsedSpecification, 2 > testSpecifications;
368
- getTestSpecifications (getFunction (), testSpecifications);
369
- Arguments arguments;
370
- SmallVector<StringRef, 4 > components;
371
- for (unsigned long index = 0 , size = testSpecifications.size ();
372
- index < size; ++index) {
373
- components.clear ();
374
- arguments.clear ();
375
- auto testSpecification = testSpecifications[index];
376
- test::parseTestArgumentsFromSpecification (
377
- getFunction (), testSpecification, arguments, components);
378
- auto name = arguments.takeString ();
379
- ArrayRef<StringRef> argumentStrings = components;
380
- argumentStrings = argumentStrings.drop_front ();
381
- printTestLifetime (/* begin=*/ true , /* index=*/ index, /* size=*/ size, name,
382
- argumentStrings);
383
- runTest (name, arguments);
384
- printTestLifetime (/* begin=*/ false , /* index=*/ index, /* size=*/ size, name,
385
- argumentStrings);
386
- }
387
- }
388
- friend class UnitTest ;
389
- };
390
394
391
395
template <typename Analysis>
392
396
Analysis *UnitTest::getAnalysis () {
0 commit comments