| 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 "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
| 11 | 11 |
| 12 import '../../utils/dummy_compiler_test.dart' as dummy; | 12 import '../../utils/dummy_compiler_test.dart' as dummy; |
| 13 import 'package:compiler/compiler.dart'; | 13 import 'package:compiler/compiler_new.dart'; |
| 14 import 'package:compiler/src/options.dart'; |
| 14 import 'package:compiler/src/commandline_options.dart'; | 15 import 'package:compiler/src/commandline_options.dart'; |
| 15 import 'package:compiler/src/diagnostics/messages.dart' | 16 import 'package:compiler/src/diagnostics/messages.dart' |
| 16 show MessageKind, MessageTemplate; | 17 show MessageKind, MessageTemplate; |
| 18 import 'package:compiler/src/old_to_new_api.dart'; |
| 17 | 19 |
| 18 import 'output_collector.dart'; | 20 import 'output_collector.dart'; |
| 19 | 21 |
| 20 runCompiler(String main, List<String> options, | 22 runCompiler(String main, List<String> options, |
| 21 onValue(String code, List errors, List warnings)) { | 23 onValue(String code, List errors, List warnings)) { |
| 22 List errors = new List(); | 24 List errors = new List(); |
| 23 List warnings = new List(); | 25 List warnings = new List(); |
| 24 | 26 |
| 25 Future<String> localProvider(Uri uri) { | 27 Future<String> localProvider(Uri uri) { |
| 26 if (uri.scheme != 'main') return dummy.provider(uri); | 28 if (uri.scheme != 'main') return dummy.provider(uri); |
| 27 return new Future<String>.value(main); | 29 return new Future<String>.value(main); |
| 28 } | 30 } |
| 29 | 31 |
| 30 void localHandler( | 32 void localHandler( |
| 31 Uri uri, int begin, int end, String message, Diagnostic kind) { | 33 Uri uri, int begin, int end, String message, Diagnostic kind) { |
| 32 dummy.handler(uri, begin, end, message, kind); | 34 dummy.handler(uri, begin, end, message, kind); |
| 33 if (kind == Diagnostic.ERROR) { | 35 if (kind == Diagnostic.ERROR) { |
| 34 errors.add(message); | 36 errors.add(message); |
| 35 } else if (kind == Diagnostic.WARNING) { | 37 } else if (kind == Diagnostic.WARNING) { |
| 36 warnings.add(message); | 38 warnings.add(message); |
| 37 } | 39 } |
| 38 } | 40 } |
| 39 | 41 |
| 40 print('-----------------------------------------------'); | 42 print('-----------------------------------------------'); |
| 41 print('main source:\n$main'); | 43 print('main source:\n$main'); |
| 42 print('options: $options\n'); | 44 print('options: $options\n'); |
| 43 asyncStart(); | 45 asyncStart(); |
| 44 OutputCollector outputCollector = new OutputCollector(); | 46 OutputCollector outputCollector = new OutputCollector(); |
| 45 Future<CompilationResult> result = compile( | 47 Future<CompilationResult> result = compile( |
| 46 new Uri(scheme: 'main'), | 48 new CompilerOptions.parse( |
| 47 new Uri(scheme: 'lib', path: '/'), | 49 entryPoint: new Uri(scheme: 'main'), |
| 48 new Uri(scheme: 'package', path: '/'), | 50 libraryRoot: new Uri(scheme: 'lib', path: '/'), |
| 49 localProvider, | 51 packageRoot: new Uri(scheme: 'package', path: '/'), |
| 50 localHandler, | 52 options: options), |
| 51 options, | 53 new LegacyCompilerInput(localProvider), |
| 54 new LegacyCompilerDiagnostics(localHandler), |
| 52 outputCollector); | 55 outputCollector); |
| 53 result | 56 result |
| 54 .then((_) { | 57 .then((_) { |
| 55 onValue(outputCollector.getOutput('', 'js'), errors, warnings); | 58 onValue(outputCollector.getOutput('', OutputType.js), errors, warnings); |
| 56 }, onError: (e, st) { | 59 }, onError: (e, st) { |
| 57 throw 'Compilation failed: ${e} ${st}'; | 60 throw 'Compilation failed: ${e} ${st}'; |
| 58 }) | 61 }) |
| 59 .then(asyncSuccess) | 62 .then(asyncSuccess) |
| 60 .catchError((error, stack) { | 63 .catchError((error, stack) { |
| 61 print('\n\n-----------------------------------------------'); | 64 print('\n\n-----------------------------------------------'); |
| 62 print('main source:\n$main'); | 65 print('main source:\n$main'); |
| 63 print('options: $options\n'); | 66 print('options: $options\n'); |
| 64 print('threw:\n $error\n$stack'); | 67 print('threw:\n $error\n$stack'); |
| 65 print('-----------------------------------------------\n\n'); | 68 print('-----------------------------------------------\n\n'); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 runCompiler( | 182 runCompiler( |
| 180 """main() {} | 183 """main() {} |
| 181 foo() native 'foo';""", | 184 foo() native 'foo';""", |
| 182 [Flags.analyzeOnly], (String code, List errors, List warnings) { | 185 [Flags.analyzeOnly], (String code, List errors, List warnings) { |
| 183 Expect.isNull(code); | 186 Expect.isNull(code); |
| 184 Expect.isTrue( | 187 Expect.isTrue( |
| 185 errors.single.startsWith("'native' modifier is not supported.")); | 188 errors.single.startsWith("'native' modifier is not supported.")); |
| 186 Expect.isTrue(warnings.isEmpty); | 189 Expect.isTrue(warnings.isEmpty); |
| 187 }); | 190 }); |
| 188 } | 191 } |
| OLD | NEW |