Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: test/codegen/lib/mirrors/mirrors_reader_test.dart

Issue 2265533002: Add mirrors tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Test that everything reachable from a [MirrorSystem] can be accessed.
6
7 library test.mirrors.reader;
8
9 import 'dart:mirrors';
10 import 'package:expect/expect.dart';
11 import 'mirrors_reader.dart';
12
13 class RuntimeMirrorsReader extends MirrorsReader {
14 final MirrorSystem mirrorSystem;
15 final String mirrorSystemType;
16
17 RuntimeMirrorsReader(MirrorSystem mirrorSystem,
18 {bool verbose: false, bool includeStackTrace: false})
19 : this.mirrorSystem = mirrorSystem,
20 this.mirrorSystemType = '${mirrorSystem.runtimeType}',
21 super(verbose: verbose, includeStackTrace: includeStackTrace);
22
23 visitLibraryMirror(LibraryMirror mirror) {
24 super.visitLibraryMirror(mirror);
25 Expect.equals(mirror, mirrorSystem.libraries[mirror.uri]);
26 }
27
28 visitClassMirror(ClassMirror mirror) {
29 super.visitClassMirror(mirror);
30 Expect.isNotNull(mirror.owner);
31 }
32
33 bool allowUnsupported(var receiver, String tag, UnsupportedError exception) {
34 if (mirrorSystemType == '_LocalMirrorSystem') {
35 // VM mirror system.
36 if (tag.endsWith('location')) {
37 return receiver is ParameterMirror;
38 }
39 } else if (mirrorSystemType == 'JsMirrorSystem') {
40 // Dart2js runtime mirror system.
41 if (tag.endsWith('.metadata')) {
42 return true;// Issue 10905.
43 }
44 }
45 return false;
46 }
47
48 bool expectUnsupported(var receiver, String tag, UnsupportedError exception) {
49 // [DeclarationMirror.location] is intentionally not supported in runtime
50 // mirrors.
51
52 if (mirrorSystemType == '_LocalMirrorSystem') {
53 // VM mirror system.
54 } else if (mirrorSystemType == 'JsMirrorSystem') {
55 // Dart2js runtime mirror system.
56 if (receiver is DeclarationMirror && tag == 'location') {
57 return true;
58 }
59 }
60 return false;
61 }
62 }
63
64 void main([List<String> arguments = const <String>[]]) {
65 MirrorSystem mirrors = currentMirrorSystem();
66 MirrorsReader reader = new RuntimeMirrorsReader(mirrors,
67 verbose: arguments.contains('-v'),
68 includeStackTrace: arguments.contains('-s'));
69 reader.checkMirrorSystem(mirrors);
70 }
OLDNEW
« no previous file with comments | « test/codegen/lib/mirrors/mirrors_reader.dart ('k') | test/codegen/lib/mirrors/mirrors_resolve_fields_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698