OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, 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 // Test a sequence of modifications to hello-world which used to cause problems | |
6 // on Try Dart. | |
7 | |
8 import 'dart:io' show Platform; | |
9 | |
10 import 'dart:async' show Future; | |
11 | |
12 import 'package:dart2js_incremental/dart2js_incremental.dart' | |
13 show IncrementalCompiler; | |
14 | |
15 import 'package:compiler/compiler.dart' show Diagnostic; | |
16 | |
17 import 'package:compiler/src/null_compiler_output.dart' show NullCompilerOutput; | |
18 | |
19 import 'package:compiler/src/old_to_new_api.dart' | |
20 show LegacyCompilerDiagnostics; | |
21 | |
22 import 'package:async_helper/async_helper.dart' show asyncTest; | |
23 | |
24 import 'package:expect/expect.dart' show Expect; | |
25 | |
26 import '../memory_source_file_helper.dart' show MemorySourceFileProvider; | |
27 | |
28 var tests = { | |
29 '/test1.dart': ''' | |
30 var greeting = "Hello, World!"; | |
31 | |
32 void main() { | |
33 print(greeting); | |
34 } | |
35 ''', | |
36 '/test2.dart': ''' | |
37 va greeting = "Hello, World!"; | |
38 | |
39 void main() { | |
40 print(greeting); | |
41 } | |
42 ''', | |
43 '/test3.dart': ''' | |
44 greeting = "Hello, World!"; | |
45 | |
46 void main() { | |
47 print(greeting); | |
48 } | |
49 ''', | |
50 '/test4.dart': ''' | |
51 in greeting = "Hello, World!"; | |
52 | |
53 void main() { | |
54 print(greeting); | |
55 } | |
56 ''', | |
57 '/test5.dart': ''' | |
58 int greeting = "Hello, World!"; | |
59 | |
60 void main() { | |
61 print(greeting); | |
62 } | |
63 ''', | |
64 }; | |
65 | |
66 var testResults = { | |
67 '/test1.dart': true, | |
68 '/test2.dart': true, | |
69 '/test3.dart': false, | |
70 '/test4.dart': false, | |
71 '/test5.dart': true, | |
72 }; | |
73 | |
74 main() { | |
75 Uri libraryRoot = Uri.base.resolve('sdk/'); | |
76 Uri packageConfig = Uri.base.resolve('.packages'); | |
77 MemorySourceFileProvider provider = new MemorySourceFileProvider(tests); | |
78 asyncTest(() => runTests(libraryRoot, packageConfig, provider)); | |
79 } | |
80 | |
81 Future runTests( | |
82 Uri libraryRoot, Uri packageConfig, MemorySourceFileProvider provider) { | |
83 IncrementalCompiler compiler = new IncrementalCompiler( | |
84 diagnosticHandler: new LegacyCompilerDiagnostics(handler), | |
85 inputProvider: provider, | |
86 outputProvider: const NullCompilerOutput(), | |
87 options: ['--analyze-main'], | |
88 libraryRoot: libraryRoot, | |
89 packageConfig: packageConfig); | |
90 | |
91 return Future.forEach(tests.keys, (String testName) { | |
92 Uri testUri = Uri.parse('memory:$testName'); | |
93 return compiler.compile(testUri).then((bool success) { | |
94 Expect.equals(testResults[testName], success, | |
95 'Compilation unexpectedly ${success ? "succeed" : "failed"}.'); | |
96 }); | |
97 }); | |
98 } | |
99 | |
100 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { | |
101 if (kind != Diagnostic.VERBOSE_INFO) { | |
102 print('$uri:$begin:$end:$message:$kind'); | |
103 } | |
104 } | |
OLD | NEW |