| OLD | NEW |
| (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 analyze_only; | |
| 7 | |
| 8 import 'dart:async'; | |
| 9 import 'dart:uri'; | |
| 10 | |
| 11 import 'dummy_compiler_test.dart' as dummy; | |
| 12 import '../../sdk/lib/_internal/compiler/compiler.dart'; | |
| 13 | |
| 14 runCompiler(String main, List<String> options, | |
| 15 onValue(String code, List errors, List warnings)) { | |
| 16 List errors = new List(); | |
| 17 List warnings = new List(); | |
| 18 | |
| 19 Future<String> localProvider(Uri uri) { | |
| 20 return dummy.provider(uri, main); | |
| 21 } | |
| 22 | |
| 23 void localHandler(Uri uri, int begin, int end, | |
| 24 String message, Diagnostic kind) { | |
| 25 dummy.handler(uri, begin, end, message, kind); | |
| 26 if (kind == Diagnostic.ERROR) { | |
| 27 errors.add(message); | |
| 28 } else if (kind == Diagnostic.WARNING) { | |
| 29 warnings.add(message); | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 print('-----------------------------------------------'); | |
| 34 print('main source:\n$main'); | |
| 35 print('options: $options\n'); | |
| 36 Future<String> result = | |
| 37 compile(new Uri.fromComponents(scheme: 'main'), | |
| 38 new Uri.fromComponents(scheme: 'lib', path: '/'), | |
| 39 new Uri.fromComponents(scheme: 'package', path: '/'), | |
| 40 localProvider, localHandler, options); | |
| 41 result.then((String code) { | |
| 42 onValue(code, errors, warnings); | |
| 43 }, onError: (AsyncError e) { | |
| 44 throw 'Compilation failed'; | |
| 45 }); | |
| 46 } | |
| 47 | |
| 48 main() { | |
| 49 runCompiler( | |
| 50 "", | |
| 51 [], | |
| 52 (String code, List errors, List warnings) { | |
| 53 Expect.isNull(code); | |
| 54 Expect.equals(1, errors.length); | |
| 55 Expect.equals('Could not find main', errors[0].toString()); | |
| 56 Expect.isTrue(warnings.isEmpty); | |
| 57 }); | |
| 58 | |
| 59 runCompiler( | |
| 60 "main() {}", | |
| 61 [], | |
| 62 (String code, List errors, List warnings) { | |
| 63 Expect.isNotNull(code); | |
| 64 Expect.isTrue(errors.isEmpty); | |
| 65 Expect.isTrue(warnings.isEmpty); | |
| 66 }); | |
| 67 | |
| 68 runCompiler( | |
| 69 "", | |
| 70 ['--analyze-only'], | |
| 71 (String code, List errors, List warnings) { | |
| 72 Expect.isNull(code); | |
| 73 Expect.equals(1, errors.length); | |
| 74 Expect.isTrue(errors[0].toString().startsWith('Could not find main')); | |
| 75 Expect.isTrue(warnings.isEmpty); | |
| 76 }); | |
| 77 | |
| 78 runCompiler( | |
| 79 "main() {}", | |
| 80 ['--analyze-only'], | |
| 81 (String code, List errors, List warnings) { | |
| 82 Expect.isNull(code); | |
| 83 Expect.isTrue(errors.isEmpty); | |
| 84 Expect.isTrue(warnings.isEmpty); | |
| 85 }); | |
| 86 | |
| 87 runCompiler( | |
| 88 "Foo foo; // Unresolved but not analyzed.", | |
| 89 ['--analyze-only'], | |
| 90 (String code, List errors, List warnings) { | |
| 91 Expect.isNull(code); | |
| 92 Expect.equals(1, errors.length); | |
| 93 Expect.isTrue(errors[0].toString().startsWith('Could not find main')); | |
| 94 Expect.isTrue(warnings.isEmpty); | |
| 95 }); | |
| 96 | |
| 97 runCompiler( | |
| 98 """main() { | |
| 99 Foo foo; // Unresolved and analyzed. | |
| 100 }""", | |
| 101 ['--analyze-only'], | |
| 102 (String code, List errors, List warnings) { | |
| 103 Expect.isNull(code); | |
| 104 Expect.isTrue(errors.isEmpty); | |
| 105 Expect.equals(1, warnings.length); | |
| 106 Expect.equals('Warning: cannot resolve type Foo', warnings[0].toString()); | |
| 107 }); | |
| 108 | |
| 109 runCompiler( | |
| 110 "Foo foo; // Unresolved and analyzed.", | |
| 111 ['--analyze-only', '--analyze-all'], | |
| 112 (String code, List errors, List warnings) { | |
| 113 Expect.isNull(code); | |
| 114 Expect.isTrue(errors.isEmpty); | |
| 115 Expect.equals('Warning: cannot resolve type Foo', warnings[0].toString()); | |
| 116 }); | |
| 117 | |
| 118 runCompiler( | |
| 119 """Foo foo; // Unresolved and analyzed. | |
| 120 main() {}""", | |
| 121 ['--analyze-only', '--analyze-all'], | |
| 122 (String code, List errors, List warnings) { | |
| 123 Expect.isNull(code); | |
| 124 Expect.isTrue(errors.isEmpty); | |
| 125 Expect.equals(1, warnings.length); | |
| 126 Expect.equals('Warning: cannot resolve type Foo', warnings[0].toString()); | |
| 127 }); | |
| 128 } | |
| OLD | NEW |