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