| OLD | NEW |
| 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 */ |
| 11 #library('test_pub'); | 11 #library('test_pub'); |
| 12 | 12 |
| 13 #import('dart:io'); | 13 #import('dart:io'); |
| 14 #import('dart:isolate'); | 14 #import('dart:isolate'); |
| 15 #import('dart:json'); | 15 #import('dart:json'); |
| 16 #import('dart:math'); |
| 16 #import('dart:uri'); | 17 #import('dart:uri'); |
| 17 | 18 |
| 18 #import('../../../pkg/unittest/unittest.dart'); | 19 #import('../../../pkg/unittest/unittest.dart'); |
| 19 #import('../../lib/file_system.dart', prefix: 'fs'); | 20 #import('../../lib/file_system.dart', prefix: 'fs'); |
| 20 #import('../../pub/io.dart'); | 21 #import('../../pub/io.dart'); |
| 21 #import('../../pub/utils.dart'); | 22 #import('../../pub/utils.dart'); |
| 22 #import('../../pub/yaml/yaml.dart'); | 23 #import('../../pub/yaml/yaml.dart'); |
| 23 | 24 |
| 24 /** | 25 /** |
| 25 * Creates a new [FileDescriptor] with [name] and [contents]. | 26 * Creates a new [FileDescriptor] with [name] and [contents]. |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 } | 358 } |
| 358 | 359 |
| 359 void _validateOutputString(String expectedText, List<String> actual) { | 360 void _validateOutputString(String expectedText, List<String> actual) { |
| 360 final expected = expectedText.split('\n'); | 361 final expected = expectedText.split('\n'); |
| 361 | 362 |
| 362 // Strip off the last line. This lets us have expected multiline strings | 363 // Strip off the last line. This lets us have expected multiline strings |
| 363 // where the closing ''' is on its own line. It also fixes '' expected output | 364 // where the closing ''' is on its own line. It also fixes '' expected output |
| 364 // to expect zero lines of output, not a single empty line. | 365 // to expect zero lines of output, not a single empty line. |
| 365 expected.removeLast(); | 366 expected.removeLast(); |
| 366 | 367 |
| 367 final length = Math.min(expected.length, actual.length); | 368 final length = min(expected.length, actual.length); |
| 368 for (var i = 0; i < length; i++) { | 369 for (var i = 0; i < length; i++) { |
| 369 if (expected[i].trim() != actual[i].trim()) { | 370 if (expected[i].trim() != actual[i].trim()) { |
| 370 Expect.fail( | 371 Expect.fail( |
| 371 'Output line ${i + 1} was: ${actual[i]}\nexpected: ${expected[i]}'); | 372 'Output line ${i + 1} was: ${actual[i]}\nexpected: ${expected[i]}'); |
| 372 } | 373 } |
| 373 } | 374 } |
| 374 | 375 |
| 375 if (expected.length > actual.length) { | 376 if (expected.length > actual.length) { |
| 376 final message = new StringBuffer(); | 377 final message = new StringBuffer(); |
| 377 message.add('Missing expected output:\n'); | 378 message.add('Missing expected output:\n'); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 } | 812 } |
| 812 | 813 |
| 813 /** | 814 /** |
| 814 * Schedules a callback to be called after Pub is run with [runPub], even if it | 815 * Schedules a callback to be called after Pub is run with [runPub], even if it |
| 815 * fails. | 816 * fails. |
| 816 */ | 817 */ |
| 817 void _scheduleCleanup(_ScheduledEvent event) { | 818 void _scheduleCleanup(_ScheduledEvent event) { |
| 818 if (_scheduledCleanup == null) _scheduledCleanup = []; | 819 if (_scheduledCleanup == null) _scheduledCleanup = []; |
| 819 _scheduledCleanup.add(event); | 820 _scheduledCleanup.add(event); |
| 820 } | 821 } |
| OLD | NEW |