| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Check that 'dart:' libraries have their corresponding dart.library.X | 5 /// Check that 'dart:' libraries have their corresponding dart.library.X |
| 6 /// environment variable set. | 6 /// environment variable set. |
| 7 | 7 |
| 8 import "dart:io"; | 8 import "dart:io"; |
| 9 | 9 |
| 10 import "dart:async"; | 10 import "dart:async"; |
| 11 | 11 |
| 12 import "memory_source_file_helper.dart"; | 12 import "memory_source_file_helper.dart"; |
| 13 | 13 |
| 14 import "package:async_helper/async_helper.dart"; | 14 import "package:async_helper/async_helper.dart"; |
| 15 | 15 |
| 16 import 'package:expect/expect.dart' show | 16 import 'package:expect/expect.dart' show |
| 17 Expect; | 17 Expect; |
| 18 | 18 |
| 19 import 'package:compiler/src/elements/elements.dart' show | 19 import 'package:compiler/src/elements/elements.dart' show |
| 20 LibraryElement; | 20 LibraryElement; |
| 21 | 21 |
| 22 import 'package:compiler/src/null_compiler_output.dart' show | 22 import 'package:compiler/src/null_compiler_output.dart' show |
| 23 NullCompilerOutput; | 23 NullCompilerOutput; |
| 24 | 24 |
| 25 import 'package:compiler/compiler_new.dart' show | 25 import 'package:compiler/compiler_new.dart' show |
| 26 CompilerInput, | 26 CompilerInput, |
| 27 CompilerDiagnostics; | 27 CompilerDiagnostics, |
| 28 CompilerOptions; |
| 28 | 29 |
| 29 import 'package:sdk_library_metadata/libraries.dart' show | 30 import 'package:sdk_library_metadata/libraries.dart' show |
| 30 LibraryInfo; | 31 LibraryInfo; |
| 31 | 32 |
| 32 const clientPlatform = r''' | 33 const clientPlatform = r''' |
| 33 [dart-spec] | 34 [dart-spec] |
| 34 spec: 3rd edition. | 35 spec: 3rd edition. |
| 35 | 36 |
| 36 [features] | 37 [features] |
| 37 # No extra features | 38 # No extra features |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 74 |
| 74 class DummyCompilerDiagnostics implements CompilerDiagnostics { | 75 class DummyCompilerDiagnostics implements CompilerDiagnostics { |
| 75 const DummyCompilerDiagnostics(); | 76 const DummyCompilerDiagnostics(); |
| 76 | 77 |
| 77 report(code, uri, begin, end, text, kind) { | 78 report(code, uri, begin, end, text, kind) { |
| 78 throw "should not be needed"; | 79 throw "should not be needed"; |
| 79 } | 80 } |
| 80 } | 81 } |
| 81 | 82 |
| 82 class CustomCompiler extends CompilerImpl { | 83 class CustomCompiler extends CompilerImpl { |
| 83 CustomCompiler( | 84 CustomCompiler(options, environment) |
| 84 options, | |
| 85 environment) | |
| 86 : super( | 85 : super( |
| 87 const DummyCompilerInput(), | 86 const DummyCompilerInput(), |
| 88 const NullCompilerOutput(), | 87 const NullCompilerOutput(), |
| 89 const DummyCompilerDiagnostics(), | 88 const DummyCompilerDiagnostics(), |
| 90 Uri.base.resolve("sdk/"), | 89 new CompilerOptions.parse( |
| 91 null, | 90 libraryRoot: Uri.base.resolve("sdk/"), |
| 92 options, | 91 options: options, |
| 93 environment); | 92 environment: environment)); |
| 94 } | 93 } |
| 95 | 94 |
| 96 runTest() async { | 95 runTest() async { |
| 97 var compiler = new CustomCompiler( | 96 var compiler = new CustomCompiler([], {}); |
| 98 [], | |
| 99 {}); | |
| 100 | 97 |
| 101 await compiler.setupSdk(); | 98 await compiler.setupSdk(); |
| 102 | 99 |
| 103 // Core libraries are always present. | 100 // Core libraries are always present. |
| 104 Expect.equals("true", compiler.fromEnvironment("dart.library.collection")); | 101 Expect.equals("true", compiler.fromEnvironment("dart.library.collection")); |
| 105 // Non-existing entries in the environment return 'null'. | 102 // Non-existing entries in the environment return 'null'. |
| 106 Expect.isNull(compiler.fromEnvironment("not in env")); | 103 Expect.isNull(compiler.fromEnvironment("not in env")); |
| 107 // Check for client libraries (default if there are no flags to the compiler). | 104 // Check for client libraries (default if there are no flags to the compiler). |
| 108 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.client")); | 105 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.client")); |
| 109 Expect.equals("true", compiler.fromEnvironment("dart.library.html")); | 106 Expect.equals("true", compiler.fromEnvironment("dart.library.html")); |
| 110 // Check for shared libraries.. | 107 // Check for shared libraries.. |
| 111 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared")); | 108 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared")); |
| 112 // Check server libraries are not present. | 109 // Check server libraries are not present. |
| 113 Expect.equals(null, compiler.fromEnvironment("dart.library.mock.server")); | 110 Expect.equals(null, compiler.fromEnvironment("dart.library.mock.server")); |
| 114 Expect.equals(null, compiler.fromEnvironment("dart.library.io")); | 111 Expect.equals(null, compiler.fromEnvironment("dart.library.io")); |
| 115 | 112 |
| 116 compiler = new CustomCompiler( | 113 compiler = new CustomCompiler(['--categories=Server'], {}); |
| 117 ['--categories=Server'], | |
| 118 {}); | |
| 119 | 114 |
| 120 await compiler.setupSdk(); | 115 await compiler.setupSdk(); |
| 121 | 116 |
| 122 // Core libraries are always present. | 117 // Core libraries are always present. |
| 123 Expect.equals("true", compiler.fromEnvironment("dart.library.collection")); | 118 Expect.equals("true", compiler.fromEnvironment("dart.library.collection")); |
| 124 // Non-existing entries in the environment return 'null'. | 119 // Non-existing entries in the environment return 'null'. |
| 125 Expect.isNull(compiler.fromEnvironment("not in env")); | 120 Expect.isNull(compiler.fromEnvironment("not in env")); |
| 126 // Check client libraries are not present. | 121 // Check client libraries are not present. |
| 127 Expect.equals(null, compiler.fromEnvironment("dart.library.mock.client")); | 122 Expect.equals(null, compiler.fromEnvironment("dart.library.mock.client")); |
| 128 Expect.equals(null, compiler.fromEnvironment("dart.library.html")); | 123 Expect.equals(null, compiler.fromEnvironment("dart.library.html")); |
| 129 // Check for shared libraries.. | 124 // Check for shared libraries.. |
| 130 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared")); | 125 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared")); |
| 131 // Check for server libraries. | 126 // Check for server libraries. |
| 132 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.server")); | 127 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.server")); |
| 133 Expect.equals("true", compiler.fromEnvironment("dart.library.io")); | 128 Expect.equals("true", compiler.fromEnvironment("dart.library.io")); |
| 134 | 129 |
| 135 // Check that user-defined env-variables win. | 130 // Check that user-defined env-variables win. |
| 136 compiler = new CustomCompiler( | 131 compiler = new CustomCompiler([], |
| 137 [], | |
| 138 {'dart.library.collection': "false", | 132 {'dart.library.collection': "false", |
| 139 'dart.library.mock.client': "foo"}); | 133 'dart.library.mock.client': "foo"}); |
| 140 | 134 |
| 141 await compiler.setupSdk(); | 135 await compiler.setupSdk(); |
| 142 | 136 |
| 143 Expect.equals("false", compiler.fromEnvironment("dart.library.collection")); | 137 Expect.equals("false", compiler.fromEnvironment("dart.library.collection")); |
| 144 Expect.equals("foo", compiler.fromEnvironment("dart.library.mock.client")); | 138 Expect.equals("foo", compiler.fromEnvironment("dart.library.mock.client")); |
| 145 } | 139 } |
| 146 | 140 |
| 147 main() { | 141 main() { |
| 148 asyncStart(); | 142 asyncStart(); |
| 149 runTest().then((_) { | 143 runTest().then((_) { |
| 150 asyncEnd(); | 144 asyncEnd(); |
| 151 }); | 145 }); |
| 152 } | 146 } |
| OLD | NEW |