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

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

Issue 9950005: First check in for pub package manager. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. Created 8 years, 8 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/pub.dart ('K') | « utils/tests/pub/pub_tests.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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
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
8 * pub, and then validate the results. This library provides an API to build
9 * tests like that.
10 */
11 #library('test_pub');
12
13 #import('dart:io');
14
15 #import('../../../lib/unittest/unittest_vm.dart');
16 #import('../../lib/file_system.dart');
17
18 void testOutput(String description, List<String> pubArgs, String expected,
19 [int exitCode = 0]) {
20 asyncTest(description, 1, () {
21 // Find a dart executable we can use to run pub. Uses the one that the
22 // test infrastructure uses.
23 final scriptDir = new File(new Options().script).directorySync().path;
24 final platform = new Platform().operatingSystem();
25 final dartBin = joinPaths(scriptDir,
26 '../../../tools/testing/bin/$platform/dart');
kasperl 2012/04/11 07:17:03 You sometimes indent these with 4 spaces and somet
Bob Nystrom 2012/04/11 16:50:23 Normal indentation should be 2 spaces, and line co
27
28 // Find the main pub entrypoint.
29 final pubPath = joinPaths(scriptDir, '../../pub/pub.dart');
30
31 final args = [pubPath];
32 args.addAll(pubArgs);
33
34 final process = new Process.start(dartBin, args);
35 final outStream = new StringInputStream(process.stdout);
36 final output = <String>[];
37 bool processDone = false;
38
39 checkComplete() {
40 if (!outStream.closed) return;
41 if (!processDone) return;
42
43 _validateOutput(expected, output);
44 callbackDone();
45 }
46
47 process.stderr.pipe(stderr, close: false);
48
49 outStream.onLine = () {
50 output.add(outStream.readLine());
51 };
52
53 outStream.onClosed = checkComplete;
54
55 process.onError = (error) {
56 Expect.fail('Failed to run pub: $error');
57 processDone = true;
58 };
59
60 process.onExit = (actualExitCode) {
61 Expect.equals(actualExitCode, exitCode,
62 'Pub returned exit code $actualExitCode, expected $exitCode.');
63 processDone = true;
64 checkComplete();
65 };
66 });
67 }
68
69 /**
70 * Compares the [actual] output from running pub with [expectedText]. Ignores
71 * leading and trailing whitespace differences and tries to report the
72 * offending difference in a nice way.
73 */
74 void _validateOutput(String expectedText, List<String> actual) {
75 final expected = expectedText.split('\n');
76
77 final length = Math.min(expected.length, actual.length);
78 for (var i = 0; i < length; i++) {
79 if (expected[i].trim() != actual[i].trim()) {
80 Expect.fail(
81 'Output line ${i + 1} was: ${actual[i]}\nexpected: ${expected[i]}');
82 }
83 }
84
85 if (expected.length > actual.length) {
86 final message = new StringBuffer();
87 message.add('Missing expected output:\n');
88 for (var i = actual.length; i < expected.length; i++) {
89 message.add(expected[i]);
90 message.add('\n');
91 }
92
93 Expect.fail(message.toString());
94 }
95
96 if (expected.length < actual.length) {
97 final message = new StringBuffer();
98 message.add('Unexpected output:\n');
99 for (var i = expected.length; i < actual.length; i++) {
100 message.add(actual[i]);
101 message.add('\n');
102 }
103
104 Expect.fail(message.toString());
105 }
106 }
OLDNEW
« utils/pub/pub.dart ('K') | « utils/tests/pub/pub_tests.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698