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 | 11 |
11 import '../../utils/dummy_compiler_test.dart' as dummy; | 12 import '../../utils/dummy_compiler_test.dart' as dummy; |
12 import '../../../sdk/lib/_internal/compiler/compiler.dart'; | 13 import '../../../sdk/lib/_internal/compiler/compiler.dart'; |
13 | 14 |
14 runCompiler(String main, List<String> options, | 15 runCompiler(String main, List<String> options, |
15 onValue(String code, List errors, List warnings)) { | 16 onValue(String code, List errors, List warnings)) { |
16 List errors = new List(); | 17 List errors = new List(); |
17 List warnings = new List(); | 18 List warnings = new List(); |
18 | 19 |
19 Future<String> localProvider(Uri uri) { | 20 Future<String> localProvider(Uri uri) { |
20 if (uri.scheme != 'main') return dummy.provider(uri); | 21 if (uri.scheme != 'main') return dummy.provider(uri); |
21 return new Future<String>.value(main); | 22 return new Future<String>.value(main); |
22 } | 23 } |
23 | 24 |
24 void localHandler(Uri uri, int begin, int end, | 25 void localHandler(Uri uri, int begin, int end, |
25 String message, Diagnostic kind) { | 26 String message, Diagnostic kind) { |
26 dummy.handler(uri, begin, end, message, kind); | 27 dummy.handler(uri, begin, end, message, kind); |
27 if (kind == Diagnostic.ERROR) { | 28 if (kind == Diagnostic.ERROR) { |
28 errors.add(message); | 29 errors.add(message); |
29 } else if (kind == Diagnostic.WARNING) { | 30 } else if (kind == Diagnostic.WARNING) { |
30 warnings.add(message); | 31 warnings.add(message); |
31 } | 32 } |
32 } | 33 } |
33 | 34 |
34 print('-----------------------------------------------'); | 35 print('-----------------------------------------------'); |
35 print('main source:\n$main'); | 36 print('main source:\n$main'); |
36 print('options: $options\n'); | 37 print('options: $options\n'); |
| 38 asyncStart(); |
37 Future<String> result = | 39 Future<String> result = |
38 compile(new Uri(scheme: 'main'), | 40 compile(new Uri(scheme: 'main'), |
39 new Uri(scheme: 'lib', path: '/'), | 41 new Uri(scheme: 'lib', path: '/'), |
40 new Uri(scheme: 'package', path: '/'), | 42 new Uri(scheme: 'package', path: '/'), |
41 localProvider, localHandler, options); | 43 localProvider, localHandler, options); |
42 result.then((String code) { | 44 result.then((String code) { |
43 onValue(code, errors, warnings); | 45 onValue(code, errors, warnings); |
44 }, onError: (e) { | 46 }, onError: (e) { |
45 throw 'Compilation failed'; | 47 throw 'Compilation failed'; |
46 }); | 48 }).whenComplete(() => asyncEnd()); |
47 } | 49 } |
48 | 50 |
49 main() { | 51 main() { |
50 runCompiler( | 52 runCompiler( |
51 "", | 53 "", |
52 [], | 54 [], |
53 (String code, List errors, List warnings) { | 55 (String code, List errors, List warnings) { |
54 Expect.isNull(code); | 56 Expect.isNull(code); |
55 Expect.equals(1, errors.length); | 57 Expect.equals(1, errors.length); |
56 Expect.equals('Error: Could not find "main".', errors[0].toString()); | 58 Expect.equals('Error: Could not find "main".', errors[0].toString()); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // --analyze-signatures-only implies --analyze-only | 157 // --analyze-signatures-only implies --analyze-only |
156 runCompiler( | 158 runCompiler( |
157 "", | 159 "", |
158 ['--analyze-signatures-only', '--analyze-all'], | 160 ['--analyze-signatures-only', '--analyze-all'], |
159 (String code, List errors, List warnings) { | 161 (String code, List errors, List warnings) { |
160 Expect.isNull(code); | 162 Expect.isNull(code); |
161 Expect.isTrue(errors.isEmpty); | 163 Expect.isTrue(errors.isEmpty); |
162 Expect.isTrue(warnings.isEmpty); | 164 Expect.isTrue(warnings.isEmpty); |
163 }); | 165 }); |
164 } | 166 } |
OLD | NEW |