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, |
| 31 LibraryInfo; |
| 32 |
| 33 const LibraryInfo mock1LibraryInfo = const LibraryInfo( |
| 34 "mock1.dart", |
| 35 category: "Client", |
| 36 documented: false, |
| 37 platforms: DART2JS_PLATFORM); |
| 38 |
| 39 const LibraryInfo mock2LibraryInfo = const LibraryInfo( |
| 40 "mock2.dart", |
| 41 category: "Server", |
| 42 documented: false, |
| 43 platforms: DART2JS_PLATFORM); |
| 44 |
| 45 const LibraryInfo mock3LibraryInfo = const LibraryInfo( |
| 46 "mock3.dart", |
| 47 category: "Shared", |
| 48 documented: false, |
| 49 platforms: DART2JS_PLATFORM); |
| 50 |
| 51 class DummyCompilerInput implements CompilerInput { |
| 52 const DummyCompilerInput(); |
| 53 |
| 54 readFromUri(uri) { |
| 55 throw "should not be needed"; |
| 56 } |
| 57 } |
| 58 |
| 59 class DummyCompilerDiagnostics implements CompilerDiagnostics { |
| 60 const DummyCompilerDiagnostics(); |
| 61 |
| 62 report(code, uri, begin, end, text, kind) { |
| 63 throw "should not be needed"; |
| 64 } |
| 65 } |
| 66 |
| 67 class CustomCompiler extends Compiler { |
| 68 CustomCompiler( |
| 69 options, |
| 70 environment) |
| 71 : super( |
| 72 const DummyCompilerInput(), |
| 73 const NullCompilerOutput(), |
| 74 const DummyCompilerDiagnostics(), |
| 75 Uri.base.resolve("sdk/"), |
| 76 null, |
| 77 options, |
| 78 environment); |
| 79 |
| 80 LibraryInfo lookupLibraryInfo(String name) { |
| 81 if (name == "mock.client") return mock1LibraryInfo; |
| 82 if (name == "mock.server") return mock2LibraryInfo; |
| 83 if (name == "mock.shared") return mock3LibraryInfo; |
| 84 return super.lookupLibraryInfo(name); |
| 85 } |
| 86 } |
| 87 |
| 88 main() { |
| 89 Compiler compiler = new CustomCompiler( |
| 90 [], |
| 91 {}); |
| 92 |
| 93 // Core libraries are always present. |
| 94 Expect.equals("true", compiler.fromEnvironment("dart.library.collection")); |
| 95 // Non-existing entries in the environment return 'null'. |
| 96 Expect.isNull(compiler.fromEnvironment("not in env")); |
| 97 // Check for client libraries (default if there are no flags to the compiler). |
| 98 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.client")); |
| 99 Expect.equals("true", compiler.fromEnvironment("dart.library.html")); |
| 100 // Check for shared libraries.. |
| 101 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared")); |
| 102 // Check server libraries are not present. |
| 103 Expect.equals(null, compiler.fromEnvironment("dart.library.mock.server")); |
| 104 Expect.equals(null, compiler.fromEnvironment("dart.library.io")); |
| 105 |
| 106 compiler = new CustomCompiler( |
| 107 ['--categories=Server'], |
| 108 {}); |
| 109 |
| 110 // Core libraries are always present. |
| 111 Expect.equals("true", compiler.fromEnvironment("dart.library.collection")); |
| 112 // Non-existing entries in the environment return 'null'. |
| 113 Expect.isNull(compiler.fromEnvironment("not in env")); |
| 114 // Check client libraries are not present. |
| 115 Expect.equals(null, compiler.fromEnvironment("dart.library.mock.client")); |
| 116 Expect.equals(null, compiler.fromEnvironment("dart.library.html")); |
| 117 // Check for shared libraries.. |
| 118 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared")); |
| 119 // Check for server libraries. |
| 120 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.server")); |
| 121 Expect.equals("true", compiler.fromEnvironment("dart.library.io")); |
| 122 |
| 123 // Check that user-defined env-variables win. |
| 124 compiler = new CustomCompiler( |
| 125 [], |
| 126 {'dart.library.collection': "false", |
| 127 'dart.library.mock.client': "foo"}); |
| 128 Expect.equals("false", compiler.fromEnvironment("dart.library.collection")); |
| 129 Expect.equals("foo", compiler.fromEnvironment("dart.library.mock.client")); |
| 130 } |
OLD | NEW |