Chromium Code Reviews

Side by Side Diff: tests/compiler/dart2js/library_env_test.dart

Issue 1404183002: Add support for 'dart.library.X' environment variables in dart2js. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove import. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « pkg/compiler/lib/src/apiimpl.dart ('k') | tests/language/language.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 LibraryInfo;
31
32 const clientPlatform = r'''
33 [dart-spec]
34 spec: 3rd edition.
35
36 [features]
37 # No extra features
38
39 [libraries]
40 mock.client: mock1.dart
41 mock.shared: mock3.dart
42 collection: collection/collection.dart
43 html: html/dart2js/html_dart2js.dart
44 ''';
45
46 const serverPlatform = r'''
47 [dart-spec]
48 spec: 3rd edition.
49
50 [features]
51 # No extra features
52
53 [libraries]
54 mock.server: mock2.dart
55 mock.shared: mock3.dart
56 collection: collection/collection.dart
57 io: io/io.dart
58 ''';
59
60 class DummyCompilerInput implements CompilerInput {
61 const DummyCompilerInput();
62
63 readFromUri(uri) async {
64 if (uri.toString().endsWith("dart_client.platform")) {
65 return clientPlatform;
66 } else if (uri.toString().endsWith("dart_server.platform")) {
67 return serverPlatform;
68 } else {
69 throw "should not be needed $uri";
70 }
71 }
72 }
73
74 class DummyCompilerDiagnostics implements CompilerDiagnostics {
75 const DummyCompilerDiagnostics();
76
77 report(code, uri, begin, end, text, kind) {
78 throw "should not be needed";
79 }
80 }
81
82 class CustomCompiler extends CompilerImpl {
83 CustomCompiler(
84 options,
85 environment)
86 : super(
87 const DummyCompilerInput(),
88 const NullCompilerOutput(),
89 const DummyCompilerDiagnostics(),
90 Uri.base.resolve("sdk/"),
91 null,
92 options,
93 environment);
94 }
95
96 runTest() async {
97 var compiler = new CustomCompiler(
98 [],
99 {});
100
101 await compiler.setupSdk();
102
103 // Core libraries are always present.
104 Expect.equals("true", compiler.fromEnvironment("dart.library.collection"));
105 // Non-existing entries in the environment return 'null'.
106 Expect.isNull(compiler.fromEnvironment("not in env"));
107 // Check for client libraries (default if there are no flags to the compiler).
108 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.client"));
109 Expect.equals("true", compiler.fromEnvironment("dart.library.html"));
110 // Check for shared libraries..
111 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared"));
112 // Check server libraries are not present.
113 Expect.equals(null, compiler.fromEnvironment("dart.library.mock.server"));
114 Expect.equals(null, compiler.fromEnvironment("dart.library.io"));
115
116 compiler = new CustomCompiler(
117 ['--categories=Server'],
118 {});
119
120 await compiler.setupSdk();
121
122 // Core libraries are always present.
123 Expect.equals("true", compiler.fromEnvironment("dart.library.collection"));
124 // Non-existing entries in the environment return 'null'.
125 Expect.isNull(compiler.fromEnvironment("not in env"));
126 // Check client libraries are not present.
127 Expect.equals(null, compiler.fromEnvironment("dart.library.mock.client"));
128 Expect.equals(null, compiler.fromEnvironment("dart.library.html"));
129 // Check for shared libraries..
130 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared"));
131 // Check for server libraries.
132 Expect.equals("true", compiler.fromEnvironment("dart.library.mock.server"));
133 Expect.equals("true", compiler.fromEnvironment("dart.library.io"));
134
135 // Check that user-defined env-variables win.
136 compiler = new CustomCompiler(
137 [],
138 {'dart.library.collection': "false",
139 'dart.library.mock.client': "foo"});
140
141 await compiler.setupSdk();
142
143 Expect.equals("false", compiler.fromEnvironment("dart.library.collection"));
144 Expect.equals("foo", compiler.fromEnvironment("dart.library.mock.client"));
145 }
146
147 main() {
148 asyncStart();
149 runTest().then((_) {
150 asyncEnd();
151 });
152 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/apiimpl.dart ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine