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

Side by Side Diff: tests/utils/analyze_only_test.dart

Issue 11882017: Add --analyze-only flag to dart2js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add analyze_only_test Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 // Smoke test of the dart2js compiler API.
6 library dummy_compiler;
ahe 2013/01/24 10:16:33 Rename?
Johnni Winther 2013/01/24 11:21:51 Done.
7
8 import 'dart:async';
9 import 'dart:uri';
10
11 import '../../sdk/lib/_internal/compiler/compiler.dart';
12
13 Future<String> provider(Uri uri, String mainSource) {
ahe 2013/01/24 10:16:33 Can you import this from dummy_compiler_test?
Johnni Winther 2013/01/24 11:21:51 Done.
14 Completer<String> completer = new Completer<String>();
15 String source;
16 if (uri.scheme == "main") {
17 source = mainSource;
18 } else if (uri.scheme == "lib") {
19 if (uri.path.endsWith("/core.dart")) {
20 source = """library core;
21 class Object {}
22 class Type {}
23 class bool {}
24 class num {}
25 class int {}
26 class double{}
27 class String{}
28 class Function{}
29 class List {}
30 class Map {}
31 class Closure {}
32 class Dynamic_ {}
33 class Null {}
34 getRuntimeTypeInfo(o) {}
35 setRuntimeTypeInfo(o, i) {}
36 eqNull(a) {}
37 eqNullB(a) {}""";
38 } else if (uri.path.endsWith('_patch.dart')) {
39 source = '';
40 } else if (uri.path.endsWith('interceptors.dart')) {
41 source = """class ObjectInterceptor {}
42 class JSArray {
43 var length;
44 var removeLast;
45 var add;
46 }
47 class JSString {
48 var length;
49 var split;
50 var concat;
51 }
52 class JSFunction {}
53 class JSInt {}
54 class JSDouble {}
55 class JSNumber {}
56 class JSNull {}
57 class JSBool {}
58 var getInterceptor;""";
59 } else if (uri.path.endsWith('js_helper.dart')) {
60 source = 'library jshelper; class JSInvocationMirror {}';
61 } else if (uri.path.endsWith('isolate_helper.dart')) {
62 source = 'library isolatehelper; class _WorkerStub {}';
63 } else {
64 source = "library lib;";
65 }
66 } else {
67 throw "unexpected URI $uri";
68 }
69 completer.complete(source);
70 return completer.future;
71 }
72
73 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) {
74 if (uri == null) {
75 print('$kind: $message');
76 } else {
77 print('$uri:$begin:$end: $kind: $message');
78 }
79 }
80
81 runCompiler(String main, List<String> options,
82 onValue(String code, List errors, List warnings)) {
83 List errors = new List();
84 List warnings = new List();
85
86 Future<String> localProvider(Uri uri) {
87 return provider(uri, main);
88 }
89
90 void localHandler(Uri uri, int begin, int end,
91 String message, Diagnostic kind) {
92 handler(uri, begin, end, message, kind);
93 if (kind == Diagnostic.ERROR) {
94 errors.add(message);
95 } else if (kind == Diagnostic.WARNING) {
96 warnings.add(message);
97 }
98 }
99
100 print('-----------------------------------------------');
101 print('main source:\n$main');
102 print('options: $options\n');
103 Future<String> result =
104 compile(new Uri.fromComponents(scheme: 'main'),
105 new Uri.fromComponents(scheme: 'lib', path: '/'),
106 new Uri.fromComponents(scheme: 'package', path: '/'),
107 localProvider, localHandler, options);
108 result.then((String code) {
109 onValue(code, errors, warnings);
110 }, onError: (AsyncError e) {
111 throw 'Compilation failed';
112 });
113 }
114
115 main() {
116 runCompiler(
117 "",
118 [],
119 (String code, List errors, List warnings) {
120 Expect.isNull(code);
121 Expect.equals(1, errors.length);
122 Expect.equals('Could not find main', errors[0].toString());
123 Expect.isTrue(warnings.isEmpty);
124 });
125
126 runCompiler(
127 "main() {}",
128 [],
129 (String code, List errors, List warnings) {
130 Expect.isNotNull(code);
131 Expect.isTrue(errors.isEmpty);
132 Expect.isTrue(warnings.isEmpty);
133 });
134
135 runCompiler(
136 "",
137 ['--analyze-only'],
138 (String code, List errors, List warnings) {
139 Expect.isNull(code);
140 Expect.equals(1, errors.length);
141 Expect.isTrue(errors[0].toString().startsWith('Could not find main'));
142 Expect.isTrue(warnings.isEmpty);
143 });
144
145 runCompiler(
146 "main() {}",
147 ['--analyze-only'],
148 (String code, List errors, List warnings) {
149 Expect.isNull(code);
150 Expect.isTrue(errors.isEmpty);
151 Expect.isTrue(warnings.isEmpty);
152 });
153
154 runCompiler(
155 "Foo foo; // Unresolved but not analyzed.",
156 ['--analyze-only'],
157 (String code, List errors, List warnings) {
158 Expect.isNull(code);
159 Expect.equals(1, errors.length);
160 Expect.isTrue(errors[0].toString().startsWith('Could not find main'));
161 Expect.isTrue(warnings.isEmpty);
162 });
163
164 runCompiler(
165 """main() {
166 Foo foo; // Unresolved and analyzed.
167 }""",
168 ['--analyze-only'],
169 (String code, List errors, List warnings) {
170 Expect.isNull(code);
171 Expect.isTrue(errors.isEmpty);
172 Expect.equals(1, warnings.length);
173 Expect.equals('Warning: cannot resolve type Foo', warnings[0].toString());
174 });
175
176 runCompiler(
177 "Foo foo; // Unresolved and analyzed.",
178 ['--analyze-only', '--analyze-all'],
179 (String code, List errors, List warnings) {
180 Expect.isNull(code);
181 Expect.isTrue(errors.isEmpty);
182 Expect.equals('Warning: cannot resolve type Foo', warnings[0].toString());
183 });
184
185 runCompiler(
186 """Foo foo; // Unresolved and analyzed.
187 main() {}""",
188 ['--analyze-only', '--analyze-all'],
189 (String code, List errors, List warnings) {
190 Expect.isNull(code);
191 Expect.isTrue(errors.isEmpty);
192 Expect.equals(1, warnings.length);
193 Expect.equals('Warning: cannot resolve type Foo', warnings[0].toString());
194 });
195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698