OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub | 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub |
6 /// tests are integration tests that stage some stuff on the file system, run | 6 /// tests are integration tests that stage some stuff on the file system, run |
7 /// pub, and then validate the results. This library provides an API to build | 7 /// pub, and then validate the results. This library provides an API to build |
8 /// tests like that. | 8 /// tests like that. |
9 library test_pub; | 9 library test_pub; |
10 | 10 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 String yaml(value) => JSON.encode(value); | 241 String yaml(value) => JSON.encode(value); |
242 | 242 |
243 /// The full path to the created sandbox directory for an integration test. | 243 /// The full path to the created sandbox directory for an integration test. |
244 String get sandboxDir => _sandboxDir; | 244 String get sandboxDir => _sandboxDir; |
245 String _sandboxDir; | 245 String _sandboxDir; |
246 | 246 |
247 /// The path of the package cache directory used for tests. Relative to the | 247 /// The path of the package cache directory used for tests. Relative to the |
248 /// sandbox directory. | 248 /// sandbox directory. |
249 final String cachePath = "cache"; | 249 final String cachePath = "cache"; |
250 | 250 |
251 /// The path of the mock SDK directory used for tests. Relative to the sandbox | |
252 /// directory. | |
253 final String sdkPath = "sdk"; | |
254 | |
255 /// The path of the mock app directory used for tests. Relative to the sandbox | 251 /// The path of the mock app directory used for tests. Relative to the sandbox |
256 /// directory. | 252 /// directory. |
257 final String appPath = "myapp"; | 253 final String appPath = "myapp"; |
258 | 254 |
259 /// The path of the packages directory in the mock app used for tests. Relative | 255 /// The path of the packages directory in the mock app used for tests. Relative |
260 /// to the sandbox directory. | 256 /// to the sandbox directory. |
261 final String packagesPath = "$appPath/packages"; | 257 final String packagesPath = "$appPath/packages"; |
262 | 258 |
263 /// Set to true when the current batch of scheduled events should be aborted. | 259 /// Set to true when the current batch of scheduled events should be aborted. |
264 bool _abortScheduled = false; | 260 bool _abortScheduled = false; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 void solo_integration(String description, void body()) => | 329 void solo_integration(String description, void body()) => |
334 _integration(description, body, solo_test); | 330 _integration(description, body, solo_test); |
335 | 331 |
336 void _integration(String description, void body(), [Function testFn]) { | 332 void _integration(String description, void body(), [Function testFn]) { |
337 testFn(description, () { | 333 testFn(description, () { |
338 // The windows bots are very slow, so we increase the default timeout. | 334 // The windows bots are very slow, so we increase the default timeout. |
339 if (Platform.operatingSystem == "windows") { | 335 if (Platform.operatingSystem == "windows") { |
340 currentSchedule.timeout = new Duration(seconds: 10); | 336 currentSchedule.timeout = new Duration(seconds: 10); |
341 } | 337 } |
342 | 338 |
343 // Ensure the SDK version is always available. | |
344 d.dir(sdkPath, [ | |
345 d.file('version', '0.1.2.3') | |
346 ]).create(); | |
347 | |
348 _sandboxDir = createSystemTempDir(); | 339 _sandboxDir = createSystemTempDir(); |
349 d.defaultRoot = sandboxDir; | 340 d.defaultRoot = sandboxDir; |
350 currentSchedule.onComplete.schedule(() => deleteEntry(_sandboxDir), | 341 currentSchedule.onComplete.schedule(() => deleteEntry(_sandboxDir), |
351 'deleting the sandbox directory'); | 342 'deleting the sandbox directory'); |
352 | 343 |
353 // Schedule the test. | 344 // Schedule the test. |
354 body(); | 345 body(); |
355 }); | 346 }); |
356 } | 347 } |
357 | 348 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 | 467 |
477 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, | 468 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, |
478 '--verbose']; | 469 '--verbose']; |
479 dartArgs.addAll(args); | 470 dartArgs.addAll(args); |
480 | 471 |
481 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); | 472 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); |
482 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { | 473 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { |
483 var environment = {}; | 474 var environment = {}; |
484 environment['_PUB_TESTING'] = 'true'; | 475 environment['_PUB_TESTING'] = 'true'; |
485 environment['PUB_CACHE'] = pathInSandbox(cachePath); | 476 environment['PUB_CACHE'] = pathInSandbox(cachePath); |
486 environment['DART_SDK'] = pathInSandbox(sdkPath); | 477 |
| 478 // Ensure a known SDK version is set for the tests that rely on that. |
| 479 environment['_PUB_TEST_SDK_VERSION'] = "0.1.2+3"; |
| 480 |
487 if (tokenEndpoint != null) { | 481 if (tokenEndpoint != null) { |
488 environment['_PUB_TEST_TOKEN_ENDPOINT'] = | 482 environment['_PUB_TEST_TOKEN_ENDPOINT'] = |
489 tokenEndpoint.toString(); | 483 tokenEndpoint.toString(); |
490 } | 484 } |
491 | 485 |
492 // If there is a server running, tell pub what its URL is so hosted | 486 // If there is a server running, tell pub what its URL is so hosted |
493 // dependencies will look there. | 487 // dependencies will look there. |
494 if (_hasServer) { | 488 if (_hasServer) { |
495 return port.then((p) { | 489 return port.then((p) { |
496 environment['PUB_HOSTED_URL'] = "http://127.0.0.1:$p"; | 490 environment['PUB_HOSTED_URL'] = "http://127.0.0.1:$p"; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 bool matches(item, Map matchState) { | 842 bool matches(item, Map matchState) { |
849 if (item is! Pair) return false; | 843 if (item is! Pair) return false; |
850 return _firstMatcher.matches(item.first, matchState) && | 844 return _firstMatcher.matches(item.first, matchState) && |
851 _lastMatcher.matches(item.last, matchState); | 845 _lastMatcher.matches(item.last, matchState); |
852 } | 846 } |
853 | 847 |
854 Description describe(Description description) { | 848 Description describe(Description description) { |
855 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 849 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
856 } | 850 } |
857 } | 851 } |
OLD | NEW |