Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: tests/standalone/packages_file_test.dart

Issue 2015193002: Also add comments requested by review, and some more. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 "dart:convert" show JSON; 7 import "dart:convert" show JSON;
8 import "package:path/path.dart" as p; 8 import "package:path/path.dart" as p;
9 import "package:async_helper/async_helper.dart"; 9 import "package:async_helper/async_helper.dart";
10 10
11 main() async { 11 main() async {
12 asyncStart(); 12 asyncStart();
13 13
14 // The `test` function can generate file or http resources.
15 // It replaces "%file/" with URI of the root directory of generated files and
16 // "%http/" with the URI of the HTTP server's root in appropriate contexts
17 // (all file contents and parameters).
18
19 // With no specified resolutiuon and no implicit .packages or packages/
floitsch 2016/05/27 14:11:19 Resolution
20 // available, nothing can be resolved and the package can't be imported.
14 await test("file: no resolution", 21 await test("file: no resolution",
15 "%file/main.dart", 22 "%file/main.dart",
16 file: {"main": testMain}, 23 file: {"main": testMain},
17 expect: {"foo.x": null}); 24 expect: {"foo.x": null});
18 25
19 // An HTTP script with no ".packages" file assumes a "packages" dir. 26 // An HTTP script with no ".packages" file assumes a "packages" dir.
27 // All packages are resolved relative to that dir, whether it exists or not.
20 await test("http: no resolution", "%http/main.dart", 28 await test("http: no resolution", "%http/main.dart",
21 http: {"main": testMain}, 29 http: {"main": testMain},
22 expect: { 30 expect: {
23 "iroot": "%http/packages/", 31 "iroot": "%http/packages/",
24 // "foo": null, 32 // "foo": null,
25 "foo/": "%http/packages/foo/", 33 "foo/": "%http/packages/foo/",
26 "foo/bar": "%http/packages/foo/bar", 34 "foo/bar": "%http/packages/foo/bar",
27 "foo.x": null, 35 "foo.x": null,
28 }); 36 });
29 37
38 // A number of tests which behave similarly whether run as local files or
39 // over HTTP.
30 for (var scheme in ["file", "http"]) { 40 for (var scheme in ["file", "http"]) {
31 41
42 /// Run a test in the current scheme.
43 ///
44 /// The files are served either through HTTP or in a local directory.
45 /// Use "%$scheme/" to refer to the root of the served files.
32 testScheme(name, main, {expect, files, args, root, config}) { 46 testScheme(name, main, {expect, files, args, root, config}) {
33 return test("$scheme: $name", main, expect: expect, 47 return test("$scheme: $name", main, expect: expect,
34 root: root, config: config, args: args, 48 root: root, config: config, args: args,
35 file: scheme == "file" ? files : null, 49 file: scheme == "file" ? files : null,
36 http: scheme == "http" ? files : null); 50 http: scheme == "http" ? files : null);
37 } 51 }
38 52
39 { 53 {
40 var files = {"main": testMain, "packages": fooPackage}; 54 var files = {"main": testMain, "packages": fooPackage};
41 // Expect implicitly detected package dir. 55 // Expect implicitly detected package dir.
42 await testScheme("implicit packages dir","%$scheme/main.dart", 56 await testScheme("implicit packages dir","%$scheme/main.dart",
43 files: files, 57 files: files,
44 expect: { 58 expect: {
45 "iroot": "%$scheme/packages/", 59 "iroot": "%$scheme/packages/",
46 // "foo": null, 60 // "foo": null,
47 "foo/": "%$scheme/packages/foo/", 61 "foo/": "%$scheme/packages/foo/",
48 "foo/bar": "%$scheme/packages/foo/bar", 62 "foo/bar": "%$scheme/packages/foo/bar",
49 }); 63 });
50 } 64 }
51 65
52 { 66 {
53 var files = {"sub": {"main": testMain, "packages": fooPackage}, 67 var files = {"sub": {"main": testMain, "packages": fooPackage},
54 ".packages": ""}; 68 ".packages": ""};
55 // Expect implicitly detected package dir. 69 // Expect implicitly detected package dir.
70 // Should not detect the .packages file in parent directory.
71 // That file is empty, so if it is used, the system cannot resolve "foo".
56 await testScheme("implicit packages dir 2", "%$scheme/sub/main.dart", 72 await testScheme("implicit packages dir 2", "%$scheme/sub/main.dart",
57 files: files, 73 files: files,
58 expect: { 74 expect: {
59 "iroot": "%$scheme/sub/packages/", 75 "iroot": "%$scheme/sub/packages/",
60 // "foo": null, 76 // "foo": null,
61 "foo/": "%$scheme/sub/packages/foo/", 77 "foo/": "%$scheme/sub/packages/foo/",
62 "foo/bar": "%$scheme/sub/packages/foo/bar", 78 "foo/bar": "%$scheme/sub/packages/foo/bar",
63 }); 79 });
64 } 80 }
65 81
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 expect: { 139 expect: {
124 "pconf": "%$scheme/.pkgs", 140 "pconf": "%$scheme/.pkgs",
125 "iconf": "%$scheme/.pkgs", 141 "iconf": "%$scheme/.pkgs",
126 // "foo": null, 142 // "foo": null,
127 "foo/": "%$scheme/pkgs/foo/", 143 "foo/": "%$scheme/pkgs/foo/",
128 "foo/bar": "%$scheme/pkgs/foo/bar", 144 "foo/bar": "%$scheme/pkgs/foo/bar",
129 }); 145 });
130 } 146 }
131 147
132 { 148 {
149 /// The package config can be specified as a data: URI.
150 /// (In that case, relative URI references in the config file won't work).
133 var files = {"main": testMain, 151 var files = {"main": testMain,
134 ".packages": "foo:packages/foo/", 152 ".packages": "foo:packages/foo/",
135 "packages": fooPackage, 153 "packages": fooPackage,
136 "pkgs": fooPackage}; 154 "pkgs": fooPackage};
137 var dataUri = "data:,foo:%$scheme/pkgs/foo/\n"; 155 var dataUri = "data:,foo:%$scheme/pkgs/foo/\n";
138 await testScheme("explicit data: config file", "%$scheme/main.dart", 156 await testScheme("explicit data: config file", "%$scheme/main.dart",
139 files: files, 157 files: files,
140 config: dataUri, 158 config: dataUri,
141 expect: { 159 expect: {
142 "pconf": dataUri, 160 "pconf": dataUri,
143 "iconf": dataUri, 161 "iconf": dataUri,
144 // "foo": null, 162 // "foo": null,
145 "foo/": "%$scheme/pkgs/foo/", 163 "foo/": "%$scheme/pkgs/foo/",
146 "foo/bar": "%$scheme/pkgs/foo/bar", 164 "foo/bar": "%$scheme/pkgs/foo/bar",
147 }); 165 });
148 } 166 }
149 } 167 }
150 168
151 { 169 {
152 // With a file: URI, the lookup checks for a .packages file in superdirs. 170 // With a file: URI, the lookup checks for a .packages file in superdirs
171 // when it fails to find a ,packages file or packages/ directory next to
172 // the entry point.
153 var files = {"sub": { "main": testMain }, 173 var files = {"sub": { "main": testMain },
154 ".packages": "foo:pkgs/foo/", 174 ".packages": "foo:pkgs/foo/",
155 "pkgs": fooPackage}; 175 "pkgs": fooPackage};
156 await test("file: implicit .packages file in ..", "%file/sub/main.dart", 176 await test("file: implicit .packages file in ..", "%file/sub/main.dart",
157 file: files, 177 file: files,
158 expect: { 178 expect: {
159 "iconf": "%file/.packages", 179 "iconf": "%file/.packages",
160 // "foo": null, 180 // "foo": null,
161 "foo/": "%file/pkgs/foo/", 181 "foo/": "%file/pkgs/foo/",
162 "foo/bar": "%file/pkgs/foo/bar", 182 "foo/bar": "%file/pkgs/foo/bar",
163 }); 183 });
164 } 184 }
165 185
166 { 186 {
167 // With a non-file: URI, the lookup assumes a packges/ dir. 187 // With a non-file: URI, the lookup assumes a packges/ dir.
188 // The absence of a .packages file next to the entry point means
189 // that the resolution assumes a packages directory, whether it exists or
190 // not. It should not find the .packages file in the parent directory.
168 var files = {"sub": { "main": testMain }, 191 var files = {"sub": { "main": testMain },
169 ".packages": "foo:pkgs/foo/", 192 ".packages": "foo:pkgs/foo/",
170 "pkgs": fooPackage}; 193 "pkgs": fooPackage};
171 // Expect implicitly detected .package file.
172 await test("http: implicit packages dir", "%http/sub/main.dart", 194 await test("http: implicit packages dir", "%http/sub/main.dart",
173 http: files, 195 http: files,
174 expect: { 196 expect: {
175 "iroot": "%http/sub/packages/", 197 "iroot": "%http/sub/packages/",
176 // "foo": null, 198 // "foo": null,
177 "foo/": "%http/sub/packages/foo/", 199 "foo/": "%http/sub/packages/foo/",
178 "foo/bar": "%http/sub/packages/foo/bar", 200 "foo/bar": "%http/sub/packages/foo/bar",
179 "foo.x": null, 201 "foo.x": null,
180 }); 202 });
181 } 203 }
(...skipping 11 matching lines...) Expand all
193 215
194 var failingTests = new Set(); 216 var failingTests = new Set();
195 217
196 var fileHttpRegexp = new RegExp(r"%(?:file|http)/"); 218 var fileHttpRegexp = new RegExp(r"%(?:file|http)/");
197 219
198 Future test(String name, String main, 220 Future test(String name, String main,
199 {String root, String config, List<String> args, 221 {String root, String config, List<String> args,
200 Map file, Map http, Map expect}) async { 222 Map file, Map http, Map expect}) async {
201 // Default values that are easily recognized in output. 223 // Default values that are easily recognized in output.
202 String fileRoot = "<no files configured>"; 224 String fileRoot = "<no files configured>";
203 String httpRoot = "<not http server configured>"; 225 String httpRoot = "<no http server configured>";
204 226
205 /// Replaces markers `%file/` and `%http/` with the actual locations. 227 /// Replaces markers `%file/` and `%http/` with the actual locations.
206 /// 228 ///
207 /// Accepts a `null` [source] and returns `null` again. 229 /// Accepts a `null` [source] and returns `null` again.
208 String fixPaths(String source) { 230 String fixPaths(String source) {
209 if (source == null) return null; 231 if (source == null) return null;
210 var result = source.replaceAllMapped(fileHttpRegexp, (match) { 232 var result = source.replaceAllMapped(fileHttpRegexp, (match) {
211 if (source.startsWith("file", match.start + 1)) return fileRoot; 233 if (source.startsWith("file", match.start + 1)) return fileRoot;
212 return httpRoot; 234 return httpRoot;
213 }); 235 });
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 489 }
468 490
469 // Counter used to avoid reusing temporary directory names. 491 // Counter used to avoid reusing temporary directory names.
470 // Some platforms are timer based, and creating two temp-dirs withing a short 492 // Some platforms are timer based, and creating two temp-dirs withing a short
471 // duration may cause a collision. 493 // duration may cause a collision.
472 int tmpDirCounter = 0; 494 int tmpDirCounter = 0;
473 495
474 Directory createTempDir() { 496 Directory createTempDir() {
475 return Directory.systemTemp.createTempSync("pftest-${tmpDirCounter++}-"); 497 return Directory.systemTemp.createTempSync("pftest-${tmpDirCounter++}-");
476 } 498 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698