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

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

Issue 10340005: Add support for pub install. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 8 years, 7 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
« no previous file with comments | « utils/tests/pub/pub_test.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 /** 5 /**
6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub 6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub
7 * tests are integration tests that stage some stuff on the file system, run 7 * tests are integration tests that stage some stuff on the file system, run
8 * pub, and then validate the results. This library provides an API to build 8 * pub, and then validate the results. This library provides an API to build
9 * tests like that. 9 * tests like that.
10 */ 10 */
(...skipping 12 matching lines...) Expand all
23 new FileDescriptor(name, contents); 23 new FileDescriptor(name, contents);
24 24
25 /** 25 /**
26 * Creates a new [DirectoryDescriptor] with [name] and [contents]. 26 * Creates a new [DirectoryDescriptor] with [name] and [contents].
27 */ 27 */
28 DirectoryDescriptor dir(String name, [List<Descriptor> contents]) => 28 DirectoryDescriptor dir(String name, [List<Descriptor> contents]) =>
29 new DirectoryDescriptor(name, contents); 29 new DirectoryDescriptor(name, contents);
30 30
31 void testPub(String description, [List<Descriptor> cache, Descriptor app, 31 void testPub(String description, [List<Descriptor> cache, Descriptor app,
32 List<String> args, List<Descriptor> expectedPackageDir, 32 List<String> args, List<Descriptor> expectedPackageDir,
33 String output, int exitCode = 0]) { 33 List<Descriptor> sdk, String output, int exitCode = 0]) {
34 asyncTest(description, 1, () { 34 asyncTest(description, 1, () {
35 var createdSandboxDir; 35 var createdSandboxDir;
36 var createdAppDir; 36 var createdAppDir;
37 var createdSdkDir;
37 38
38 deleteSandboxIfCreated() { 39 deleteSandboxIfCreated() {
39 if (createdSandboxDir != null) { 40 if (createdSandboxDir != null) {
40 deleteDir(createdSandboxDir).then((_) { 41 deleteDir(createdSandboxDir).then((_) {
41 callbackDone(); 42 callbackDone();
42 }); 43 });
43 } else { 44 } else {
44 callbackDone(); 45 callbackDone();
45 } 46 }
46 } 47 }
47 48
48 final future = _setUpSandbox().chain((sandboxDir) { 49 final future = _setUpSandbox().chain((sandboxDir) {
49 createdSandboxDir = sandboxDir; 50 createdSandboxDir = sandboxDir;
50 return _setUpApp(sandboxDir, app); 51 return _setUpApp(sandboxDir, app);
51 }).chain((appDir) { 52 }).chain((appDir) {
52 createdAppDir = appDir; 53 createdAppDir = appDir;
54 return _setUpSdk(createdSandboxDir, sdk);
55 }).chain((sdkDir) {
56 createdSdkDir = sdkDir;
53 return _setUpCache(createdSandboxDir, cache); 57 return _setUpCache(createdSandboxDir, cache);
54 }).chain((cacheDir) { 58 }).chain((cacheDir) {
55 var workingDir; 59 var workingDir;
56 if (createdAppDir != null) workingDir = createdAppDir.path; 60 if (createdAppDir != null) workingDir = createdAppDir.path;
57 61
58 if (cacheDir != null) { 62 if (cacheDir != null) {
59 // TODO(rnystrom): Hack in the cache directory path. Should pass this 63 // TODO(rnystrom): Hack in the cache directory path. Should pass this
60 // in using environment var once #752 is done. 64 // in using environment var once #752 is done.
61 args.add('--cachedir=${getFullPath(cacheDir)}'); 65 args.add('--cachedir=${getFullPath(cacheDir)}');
62 } 66 }
63 67
68 if (createdSdkDir != null) {
69 // TODO(rnystrom): Hack in the SDK path. Should pass this in using
70 // environment var once #752 is done.
71 args.add('--sdkdir=${getFullPath(createdSdkDir)}');
72 }
73
64 return _runPub(args, workingDir); 74 return _runPub(args, workingDir);
65 }).chain((result) { 75 }).chain((result) {
66 _validateOutput(output, result.stdout); 76 _validateOutput(output, result.stdout);
67 77
68 Expect.equals(result.stderr.length, 0, 78 Expect.equals(result.stderr.length, 0,
69 'Did not expect any output on stderr, and got:\n' + 79 'Did not expect any output on stderr, and got:\n' +
70 Strings.join(result.stderr, '\n')); 80 Strings.join(result.stderr, '\n'));
71 81
72 Expect.equals(result.exitCode, exitCode, 82 Expect.equals(result.exitCode, exitCode,
73 'Pub returned exit code ${result.exitCode}, expected $exitCode.'); 83 'Pub returned exit code ${result.exitCode}, expected $exitCode.');
74 84
75 return _validateExpectedPackages(createdAppDir, expectedPackageDir); 85 return _validateExpectedPackages(createdAppDir, expectedPackageDir);
76 }); 86 });
77 87
78 future.then((error) { 88 future.then((error) {
79 // Null means there were no errors. 89 // Null means there were no errors.
80 if (error != null) Expect.fail(error); 90 if (error != null) Expect.fail(error);
81 91
82 deleteSandboxIfCreated(); 92 deleteSandboxIfCreated();
83 }); 93 });
84 94
85 future.handleException((error) { 95 future.handleException((error) {
86 deleteSandboxIfCreated(); 96 deleteSandboxIfCreated();
87 return false; 97 // If we encounter an error, we want to pass it to the test framework. In
98 // order to get the stack trace information, we need to re-throw and
99 // re-catch it.
100 try {
101 throw error;
102 } catch (var e, var stack) {
103 reportTestError('$e', '$stack');
104 }
105 return true;
88 }); 106 });
89 }); 107 });
90 } 108 }
91 109
92 Future<Directory> _setUpSandbox() { 110 Future<Directory> _setUpSandbox() {
93 return createTempDir('pub-test-sandbox-'); 111 return createTempDir('pub-test-sandbox-');
94 } 112 }
95 113
96 Future _setUpCache(Directory sandboxDir, List<Descriptor> cache) { 114 Future _setUpCache(Directory sandboxDir, List<Descriptor> cache) {
97 // No cache. 115 // No cache.
98 if (cache == null) return new Future.immediate(null); 116 if (cache == null) return new Future.immediate(null);
99 117
100 return dir('pub-cache', cache).create(sandboxDir); 118 return dir('pub-cache', cache).create(sandboxDir);
101 } 119 }
102 120
103 Future _setUpApp(Directory sandboxDir, Descriptor app) { 121 Future _setUpApp(Directory sandboxDir, Descriptor app) {
104 // No app directory. 122 // No app directory.
105 if (app == null) return new Future.immediate(null); 123 if (app == null) return new Future.immediate(null);
106 124
107 return app.create(sandboxDir); 125 return app.create(sandboxDir);
108 } 126 }
109 127
128 Future _setUpSdk(Directory sandboxDir, List<Descriptor> sdk) {
129 // No SDK directory.
130 if (sdk == null) return new Future.immediate(null);
131
132 return dir('sdk', sdk).create(sandboxDir);
133 }
134
110 Future<ProcessResult> _runPub(List<String> pubArgs, String workingDir) { 135 Future<ProcessResult> _runPub(List<String> pubArgs, String workingDir) {
111 // Find a dart executable we can use to run pub. Uses the one that the 136 // Find a dart executable we can use to run pub. Uses the one that the
112 // test infrastructure uses. 137 // test infrastructure uses.
113 final scriptDir = new File(new Options().script).directorySync().path; 138 final scriptDir = new File(new Options().script).directorySync().path;
114 final platform = Platform.operatingSystem(); 139 final platform = Platform.operatingSystem();
115 final dartBin = join(scriptDir, '../../../tools/testing/bin/$platform/dart'); 140 final dartBin = join(scriptDir, '../../../tools/testing/bin/$platform/dart');
116 141
117 // Find the main pub entrypoint. 142 // Find the main pub entrypoint.
118 final pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart'); 143 final pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart');
119 144
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 return Futures.wait(entryFutures).transform((entries) { 324 return Futures.wait(entryFutures).transform((entries) {
300 for (final entry in entries) { 325 for (final entry in entries) {
301 if (entry != null) return entry; 326 if (entry != null) return entry;
302 } 327 }
303 328
304 // If we got here, all of the sub-entries were valid. 329 // If we got here, all of the sub-entries were valid.
305 return null; 330 return null;
306 }); 331 });
307 } 332 }
308 } 333 }
OLDNEW
« no previous file with comments | « utils/tests/pub/pub_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698