| 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 "../../async_helper.dart"; |
| 7 | 8 |
| 8 import '../../../sdk/lib/_internal/compiler/compiler.dart' | 9 import '../../../sdk/lib/_internal/compiler/compiler.dart' |
| 9 show Diagnostic; | 10 show Diagnostic; |
| 10 | 11 |
| 11 main() { | 12 main() { |
| 12 Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script)); | 13 Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script)); |
| 13 Uri libraryRoot = script.resolve('../../../sdk/'); | 14 Uri libraryRoot = script.resolve('../../../sdk/'); |
| 14 Uri packageRoot = script.resolve('./packages/'); | 15 Uri packageRoot = script.resolve('./packages/'); |
| 15 | 16 |
| 16 MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES; | 17 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); |
| 17 var provider = new MemorySourceFileProvider(); | |
| 18 int warningCount = 0; | 18 int warningCount = 0; |
| 19 int errorCount = 0; | 19 int errorCount = 0; |
| 20 void diagnosticHandler(Uri uri, int begin, int end, | 20 void diagnosticHandler(Uri uri, int begin, int end, |
| 21 String message, Diagnostic kind) { | 21 String message, Diagnostic kind) { |
| 22 if (kind == Diagnostic.VERBOSE_INFO) { | 22 if (kind == Diagnostic.VERBOSE_INFO) { |
| 23 return; | 23 return; |
| 24 } | 24 } |
| 25 if (kind == Diagnostic.ERROR) { | 25 if (kind == Diagnostic.ERROR) { |
| 26 errorCount++; | 26 errorCount++; |
| 27 } else if (kind == Diagnostic.WARNING) { | 27 } else if (kind == Diagnostic.WARNING) { |
| 28 warningCount++; | 28 warningCount++; |
| 29 } else { | 29 } else { |
| 30 throw 'unexpected diagnostic $kind: $message'; | 30 throw 'unexpected diagnostic $kind: $message'; |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 Compiler compiler = new Compiler(provider.readStringFromUri, | 34 Compiler compiler = new Compiler(provider.readStringFromUri, |
| 35 (name, extension) => null, | 35 (name, extension) => null, |
| 36 diagnosticHandler, | 36 diagnosticHandler, |
| 37 libraryRoot, | 37 libraryRoot, |
| 38 packageRoot, | 38 packageRoot, |
| 39 ['--analyze-only']); | 39 ['--analyze-only']); |
| 40 compiler.run(Uri.parse('memory:main.dart')); | 40 asyncStart(); |
| 41 Expect.isTrue(compiler.compilationFailed); | 41 compiler.run(Uri.parse('memory:main.dart')).then((_) { |
| 42 Expect.equals(5, errorCount); | 42 Expect.isTrue(compiler.compilationFailed); |
| 43 Expect.equals(1, warningCount); | 43 Expect.equals(5, errorCount); |
| 44 Expect.equals(1, warningCount); |
| 45 }).whenComplete(() => asyncEnd()); |
| 44 } | 46 } |
| 45 | 47 |
| 46 const Map MEMORY_SOURCE_FILES = const { | 48 const Map MEMORY_SOURCE_FILES = const { |
| 47 'main.dart': """ | 49 'main.dart': """ |
| 48 main() { | 50 main() { |
| 49 for (var x, y in []) { | 51 for (var x, y in []) { |
| 50 } | 52 } |
| 51 | 53 |
| 52 for (var x = 10 in []) { | 54 for (var x = 10 in []) { |
| 53 } | 55 } |
| 54 | 56 |
| 55 for (x.y in []) { // Also causes a warning "x unresolved". | 57 for (x.y in []) { // Also causes a warning "x unresolved". |
| 56 } | 58 } |
| 57 | 59 |
| 58 for ((){}() in []) { | 60 for ((){}() in []) { |
| 59 } | 61 } |
| 60 | 62 |
| 61 for (1 in []) { | 63 for (1 in []) { |
| 62 } | 64 } |
| 63 } | 65 } |
| 64 """ | 66 """ |
| 65 }; | 67 }; |
| OLD | NEW |