| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 import 'memory_source_file_helper.dart'; | 6 import 'memory_source_file_helper.dart'; |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 | 8 |
| 9 import 'package:compiler/compiler.dart' | 9 import 'package:compiler/compiler.dart' |
| 10 show Diagnostic; | 10 show Diagnostic; |
| 11 import 'package:compiler/src/commandline_options.dart'; | 11 import 'package:compiler/compiler_new.dart' show CompilerOptions; |
| 12 import 'package:compiler/src/old_to_new_api.dart'; | 12 import 'package:compiler/src/old_to_new_api.dart'; |
| 13 | 13 |
| 14 main() { | 14 main() { |
| 15 Uri script = currentDirectory.resolveUri(Platform.script); | 15 Uri script = currentDirectory.resolveUri(Platform.script); |
| 16 Uri libraryRoot = script.resolve('../../../sdk/'); | 16 Uri libraryRoot = script.resolve('../../../sdk/'); |
| 17 Uri packageRoot = script.resolve('./packages/'); | 17 Uri packageRoot = script.resolve('./packages/'); |
| 18 | 18 |
| 19 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); | 19 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); |
| 20 int warningCount = 0; | 20 int warningCount = 0; |
| 21 int errorCount = 0; | 21 int errorCount = 0; |
| 22 void diagnosticHandler(Uri uri, int begin, int end, | 22 void diagnosticHandler(Uri uri, int begin, int end, |
| 23 String message, Diagnostic kind) { | 23 String message, Diagnostic kind) { |
| 24 if (kind == Diagnostic.VERBOSE_INFO) { | 24 if (kind == Diagnostic.VERBOSE_INFO) { |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 if (kind == Diagnostic.ERROR) { | 27 if (kind == Diagnostic.ERROR) { |
| 28 errorCount++; | 28 errorCount++; |
| 29 } else if (kind == Diagnostic.WARNING) { | 29 } else if (kind == Diagnostic.WARNING) { |
| 30 warningCount++; | 30 warningCount++; |
| 31 } else { | 31 } else { |
| 32 throw 'unexpected diagnostic $kind: $message'; | 32 throw 'unexpected diagnostic $kind: $message'; |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 CompilerImpl compiler = new CompilerImpl( | 36 CompilerImpl compiler = new CompilerImpl( |
| 37 new LegacyCompilerInput(provider.readStringFromUri), | 37 new LegacyCompilerInput(provider.readStringFromUri), |
| 38 new LegacyCompilerOutput(), | 38 new LegacyCompilerOutput(), |
| 39 new LegacyCompilerDiagnostics(diagnosticHandler), | 39 new LegacyCompilerDiagnostics(diagnosticHandler), |
| 40 libraryRoot, | 40 new CompilerOptions( |
| 41 packageRoot, | 41 libraryRoot: libraryRoot, |
| 42 [Flags.analyzeOnly], | 42 packageRoot: packageRoot)); |
| 43 {}); | |
| 44 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) { | 43 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) { |
| 45 Expect.isTrue(compiler.compilationFailed); | 44 Expect.isTrue(compiler.compilationFailed); |
| 46 Expect.equals(5, errorCount); | 45 Expect.equals(5, errorCount); |
| 47 Expect.equals(1, warningCount); | 46 Expect.equals(1, warningCount); |
| 48 })); | 47 })); |
| 49 } | 48 } |
| 50 | 49 |
| 51 const Map MEMORY_SOURCE_FILES = const { | 50 const Map MEMORY_SOURCE_FILES = const { |
| 52 'main.dart': """ | 51 'main.dart': """ |
| 53 main() { | 52 main() { |
| 54 for (var x, y in []) { | 53 for (var x, y in []) { |
| 55 } | 54 } |
| 56 | 55 |
| 57 for (var x = 10 in []) { | 56 for (var x = 10 in []) { |
| 58 } | 57 } |
| 59 | 58 |
| 60 for (x.y in []) { // Also causes a warning "x unresolved". | 59 for (x.y in []) { // Also causes a warning "x unresolved". |
| 61 } | 60 } |
| 62 | 61 |
| 63 for ((){}() in []) { | 62 for ((){}() in []) { |
| 64 } | 63 } |
| 65 | 64 |
| 66 for (1 in []) { | 65 for (1 in []) { |
| 67 } | 66 } |
| 68 } | 67 } |
| 69 """ | 68 """ |
| 70 }; | 69 }; |
| OLD | NEW |