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 27 matching lines...) Expand all Loading... |
38 import '../../pub/system_cache.dart'; | 38 import '../../pub/system_cache.dart'; |
39 import '../../pub/utils.dart'; | 39 import '../../pub/utils.dart'; |
40 import '../../pub/validator.dart'; | 40 import '../../pub/validator.dart'; |
41 import 'command_line_config.dart'; | 41 import 'command_line_config.dart'; |
42 import 'descriptor.dart' as d; | 42 import 'descriptor.dart' as d; |
43 | 43 |
44 /// This should be called at the top of a test file to set up an appropriate | 44 /// This should be called at the top of a test file to set up an appropriate |
45 /// test configuration for the machine running the tests. | 45 /// test configuration for the machine running the tests. |
46 initConfig() { | 46 initConfig() { |
47 // If we aren't running on the bots, use the human-friendly config. | 47 // If we aren't running on the bots, use the human-friendly config. |
48 if (new Options().arguments.contains('--human')) { | 48 if (!runningOnBuildbot) { |
49 unittestConfiguration = new CommandLineConfiguration(); | 49 unittestConfiguration = new CommandLineConfiguration(); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
| 53 /// Returns whether we're running on a Dart build bot. |
| 54 bool runningOnBuildbot => |
| 55 Platform.environment.containsKey('BUILDBOT_BUILDERNAME'); |
| 56 |
53 /// The current [HttpServer] created using [serve]. | 57 /// The current [HttpServer] created using [serve]. |
54 var _server; | 58 var _server; |
55 | 59 |
56 /// The cached value for [_portCompleter]. | 60 /// The cached value for [_portCompleter]. |
57 Completer<int> _portCompleterCache; | 61 Completer<int> _portCompleterCache; |
58 | 62 |
59 /// The completer for [port]. | 63 /// The completer for [port]. |
60 Completer<int> get _portCompleter { | 64 Completer<int> get _portCompleter { |
61 if (_portCompleterCache != null) return _portCompleterCache; | 65 if (_portCompleterCache != null) return _portCompleterCache; |
62 _portCompleterCache = new Completer<int>(); | 66 _portCompleterCache = new Completer<int>(); |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 /// This will also increase the [Schedule] timeout to 30 seconds on Windows, | 396 /// This will also increase the [Schedule] timeout to 30 seconds on Windows, |
393 /// where Git runs really slowly. | 397 /// where Git runs really slowly. |
394 void ensureGit() { | 398 void ensureGit() { |
395 if (Platform.operatingSystem == "windows") { | 399 if (Platform.operatingSystem == "windows") { |
396 currentSchedule.timeout = new Duration(seconds: 30); | 400 currentSchedule.timeout = new Duration(seconds: 30); |
397 } | 401 } |
398 | 402 |
399 schedule(() { | 403 schedule(() { |
400 return gitlib.isInstalled.then((installed) { | 404 return gitlib.isInstalled.then((installed) { |
401 if (installed) return; | 405 if (installed) return; |
402 if (Platform.environment.containsKey('BUILDBOT_BUILDERNAME')) return; | 406 if (runningOnBuildbot) return; |
403 currentSchedule.abort(); | 407 currentSchedule.abort(); |
404 }); | 408 }); |
405 }, 'ensuring that Git is installed'); | 409 }, 'ensuring that Git is installed'); |
406 } | 410 } |
407 | 411 |
408 /// Use [client] as the mock HTTP client for this test. | 412 /// Use [client] as the mock HTTP client for this test. |
409 /// | 413 /// |
410 /// Note that this will only affect HTTP requests made via http.dart in the | 414 /// Note that this will only affect HTTP requests made via http.dart in the |
411 /// parent process. | 415 /// parent process. |
412 void useMockClient(MockClient client) { | 416 void useMockClient(MockClient client) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 bool matches(item, MatchState matchState) { | 605 bool matches(item, MatchState matchState) { |
602 if (item is! Pair) return false; | 606 if (item is! Pair) return false; |
603 return _firstMatcher.matches(item.first, matchState) && | 607 return _firstMatcher.matches(item.first, matchState) && |
604 _lastMatcher.matches(item.last, matchState); | 608 _lastMatcher.matches(item.last, matchState); |
605 } | 609 } |
606 | 610 |
607 Description describe(Description description) { | 611 Description describe(Description description) { |
608 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 612 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
609 } | 613 } |
610 } | 614 } |
OLD | NEW |