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