| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Test a sequence of modifications to hello-world which used to cause problems | 5 // Test a sequence of modifications to hello-world which used to cause problems |
| 6 // on Try Dart. | 6 // on Try Dart. |
| 7 | 7 |
| 8 import 'dart:io' show | 8 import 'dart:io' show |
| 9 Platform; | 9 Platform; |
| 10 | 10 |
| 11 import 'dart:async' show | 11 import 'dart:async' show |
| 12 Future; | 12 Future; |
| 13 | 13 |
| 14 import 'package:try/src/caching_compiler.dart' show | 14 import 'package:dart2js_incremental/dart2js_incremental.dart' show |
| 15 reuseCompiler; | 15 IncrementalCompiler; |
| 16 | 16 |
| 17 import 'package:compiler/compiler.dart' as compiler; | 17 import 'package:compiler/compiler.dart' show |
| 18 Diagnostic; |
| 18 | 19 |
| 19 import 'package:async_helper/async_helper.dart' show | 20 import 'package:async_helper/async_helper.dart' show |
| 20 asyncTest; | 21 asyncTest; |
| 21 | 22 |
| 22 import 'package:expect/expect.dart' show | 23 import 'package:expect/expect.dart' show |
| 23 Expect; | 24 Expect; |
| 24 | 25 |
| 25 import '../memory_source_file_helper.dart' show | 26 import '../memory_source_file_helper.dart' show |
| 26 MemorySourceFileProvider; | 27 MemorySourceFileProvider; |
| 27 | 28 |
| 28 import 'incremental_helper.dart'; | |
| 29 | |
| 30 var tests = { | 29 var tests = { |
| 31 '/test1.dart': | 30 '/test1.dart': |
| 32 ''' | 31 ''' |
| 33 var greeting = "Hello, World!"; | 32 var greeting = "Hello, World!"; |
| 34 | 33 |
| 35 void main() { | 34 void main() { |
| 36 print(greeting); | 35 print(greeting); |
| 37 } | 36 } |
| 38 ''', | 37 ''', |
| 39 '/test2.dart': | 38 '/test2.dart': |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 }; | 70 }; |
| 72 | 71 |
| 73 var testResults = { | 72 var testResults = { |
| 74 '/test1.dart': true, | 73 '/test1.dart': true, |
| 75 '/test2.dart': true, | 74 '/test2.dart': true, |
| 76 '/test3.dart': false, | 75 '/test3.dart': false, |
| 77 '/test4.dart': false, | 76 '/test4.dart': false, |
| 78 '/test5.dart': true, | 77 '/test5.dart': true, |
| 79 }; | 78 }; |
| 80 | 79 |
| 81 var cachedCompiler; | |
| 82 | |
| 83 main() { | 80 main() { |
| 84 Uri libraryRoot = Uri.base.resolve('sdk/'); | 81 Uri libraryRoot = Uri.base.resolve('sdk/'); |
| 85 Uri packageRoot = Uri.base.resolveUri( | 82 Uri packageRoot = Uri.base.resolveUri( |
| 86 new Uri.file('${Platform.packageRoot}/')); | 83 new Uri.file('${Platform.packageRoot}/')); |
| 87 MemorySourceFileProvider provider = | 84 MemorySourceFileProvider provider = |
| 88 new MemorySourceFileProvider(tests); | 85 new MemorySourceFileProvider(tests); |
| 89 asyncTest( | 86 asyncTest(() => runTests(libraryRoot, packageRoot, provider)); |
| 90 () => runTests(libraryRoot, packageRoot, provider, INCREMENTAL_OPTIONS)); | |
| 91 } | 87 } |
| 92 | 88 |
| 93 Future runTests( | 89 Future runTests( |
| 94 Uri libraryRoot, | 90 Uri libraryRoot, |
| 95 Uri packageRoot, | 91 Uri packageRoot, |
| 96 MemorySourceFileProvider provider, | 92 MemorySourceFileProvider provider) { |
| 97 options) { | 93 IncrementalCompiler compiler = new IncrementalCompiler( |
| 94 diagnosticHandler: handler, |
| 95 inputProvider: provider, |
| 96 options: ['--analyze-main'], |
| 97 libraryRoot: libraryRoot, |
| 98 packageRoot: packageRoot); |
| 99 |
| 98 return Future.forEach(tests.keys, (String testName) { | 100 return Future.forEach(tests.keys, (String testName) { |
| 99 cachedCompiler = reuseCompiler( | |
| 100 diagnosticHandler: handler, | |
| 101 inputProvider: provider, | |
| 102 options: options, | |
| 103 cachedCompiler: cachedCompiler, | |
| 104 libraryRoot: libraryRoot, | |
| 105 packageRoot: packageRoot); | |
| 106 Uri testUri = Uri.parse('memory:$testName'); | 101 Uri testUri = Uri.parse('memory:$testName'); |
| 107 return cachedCompiler.run(testUri).then((bool success) { | 102 return compiler.compile(testUri).then((bool success) { |
| 108 Expect.equals( | 103 Expect.equals( |
| 109 testResults[testName], success, | 104 testResults[testName], success, |
| 110 'Compilation unexpectedly ${success ? "succeed" : "failed"}.'); | 105 'Compilation unexpectedly ${success ? "succeed" : "failed"}.'); |
| 111 }); | 106 }); |
| 112 }); | 107 }); |
| 113 } | 108 } |
| 114 | 109 |
| 115 void handler(Uri uri, | 110 void handler(Uri uri, |
| 116 int begin, | 111 int begin, |
| 117 int end, | 112 int end, |
| 118 String message, | 113 String message, |
| 119 compiler.Diagnostic kind) { | 114 Diagnostic kind) { |
| 120 if (kind != compiler.Diagnostic.VERBOSE_INFO) { | 115 if (kind != Diagnostic.VERBOSE_INFO) { |
| 121 print('$uri:$begin:$end:$message:$kind'); | 116 print('$uri:$begin:$end:$message:$kind'); |
| 122 } | 117 } |
| 123 } | 118 } |
| OLD | NEW |