OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library test.invoke_throws_test; |
| 6 |
| 7 import 'dart:mirrors'; |
| 8 |
| 9 import 'package:expect/expect.dart'; |
| 10 |
| 11 class MyException { |
| 12 } |
| 13 |
| 14 class Class { |
| 15 Class.noException(); |
| 16 Class.generative() { throw new MyException(); } |
| 17 Class.redirecting() : this.generative(); |
| 18 factory Class.faktory() { throw new MyException(); } |
| 19 factory Class.redirectingFactory() = Class.faktory; |
| 20 |
| 21 get getter { throw new MyException(); } |
| 22 set setter(v) { throw new MyException(); } |
| 23 method() { throw new MyException(); } |
| 24 |
| 25 noSuchMethod(invocation) { throw new MyException(); } |
| 26 |
| 27 static get staticGetter { throw new MyException(); } |
| 28 static set staticSetter(v) { throw new MyException(); } |
| 29 static staticFunction() { throw new MyException(); } |
| 30 } |
| 31 |
| 32 get libraryGetter { throw new MyException(); } |
| 33 set librarySetter(v) { throw new MyException(); } |
| 34 libraryFunction() { throw new MyException(); } |
| 35 |
| 36 main() { |
| 37 InstanceMirror im = reflect(new Class.noException()); |
| 38 Expect.throws(() => im.getField(#getter), |
| 39 (e) => e is MyException); |
| 40 Expect.throws(() => im.setField(#setter, ['arg']), |
| 41 (e) => e is MyException); |
| 42 Expect.throws(() => im.invoke(#method, []), |
| 43 (e) => e is MyException); |
| 44 Expect.throws(() => im.invoke(#triggerNoSuchMethod, []), |
| 45 (e) => e is MyException); |
| 46 |
| 47 ClassMirror cm = reflectClass(Class); |
| 48 Expect.throws(() => cm.getField(#staticGetter), |
| 49 (e) => e is MyException); |
| 50 Expect.throws(() => cm.setField(#staticSetter, ['arg']), |
| 51 (e) => e is MyException); |
| 52 Expect.throws(() => cm.invoke(#staticFunction, []), |
| 53 (e) => e is MyException); |
| 54 Expect.throws(() => cm.newInstance(#generative, []), |
| 55 (e) => e is MyException); |
| 56 Expect.throws(() => cm.newInstance(#redirecting, []), |
| 57 (e) => e is MyException); |
| 58 Expect.throws(() => cm.newInstance(#faktory, []), |
| 59 (e) => e is MyException); |
| 60 Expect.throws(() => cm.newInstance(#redirectingFactory, []), |
| 61 (e) => e is MyException); |
| 62 |
| 63 LibraryMirror lm = reflectClass(Class).owner; |
| 64 Expect.throws(() => lm.getField(#libraryGetter), |
| 65 (e) => e is MyException); |
| 66 Expect.throws(() => lm.setField(#librarySetter, ['arg']), |
| 67 (e) => e is MyException); |
| 68 Expect.throws(() => lm.invoke(#libraryFunction, []), |
| 69 (e) => e is MyException); |
| 70 } |
OLD | NEW |