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

Side by Side Diff: utils/tests/pub/test_pub.dart

Issue 12042053: Get rid of unneeded Future.immediate() calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« utils/pub/entrypoint.dart ('K') | « utils/pub/validator/name.dart ('k') | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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
11 import 'dart:async'; 11 import 'dart:async';
12 import 'dart:collection' show Queue; 12 import 'dart:collection' show Queue;
13 import 'dart:io'; 13 import 'dart:io';
14 import 'dart:json' as json; 14 import 'dart:json' as json;
15 import 'dart:math'; 15 import 'dart:math';
16 import 'dart:uri'; 16 import 'dart:uri';
17 17
18 import '../../../pkg/oauth2/lib/oauth2.dart' as oauth2; 18 import '../../../pkg/oauth2/lib/oauth2.dart' as oauth2;
19 import '../../../pkg/path/lib/path.dart' as path; 19 import '../../../pkg/path/lib/path.dart' as path;
20 import '../../../pkg/unittest/lib/unittest.dart'; 20 import '../../../pkg/unittest/lib/unittest.dart';
21 import '../../../pkg/http/lib/testing.dart'; 21 import '../../../pkg/http/lib/testing.dart';
22 import '../../lib/file_system.dart' as fs; 22 import '../../lib/file_system.dart' as fs;
23 import '../../pub/entrypoint.dart'; 23 import '../../pub/entrypoint.dart';
24 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides
25 // with the git descriptor method. Maybe we should try to clean up the top level
26 // scope a bit?
27 import '../../pub/git.dart' as gitlib;
24 import '../../pub/git_source.dart'; 28 import '../../pub/git_source.dart';
25 import '../../pub/hosted_source.dart'; 29 import '../../pub/hosted_source.dart';
26 import '../../pub/http.dart'; 30 import '../../pub/http.dart';
27 import '../../pub/io.dart'; 31 import '../../pub/io.dart';
28 import '../../pub/sdk_source.dart'; 32 import '../../pub/sdk_source.dart';
29 import '../../pub/system_cache.dart'; 33 import '../../pub/system_cache.dart';
30 import '../../pub/utils.dart'; 34 import '../../pub/utils.dart';
31 import '../../pub/validator.dart'; 35 import '../../pub/validator.dart';
32 import '../../pub/yaml/yaml.dart'; 36 import '../../pub/yaml/yaml.dart';
33 import 'command_line_config.dart'; 37 import 'command_line_config.dart';
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 void _run() { 472 void _run() {
469 var createdSandboxDir; 473 var createdSandboxDir;
470 var asyncDone = expectAsync0(() {}); 474 var asyncDone = expectAsync0(() {});
471 475
472 Future cleanup() { 476 Future cleanup() {
473 return _runScheduled(createdSandboxDir, _scheduledCleanup).then((_) { 477 return _runScheduled(createdSandboxDir, _scheduledCleanup).then((_) {
474 _scheduled = null; 478 _scheduled = null;
475 _scheduledCleanup = null; 479 _scheduledCleanup = null;
476 _scheduledOnException = null; 480 _scheduledOnException = null;
477 if (createdSandboxDir != null) return deleteDir(createdSandboxDir); 481 if (createdSandboxDir != null) return deleteDir(createdSandboxDir);
478 return new Future.immediate(null);
479 }); 482 });
480 } 483 }
481 484
482 timeout(_setUpSandbox().then((sandboxDir) { 485 timeout(_setUpSandbox().then((sandboxDir) {
483 createdSandboxDir = sandboxDir; 486 createdSandboxDir = sandboxDir;
484 return _runScheduled(sandboxDir, _scheduled); 487 return _runScheduled(sandboxDir, _scheduled);
485 }).catchError((e) { 488 }).catchError((e) {
486 // If an error occurs during testing, delete the sandbox, throw the error so 489 // If an error occurs during testing, delete the sandbox, throw the error so
487 // that the test framework sees it, then finally call asyncDone so that the 490 // that the test framework sees it, then finally call asyncDone so that the
488 // test framework knows we're done doing asynchronous stuff. 491 // test framework knows we're done doing asynchronous stuff.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 } 634 }
632 635
633 /// Skips the current test if Git is not installed. This validates that the 636 /// Skips the current test if Git is not installed. This validates that the
634 /// current test is running on a buildbot in which case we expect git to be 637 /// current test is running on a buildbot in which case we expect git to be
635 /// installed. If we are not running on the buildbot, we will instead see if 638 /// installed. If we are not running on the buildbot, we will instead see if
636 /// git is installed and skip the test if not. This way, users don't need to 639 /// git is installed and skip the test if not. This way, users don't need to
637 /// have git installed to run the tests locally (unless they actually care 640 /// have git installed to run the tests locally (unless they actually care
638 /// about the pub git tests). 641 /// about the pub git tests).
639 void ensureGit() { 642 void ensureGit() {
640 _schedule((_) { 643 _schedule((_) {
641 return isGitInstalled.then((installed) { 644 return gitlib.isInstalled.then((installed) {
642 if (!installed && 645 if (!installed &&
643 !Platform.environment.containsKey('BUILDBOT_BUILDERNAME')) { 646 !Platform.environment.containsKey('BUILDBOT_BUILDERNAME')) {
644 _abortScheduled = true; 647 _abortScheduled = true;
645 } 648 }
646 return null; 649 return null;
647 }); 650 });
648 }); 651 });
649 } 652 }
650 653
651 /// Use [client] as the mock HTTP client for this test. 654 /// Use [client] as the mock HTTP client for this test.
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 Future<String> _runGit(List<String> args, Directory workingDir) { 1061 Future<String> _runGit(List<String> args, Directory workingDir) {
1059 // Explicitly specify the committer information. Git needs this to commit 1062 // Explicitly specify the committer information. Git needs this to commit
1060 // and we don't want to rely on the buildbots having this already set up. 1063 // and we don't want to rely on the buildbots having this already set up.
1061 var environment = { 1064 var environment = {
1062 'GIT_AUTHOR_NAME': 'Pub Test', 1065 'GIT_AUTHOR_NAME': 'Pub Test',
1063 'GIT_AUTHOR_EMAIL': 'pub@dartlang.org', 1066 'GIT_AUTHOR_EMAIL': 'pub@dartlang.org',
1064 'GIT_COMMITTER_NAME': 'Pub Test', 1067 'GIT_COMMITTER_NAME': 'Pub Test',
1065 'GIT_COMMITTER_EMAIL': 'pub@dartlang.org' 1068 'GIT_COMMITTER_EMAIL': 'pub@dartlang.org'
1066 }; 1069 };
1067 1070
1068 return runGit(args, workingDir: workingDir.path, 1071 return gitlib.run(args, workingDir: workingDir.path,
1069 environment: environment).then((result) { 1072 environment: environment);
1070 if (!result.success) {
1071 throw "Error running: git ${Strings.join(args, ' ')}\n"
1072 "${Strings.join(result.stderr, '\n')}";
1073 }
1074
1075 return result.stdout;
1076 });
1077 } 1073 }
1078 } 1074 }
1079 1075
1080 /// Describes a gzipped tar file and its contents. 1076 /// Describes a gzipped tar file and its contents.
1081 class TarFileDescriptor extends Descriptor { 1077 class TarFileDescriptor extends Descriptor {
1082 final List<Descriptor> contents; 1078 final List<Descriptor> contents;
1083 1079
1084 TarFileDescriptor(Pattern name, this.contents) 1080 TarFileDescriptor(Pattern name, this.contents)
1085 : super(name); 1081 : super(name);
1086 1082
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 /// calling [completion] is unnecessary. 1553 /// calling [completion] is unnecessary.
1558 void expectLater(Future actual, matcher, {String reason, 1554 void expectLater(Future actual, matcher, {String reason,
1559 FailureHandler failureHandler, bool verbose: false}) { 1555 FailureHandler failureHandler, bool verbose: false}) {
1560 _schedule((_) { 1556 _schedule((_) {
1561 return actual.then((value) { 1557 return actual.then((value) {
1562 expect(value, matcher, reason: reason, failureHandler: failureHandler, 1558 expect(value, matcher, reason: reason, failureHandler: failureHandler,
1563 verbose: false); 1559 verbose: false);
1564 }); 1560 });
1565 }); 1561 });
1566 } 1562 }
OLDNEW
« utils/pub/entrypoint.dart ('K') | « utils/pub/validator/name.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698