| 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 // Test that no parts are emitted when deferred loading isn't used. |
| 6 |
| 5 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 6 import 'memory_source_file_helper.dart'; | 8 import 'memory_source_file_helper.dart'; |
| 7 | 9 |
| 10 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| 11 show NullSink; |
| 12 |
| 8 import '../../../sdk/lib/_internal/compiler/compiler.dart' | 13 import '../../../sdk/lib/_internal/compiler/compiler.dart' |
| 9 show Diagnostic; | 14 show Diagnostic; |
| 10 | 15 |
| 16 import 'dart:async'; |
| 17 |
| 11 main() { | 18 main() { |
| 12 Uri script = currentDirectory.resolve(nativeToUriPath(new Options().script)); | 19 Uri script = currentDirectory.resolve(nativeToUriPath(new Options().script)); |
| 13 Uri libraryRoot = script.resolve('../../../sdk/'); | 20 Uri libraryRoot = script.resolve('../../../sdk/'); |
| 14 Uri packageRoot = script.resolve('./packages/'); | 21 Uri packageRoot = script.resolve('./packages/'); |
| 15 | 22 |
| 16 MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES; | 23 MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES; |
| 17 var provider = new MemorySourceFileProvider(); | 24 var provider = new MemorySourceFileProvider(); |
| 18 int warningCount = 0; | |
| 19 int errorCount = 0; | |
| 20 void diagnosticHandler(Uri uri, int begin, int end, | 25 void diagnosticHandler(Uri uri, int begin, int end, |
| 21 String message, Diagnostic kind) { | 26 String message, Diagnostic kind) { |
| 22 if (kind == Diagnostic.VERBOSE_INFO) { | 27 if (kind == Diagnostic.VERBOSE_INFO) { |
| 23 return; | 28 return; |
| 24 } | 29 } |
| 25 if (kind == Diagnostic.ERROR) { | 30 throw '$uri:$begin:$end:$message:$kind'; |
| 26 errorCount++; | 31 } |
| 27 } else if (kind == Diagnostic.WARNING) { | 32 |
| 28 warningCount++; | 33 EventSink<String> outputProvider(String name, String extension) { |
| 29 } else { | 34 if (name != '') throw 'Attempt to output file "$name.$extension"'; |
| 30 throw 'unexpected diagnostic $kind: $message'; | 35 return new NullSink('$name.$extension'); |
| 31 } | |
| 32 } | 36 } |
| 33 | 37 |
| 34 Compiler compiler = new Compiler(provider.readStringFromUri, | 38 Compiler compiler = new Compiler(provider.readStringFromUri, |
| 35 (name, extension) => null, | 39 outputProvider, |
| 36 diagnosticHandler, | 40 diagnosticHandler, |
| 37 libraryRoot, | 41 libraryRoot, |
| 38 packageRoot, | 42 packageRoot, |
| 39 ['--analyze-only']); | 43 []); |
| 40 compiler.run(Uri.parse('memory:main.dart')); | 44 compiler.run(Uri.parse('memory:main.dart')); |
| 41 Expect.isTrue(compiler.compilationFailed); | 45 Expect.isFalse(compiler.compilationFailed); |
| 42 Expect.equals(5, errorCount); | |
| 43 Expect.equals(1, warningCount); | |
| 44 } | 46 } |
| 45 | 47 |
| 46 const Map MEMORY_SOURCE_FILES = const { | 48 const Map MEMORY_SOURCE_FILES = const { |
| 47 'main.dart': """ | 49 'main.dart': """ |
| 50 class Greeting { |
| 51 final message; |
| 52 const Greeting(this.message); |
| 53 } |
| 54 |
| 55 const fisk = const Greeting('Hello, World!'); |
| 56 |
| 48 main() { | 57 main() { |
| 49 for (var x, y in []) { | 58 var x = fisk; |
| 59 if (new DateTime.now().millisecondsSinceEpoch == 42) { |
| 60 x = new Greeting(\"I\'m confused\"); |
| 50 } | 61 } |
| 51 | 62 print(x.message); |
| 52 for (var x = 10 in []) { | |
| 53 } | |
| 54 | |
| 55 for (x.y in []) { // Also causes a warning "x unresolved". | |
| 56 } | |
| 57 | |
| 58 for ((){}() in []) { | |
| 59 } | |
| 60 | |
| 61 for (1 in []) { | |
| 62 } | |
| 63 } | 63 } |
| 64 """ | 64 """, |
| 65 }; | 65 }; |
| OLD | NEW |