| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 return _runTest(classMirror, symbol); | 60 return _runTest(classMirror, symbol); |
| 61 }); | 61 }); |
| 62 } | 62 } |
| 63 }); | 63 }); |
| 64 } | 64 } |
| 65 | 65 |
| 66 |
| 66 _runTest(ClassMirror classMirror, Symbol symbol) { | 67 _runTest(ClassMirror classMirror, Symbol symbol) { |
| 67 InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []); | 68 InstanceMirror instanceMirror = classMirror.newInstance(new Symbol(''), []); |
| 69 bool shouldRunTearDown = true; |
| 68 _invokeSymbolIfExists(instanceMirror, #setUp); | 70 _invokeSymbolIfExists(instanceMirror, #setUp); |
| 69 var testReturn = instanceMirror.invoke(symbol, []).reflectee; | 71 try { |
| 70 if (testReturn is Future) { | 72 var testReturn = instanceMirror.invoke(symbol, []).reflectee; |
| 71 return testReturn.whenComplete(() { | 73 if (testReturn is Future) { |
| 72 _invokeSymbolIfExists(instanceMirror, #tearDown); | 74 shouldRunTearDown = false; |
| 73 }); | 75 return testReturn.whenComplete(() { |
| 74 } else { | 76 _invokeTearDown(instanceMirror); |
| 75 _invokeSymbolIfExists(instanceMirror, #tearDown); | 77 }); |
| 76 return testReturn; | 78 } else { |
| 79 return testReturn; |
| 80 } |
| 81 } finally { |
| 82 if (shouldRunTearDown) { |
| 83 _invokeTearDown(instanceMirror); |
| 84 } |
| 77 } | 85 } |
| 78 } | 86 } |
| 79 | 87 |
| 80 | 88 |
| 89 void _invokeTearDown(InstanceMirror instanceMirror) { |
| 90 _invokeSymbolIfExists(instanceMirror, #tearDown); |
| 91 } |
| 92 |
| 93 |
| 81 void _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { | 94 void _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { |
| 82 try { | 95 try { |
| 83 instanceMirror.invoke(symbol, []); | 96 instanceMirror.invoke(symbol, []); |
| 84 } on NoSuchMethodError catch (e) { | 97 } on NoSuchMethodError catch (e) { |
| 85 } | 98 } |
| 86 } | 99 } |
| OLD | NEW |