Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /// Check that 'dart:' libraries have their corresponding dart.library.X | |
| 6 /// environment variable set. | |
| 7 | |
| 8 import "dart:io"; | |
| 9 | |
| 10 import "dart:async"; | |
| 11 | |
| 12 import "memory_source_file_helper.dart"; | |
| 13 | |
| 14 import "package:async_helper/async_helper.dart"; | |
| 15 | |
| 16 import 'package:expect/expect.dart' show | |
| 17 Expect; | |
| 18 | |
| 19 import 'package:compiler/src/elements/elements.dart' show | |
| 20 LibraryElement; | |
| 21 | |
| 22 import 'package:compiler/src/null_compiler_output.dart' show | |
| 23 NullCompilerOutput; | |
| 24 | |
| 25 import 'package:compiler/compiler_new.dart' show | |
| 26 CompilerInput, | |
| 27 CompilerDiagnostics; | |
| 28 | |
| 29 import 'package:sdk_library_metadata/libraries.dart' show | |
| 30 DART2JS_PLATFORM, | |
|
sigurdm
2016/01/13 13:00:48
Import no longer needed
floitsch
2016/01/13 15:34:33
Thanks.
Done.
| |
| 31 LibraryInfo; | |
| 32 | |
| 33 const clientPlatform = r''' | |
| 34 [dart-spec] | |
| 35 spec: 3rd edition. | |
| 36 | |
| 37 [features] | |
| 38 # No extra features | |
| 39 | |
| 40 [libraries] | |
| 41 mock.client: mock1.dart | |
| 42 mock.shared: mock3.dart | |
| 43 collection: collection/collection.dart | |
| 44 html: html/dart2js/html_dart2js.dart | |
| 45 '''; | |
| 46 | |
| 47 const serverPlatform = r''' | |
| 48 [dart-spec] | |
| 49 spec: 3rd edition. | |
| 50 | |
| 51 [features] | |
| 52 # No extra features | |
| 53 | |
| 54 [libraries] | |
| 55 mock.server: mock2.dart | |
| 56 mock.shared: mock3.dart | |
| 57 collection: collection/collection.dart | |
| 58 io: io/io.dart | |
| 59 '''; | |
| 60 | |
| 61 class DummyCompilerInput implements CompilerInput { | |
| 62 const DummyCompilerInput(); | |
| 63 | |
| 64 readFromUri(uri) async { | |
| 65 if (uri.toString().endsWith("dart_client.platform")) { | |
| 66 return clientPlatform; | |
| 67 } else if (uri.toString().endsWith("dart_server.platform")) { | |
| 68 return serverPlatform; | |
| 69 } else { | |
| 70 throw "should not be needed $uri"; | |
| 71 } | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 class DummyCompilerDiagnostics implements CompilerDiagnostics { | |
| 76 const DummyCompilerDiagnostics(); | |
| 77 | |
| 78 report(code, uri, begin, end, text, kind) { | |
| 79 throw "should not be needed"; | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 class CustomCompiler extends CompilerImpl { | |
| 84 CustomCompiler( | |
| 85 options, | |
| 86 environment) | |
| 87 : super( | |
| 88 const DummyCompilerInput(), | |
| 89 const NullCompilerOutput(), | |
| 90 const DummyCompilerDiagnostics(), | |
| 91 Uri.base.resolve("sdk/"), | |
| 92 null, | |
| 93 options, | |
| 94 environment); | |
| 95 } | |
| 96 | |
| 97 runTest() async { | |
| 98 var compiler = new CustomCompiler( | |
| 99 [], | |
| 100 {}); | |
| 101 | |
| 102 await compiler.setupSdk(); | |
| 103 | |
| 104 // Core libraries are always present. | |
| 105 Expect.equals("true", compiler.fromEnvironment("dart.library.collection")); | |
| 106 // Non-existing entries in the environment return 'null'. | |
| 107 Expect.isNull(compiler.fromEnvironment("not in env")); | |
| 108 // Check for client libraries (default if there are no flags to the compiler). | |
| 109 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.client")); | |
| 110 Expect.equals("true", compiler.fromEnvironment("dart.library.html")); | |
| 111 // Check for shared libraries.. | |
| 112 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared")); | |
| 113 // Check server libraries are not present. | |
| 114 Expect.equals(null, compiler.fromEnvironment("dart.library.mock.server")); | |
| 115 Expect.equals(null, compiler.fromEnvironment("dart.library.io")); | |
| 116 | |
| 117 compiler = new CustomCompiler( | |
| 118 ['--categories=Server'], | |
| 119 {}); | |
| 120 | |
| 121 await compiler.setupSdk(); | |
| 122 | |
| 123 // Core libraries are always present. | |
| 124 Expect.equals("true", compiler.fromEnvironment("dart.library.collection")); | |
| 125 // Non-existing entries in the environment return 'null'. | |
| 126 Expect.isNull(compiler.fromEnvironment("not in env")); | |
| 127 // Check client libraries are not present. | |
| 128 Expect.equals(null, compiler.fromEnvironment("dart.library.mock.client")); | |
| 129 Expect.equals(null, compiler.fromEnvironment("dart.library.html")); | |
| 130 // Check for shared libraries.. | |
| 131 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared")); | |
| 132 // Check for server libraries. | |
| 133 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.server")); | |
| 134 Expect.equals("true", compiler.fromEnvironment("dart.library.io")); | |
| 135 | |
| 136 // Check that user-defined env-variables win. | |
| 137 compiler = new CustomCompiler( | |
| 138 [], | |
| 139 {'dart.library.collection': "false", | |
| 140 'dart.library.mock.client': "foo"}); | |
| 141 | |
| 142 await compiler.setupSdk(); | |
| 143 | |
| 144 Expect.equals("false", compiler.fromEnvironment("dart.library.collection")); | |
| 145 Expect.equals("foo", compiler.fromEnvironment("dart.library.mock.client")); | |
| 146 } | |
| 147 | |
| 148 main() { | |
| 149 asyncStart(); | |
| 150 runTest().then((_) { | |
| 151 asyncEnd(); | |
| 152 }); | |
| 153 } | |
| OLD | NEW |