| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Smoke test of the dart2js compiler API. | 5 // Smoke test of the dart2js compiler API. |
| 6 library analyze_only; | 6 library analyze_only; |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:uri'; | |
| 11 | 10 |
| 12 import '../../utils/dummy_compiler_test.dart' as dummy; | 11 import '../../utils/dummy_compiler_test.dart' as dummy; |
| 13 import '../../../sdk/lib/_internal/compiler/compiler.dart'; | 12 import '../../../sdk/lib/_internal/compiler/compiler.dart'; |
| 14 | 13 |
| 15 runCompiler(String main, List<String> options, | 14 runCompiler(String main, List<String> options, |
| 16 onValue(String code, List errors, List warnings)) { | 15 onValue(String code, List errors, List warnings)) { |
| 17 List errors = new List(); | 16 List errors = new List(); |
| 18 List warnings = new List(); | 17 List warnings = new List(); |
| 19 | 18 |
| 20 Future<String> localProvider(Uri uri) { | 19 Future<String> localProvider(Uri uri) { |
| 21 if (uri.scheme != 'main') return dummy.provider(uri); | 20 if (uri.scheme != 'main') return dummy.provider(uri); |
| 22 return new Future<String>.value(main); | 21 return new Future<String>.value(main); |
| 23 } | 22 } |
| 24 | 23 |
| 25 void localHandler(Uri uri, int begin, int end, | 24 void localHandler(Uri uri, int begin, int end, |
| 26 String message, Diagnostic kind) { | 25 String message, Diagnostic kind) { |
| 27 dummy.handler(uri, begin, end, message, kind); | 26 dummy.handler(uri, begin, end, message, kind); |
| 28 if (kind == Diagnostic.ERROR) { | 27 if (kind == Diagnostic.ERROR) { |
| 29 errors.add(message); | 28 errors.add(message); |
| 30 } else if (kind == Diagnostic.WARNING) { | 29 } else if (kind == Diagnostic.WARNING) { |
| 31 warnings.add(message); | 30 warnings.add(message); |
| 32 } | 31 } |
| 33 } | 32 } |
| 34 | 33 |
| 35 print('-----------------------------------------------'); | 34 print('-----------------------------------------------'); |
| 36 print('main source:\n$main'); | 35 print('main source:\n$main'); |
| 37 print('options: $options\n'); | 36 print('options: $options\n'); |
| 38 Future<String> result = | 37 Future<String> result = |
| 39 compile(new Uri.fromComponents(scheme: 'main'), | 38 compile(new Uri(scheme: 'main'), |
| 40 new Uri.fromComponents(scheme: 'lib', path: '/'), | 39 new Uri(scheme: 'lib', path: '/'), |
| 41 new Uri.fromComponents(scheme: 'package', path: '/'), | 40 new Uri(scheme: 'package', path: '/'), |
| 42 localProvider, localHandler, options); | 41 localProvider, localHandler, options); |
| 43 result.then((String code) { | 42 result.then((String code) { |
| 44 onValue(code, errors, warnings); | 43 onValue(code, errors, warnings); |
| 45 }, onError: (e) { | 44 }, onError: (e) { |
| 46 throw 'Compilation failed'; | 45 throw 'Compilation failed'; |
| 47 }); | 46 }); |
| 48 } | 47 } |
| 49 | 48 |
| 50 main() { | 49 main() { |
| 51 runCompiler( | 50 runCompiler( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // --analyze-signatures-only implies --analyze-only | 150 // --analyze-signatures-only implies --analyze-only |
| 152 runCompiler( | 151 runCompiler( |
| 153 "", | 152 "", |
| 154 ['--analyze-signatures-only', '--analyze-all'], | 153 ['--analyze-signatures-only', '--analyze-all'], |
| 155 (String code, List errors, List warnings) { | 154 (String code, List errors, List warnings) { |
| 156 Expect.isNull(code); | 155 Expect.isNull(code); |
| 157 Expect.isTrue(errors.isEmpty); | 156 Expect.isTrue(errors.isEmpty); |
| 158 Expect.isTrue(warnings.isEmpty); | 157 Expect.isTrue(warnings.isEmpty); |
| 159 }); | 158 }); |
| 160 } | 159 } |
| OLD | NEW |