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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: tests/utils/analyze_only_test.dart
diff --git a/tests/utils/analyze_only_test.dart b/tests/utils/analyze_only_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3809d1c4a3709de6524a1236b158d60ea4b2a3d7
--- /dev/null
+++ b/tests/utils/analyze_only_test.dart
@@ -0,0 +1,195 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Smoke test of the dart2js compiler API.
+library dummy_compiler;
ahe 2013/01/24 10:16:33 Rename?
Johnni Winther 2013/01/24 11:21:51 Done.
+
+import 'dart:async';
+import 'dart:uri';
+
+import '../../sdk/lib/_internal/compiler/compiler.dart';
+
+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.
+ Completer<String> completer = new Completer<String>();
+ String source;
+ if (uri.scheme == "main") {
+ source = mainSource;
+ } else if (uri.scheme == "lib") {
+ if (uri.path.endsWith("/core.dart")) {
+ source = """library core;
+ class Object {}
+ class Type {}
+ class bool {}
+ class num {}
+ class int {}
+ class double{}
+ class String{}
+ class Function{}
+ class List {}
+ class Map {}
+ class Closure {}
+ class Dynamic_ {}
+ class Null {}
+ getRuntimeTypeInfo(o) {}
+ setRuntimeTypeInfo(o, i) {}
+ eqNull(a) {}
+ eqNullB(a) {}""";
+ } else if (uri.path.endsWith('_patch.dart')) {
+ source = '';
+ } else if (uri.path.endsWith('interceptors.dart')) {
+ source = """class ObjectInterceptor {}
+ class JSArray {
+ var length;
+ var removeLast;
+ var add;
+ }
+ class JSString {
+ var length;
+ var split;
+ var concat;
+ }
+ class JSFunction {}
+ class JSInt {}
+ class JSDouble {}
+ class JSNumber {}
+ class JSNull {}
+ class JSBool {}
+ var getInterceptor;""";
+ } else if (uri.path.endsWith('js_helper.dart')) {
+ source = 'library jshelper; class JSInvocationMirror {}';
+ } else if (uri.path.endsWith('isolate_helper.dart')) {
+ source = 'library isolatehelper; class _WorkerStub {}';
+ } else {
+ source = "library lib;";
+ }
+ } else {
+ throw "unexpected URI $uri";
+ }
+ completer.complete(source);
+ return completer.future;
+}
+
+void handler(Uri uri, int begin, int end, String message, Diagnostic kind) {
+ if (uri == null) {
+ print('$kind: $message');
+ } else {
+ print('$uri:$begin:$end: $kind: $message');
+ }
+}
+
+runCompiler(String main, List<String> options,
+ onValue(String code, List errors, List warnings)) {
+ List errors = new List();
+ List warnings = new List();
+
+ Future<String> localProvider(Uri uri) {
+ return provider(uri, main);
+ }
+
+ void localHandler(Uri uri, int begin, int end,
+ String message, Diagnostic kind) {
+ handler(uri, begin, end, message, kind);
+ if (kind == Diagnostic.ERROR) {
+ errors.add(message);
+ } else if (kind == Diagnostic.WARNING) {
+ warnings.add(message);
+ }
+ }
+
+ print('-----------------------------------------------');
+ print('main source:\n$main');
+ print('options: $options\n');
+ Future<String> result =
+ compile(new Uri.fromComponents(scheme: 'main'),
+ new Uri.fromComponents(scheme: 'lib', path: '/'),
+ new Uri.fromComponents(scheme: 'package', path: '/'),
+ localProvider, localHandler, options);
+ result.then((String code) {
+ onValue(code, errors, warnings);
+ }, onError: (AsyncError e) {
+ throw 'Compilation failed';
+ });
+}
+
+main() {
+ runCompiler(
+ "",
+ [],
+ (String code, List errors, List warnings) {
+ Expect.isNull(code);
+ Expect.equals(1, errors.length);
+ Expect.equals('Could not find main', errors[0].toString());
+ Expect.isTrue(warnings.isEmpty);
+ });
+
+ runCompiler(
+ "main() {}",
+ [],
+ (String code, List errors, List warnings) {
+ Expect.isNotNull(code);
+ Expect.isTrue(errors.isEmpty);
+ Expect.isTrue(warnings.isEmpty);
+ });
+
+ runCompiler(
+ "",
+ ['--analyze-only'],
+ (String code, List errors, List warnings) {
+ Expect.isNull(code);
+ Expect.equals(1, errors.length);
+ Expect.isTrue(errors[0].toString().startsWith('Could not find main'));
+ Expect.isTrue(warnings.isEmpty);
+ });
+
+ runCompiler(
+ "main() {}",
+ ['--analyze-only'],
+ (String code, List errors, List warnings) {
+ Expect.isNull(code);
+ Expect.isTrue(errors.isEmpty);
+ Expect.isTrue(warnings.isEmpty);
+ });
+
+ runCompiler(
+ "Foo foo; // Unresolved but not analyzed.",
+ ['--analyze-only'],
+ (String code, List errors, List warnings) {
+ Expect.isNull(code);
+ Expect.equals(1, errors.length);
+ Expect.isTrue(errors[0].toString().startsWith('Could not find main'));
+ Expect.isTrue(warnings.isEmpty);
+ });
+
+ runCompiler(
+ """main() {
+ Foo foo; // Unresolved and analyzed.
+ }""",
+ ['--analyze-only'],
+ (String code, List errors, List warnings) {
+ Expect.isNull(code);
+ Expect.isTrue(errors.isEmpty);
+ Expect.equals(1, warnings.length);
+ Expect.equals('Warning: cannot resolve type Foo', warnings[0].toString());
+ });
+
+ runCompiler(
+ "Foo foo; // Unresolved and analyzed.",
+ ['--analyze-only', '--analyze-all'],
+ (String code, List errors, List warnings) {
+ Expect.isNull(code);
+ Expect.isTrue(errors.isEmpty);
+ Expect.equals('Warning: cannot resolve type Foo', warnings[0].toString());
+ });
+
+ runCompiler(
+ """Foo foo; // Unresolved and analyzed.
+ main() {}""",
+ ['--analyze-only', '--analyze-all'],
+ (String code, List errors, List warnings) {
+ Expect.isNull(code);
+ Expect.isTrue(errors.isEmpty);
+ Expect.equals(1, warnings.length);
+ Expect.equals('Warning: cannot resolve type Foo', warnings[0].toString());
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698