| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'memory_compiler.dart'; | 7 import 'memory_compiler.dart'; |
| 8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 9 import 'package:compiler/src/commandline_options.dart'; | 9 import 'package:compiler/src/commandline_options.dart'; |
| 10 import 'package:compiler/src/common_elements.dart'; | 10 import 'package:compiler/src/common_elements.dart'; |
| 11 import 'package:compiler/src/diagnostics/spannable.dart' show Spannable; | 11 import 'package:compiler/src/diagnostics/spannable.dart' show Spannable; |
| 12 import 'package:compiler/src/elements/entities.dart' | 12 import 'package:compiler/src/elements/entities.dart' |
| 13 show LibraryEntity, ClassEntity; | 13 show LibraryEntity, ClassEntity; |
| 14 import 'package:compiler/src/io/source_file.dart' show Binary; |
| 14 import 'package:compiler/src/library_loader.dart' show ScriptLoader; | 15 import 'package:compiler/src/library_loader.dart' show ScriptLoader; |
| 15 import 'package:compiler/src/script.dart' show Script; | 16 import 'package:compiler/src/script.dart' show Script; |
| 16 import 'package:compiler/src/apiimpl.dart' show CompilerImpl; | 17 import 'package:compiler/src/apiimpl.dart' show CompilerImpl; |
| 17 import "package:expect/expect.dart"; | 18 import "package:expect/expect.dart"; |
| 18 import 'package:path/path.dart' as path; | 19 import 'package:path/path.dart' as path; |
| 19 | 20 |
| 20 final String dartkExecutable = Platform.isWindows | 21 final String dartkExecutable = Platform.isWindows |
| 21 ? 'tools/dartk_wrappers/dartk.bat' | 22 ? 'tools/dartk_wrappers/dartk.bat' |
| 22 : 'tools/dartk_wrappers/dartk'; | 23 : 'tools/dartk_wrappers/dartk'; |
| 23 | 24 |
| 24 /// Run the dartk.dart script, and return the binary encoded results. | 25 /// Run the dartk.dart script, and return the binary encoded results. |
| 25 List<int> runDartk(String filename) { | 26 List<int> runDartk(String filename) { |
| 26 String basePath = path.fromUri(Uri.base); | 27 String basePath = path.fromUri(Uri.base); |
| 27 String dartkPath = path.normalize(path.join(basePath, dartkExecutable)); | 28 String dartkPath = path.normalize(path.join(basePath, dartkExecutable)); |
| 28 | 29 |
| 29 var args = [filename, '-fbin', '-ostdout']; | 30 var args = [filename, '-fbin', '-ostdout']; |
| 30 ProcessResult result = Process.runSync(dartkPath, args, stdoutEncoding: null); | 31 ProcessResult result = Process.runSync(dartkPath, args, stdoutEncoding: null); |
| 31 Expect.equals(0, result.exitCode, result.stderr); | 32 Expect.equals(0, result.exitCode, result.stderr); |
| 32 return result.stdout; | 33 return result.stdout; |
| 33 } | 34 } |
| 34 | 35 |
| 35 class TestScriptLoader implements ScriptLoader { | 36 class TestScriptLoader implements ScriptLoader { |
| 36 CompilerImpl compiler; | 37 CompilerImpl compiler; |
| 37 TestScriptLoader(this.compiler); | 38 TestScriptLoader(this.compiler); |
| 38 | 39 |
| 39 Future<Script> readScript(Uri uri, [Spannable spannable]) => | 40 Future<Script> readScript(Uri uri, [Spannable spannable]) => |
| 40 compiler.readScript(uri, spannable); | 41 compiler.readScript(uri, spannable); |
| 42 |
| 43 Future<Binary> readBinary(Uri uri, [Spannable spannable]) => |
| 44 compiler.readBinary(uri, spannable); |
| 41 } | 45 } |
| 42 | 46 |
| 43 /// Test that the compiler can successfully read in .dill kernel files rather | 47 /// Test that the compiler can successfully read in .dill kernel files rather |
| 44 /// than just string source files. | 48 /// than just string source files. |
| 45 main() { | 49 main() { |
| 46 asyncTest(() async { | 50 asyncTest(() async { |
| 47 String filename = 'tests/corelib/list_literal_test.dart'; | 51 String filename = 'tests/corelib/list_literal_test.dart'; |
| 48 Uri uri = Uri.base.resolve(filename); | 52 Uri uri = Uri.base.resolve(filename); |
| 49 DiagnosticCollector diagnostics = new DiagnosticCollector(); | 53 DiagnosticCollector diagnostics = new DiagnosticCollector(); |
| 50 OutputCollector output = new OutputCollector(); | 54 OutputCollector output = new OutputCollector(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 65 | 69 |
| 66 ElementEnvironment environment = compiler.elementEnvironment; | 70 ElementEnvironment environment = compiler.elementEnvironment; |
| 67 LibraryEntity library = environment.lookupLibrary(uri); | 71 LibraryEntity library = environment.lookupLibrary(uri); |
| 68 Expect.isNotNull(library); | 72 Expect.isNotNull(library); |
| 69 ClassEntity clss = environment.lookupClass(library, 'ListLiteralTest'); | 73 ClassEntity clss = environment.lookupClass(library, 'ListLiteralTest'); |
| 70 Expect.isNotNull(clss); | 74 Expect.isNotNull(clss); |
| 71 var member = environment.lookupClassMember(clss, 'testMain'); | 75 var member = environment.lookupClassMember(clss, 'testMain'); |
| 72 Expect.isNotNull(member); | 76 Expect.isNotNull(member); |
| 73 }); | 77 }); |
| 74 } | 78 } |
| OLD | NEW |