| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library reflective.tests; | 5 library reflective.tests; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 @MirrorsUsed(metaTargets: 'ReflectiveTestCase') | 9 @MirrorsUsed(metaTargets: 'ReflectiveTestCase') |
| 10 import 'dart:mirrors'; | 10 import 'dart:mirrors'; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 classMirror.instanceMembers.forEach((symbol, memberMirror) { | 42 classMirror.instanceMembers.forEach((symbol, memberMirror) { |
| 43 // we need only methods | 43 // we need only methods |
| 44 if (memberMirror is! MethodMirror || !memberMirror.isRegularMethod) { | 44 if (memberMirror is! MethodMirror || !memberMirror.isRegularMethod) { |
| 45 return; | 45 return; |
| 46 } | 46 } |
| 47 String memberName = MirrorSystem.getName(symbol); | 47 String memberName = MirrorSystem.getName(symbol); |
| 48 // test_ | 48 // test_ |
| 49 if (memberName.startsWith('test_')) { | 49 if (memberName.startsWith('test_')) { |
| 50 String testName = memberName.substring('test_'.length); | 50 String testName = memberName.substring('test_'.length); |
| 51 test(testName, () { | 51 test(testName, () { |
| 52 _runTest(classMirror, symbol); | 52 return _runTest(classMirror, symbol); |
| 53 }); | 53 }); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 // solo_test_ | 56 // solo_test_ |
| 57 if (memberName.startsWith('solo_test_')) { | 57 if (memberName.startsWith('solo_test_')) { |
| 58 String testName = memberName.substring('solo_test_'.length); | 58 String testName = memberName.substring('solo_test_'.length); |
| 59 solo_test(testName, () { | 59 solo_test(testName, () { |
| 60 _runTest(classMirror, symbol); | 60 return _runTest(classMirror, symbol); |
| 61 }); | 61 }); |
| 62 } | 62 } |
| 63 }); | 63 }); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void _runTest(ClassMirror classMirror, Symbol symbol) { | 66 _runTest(ClassMirror classMirror, Symbol symbol) { |
| 67 InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []); | 67 InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []); |
| 68 _invokeSymbolIfExists(instanceMirror, #setUp); | 68 _invokeSymbolIfExists(instanceMirror, #setUp); |
| 69 var testReturn = instanceMirror.invoke(symbol, []).reflectee; | 69 var testReturn = instanceMirror.invoke(symbol, []).reflectee; |
| 70 if (testReturn is Future) { | 70 if (testReturn is Future) { |
| 71 return testReturn.whenComplete(() { | 71 return testReturn.whenComplete(() { |
| 72 _invokeSymbolIfExists(instanceMirror, #tearDown); | 72 _invokeSymbolIfExists(instanceMirror, #tearDown); |
| 73 }); | 73 }); |
| 74 } else { | 74 } else { |
| 75 _invokeSymbolIfExists(instanceMirror, #tearDown); | 75 _invokeSymbolIfExists(instanceMirror, #tearDown); |
| 76 return testReturn; | 76 return testReturn; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 void _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { | 81 void _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { |
| 82 try { | 82 try { |
| 83 instanceMirror.invoke(symbol, []); | 83 instanceMirror.invoke(symbol, []); |
| 84 } on NoSuchMethodError catch (e) { | 84 } on NoSuchMethodError catch (e) { |
| 85 } | 85 } |
| 86 } | 86 } |
| OLD | NEW |