Chromium Code Reviews| 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 #library('pub_tests'); | 5 #library('pub_tests'); |
| 6 | 6 |
| 7 // TODO(rnystrom): Better path to unittest. | 7 #import('dart:io'); |
| 8 | |
| 9 #import('test_pub.dart'); | |
| 8 #import('../../../lib/unittest/unittest_vm.dart'); | 10 #import('../../../lib/unittest/unittest_vm.dart'); |
| 9 | 11 |
| 10 main() { | 12 main() { |
| 11 test('should pass', () { | 13 group('running pub with no command', () { |
| 12 expect(1).equals(1); | 14 testOutput('displays usage', |
| 15 [], | |
| 16 ''' | |
| 17 Pub is a package manager for Dart. | |
| 18 | |
| 19 Usage: | |
| 20 | |
| 21 pub command [arguments] | |
| 22 | |
| 23 The commands are: | |
| 24 | |
| 25 version print Pub version | |
| 26 | |
| 27 Use "pub help [command]" for more information about a command.'''); | |
| 28 }); | |
| 29 | |
| 30 group('the version command', () { | |
| 31 testOutput('displays the current version', | |
| 32 ['version'], 'Pub 0.0.0'); | |
| 33 }); | |
| 34 | |
| 35 group('an unknown command', () { | |
| 36 testOutput('displays an error message', | |
| 37 ['quylthulg'], | |
| 38 ''' | |
| 39 Unknown command "quylthulg". | |
| 40 Run "pub help" to see available commands.''', | |
| 41 exitCode: 64); | |
| 13 }); | 42 }); |
| 14 } | 43 } |
| 44 | |
| 45 void testPub(String description, List<String> arguments, String expectedOutput) { | |
|
nweiz
2012/03/30 00:38:37
This name doesn't match that being used in main(),
Bob Nystrom
2012/03/30 01:06:17
Oops, old code. Deleted.
| |
| 46 // TODO(bob): Figure out how to invoke pub correctly. | |
| 47 Expect.fail('args = ${new Options().script}'); | |
|
nweiz
2012/03/30 00:38:37
Debugging line?
| |
| 48 | |
| 49 final process = new Process.start('pub', arguments); | |
| 50 | |
| 51 final output = <String>[]; | |
| 52 final outStream = new StringInputStream(process.stdout); | |
| 53 outStream.onLine = () { | |
| 54 var line = outStream.readLine(); | |
| 55 while (line != null) { | |
| 56 output.add(line); | |
| 57 line = outStream.readLine(); | |
| 58 } | |
| 59 }; | |
| 60 | |
| 61 process.onError = (error) { | |
| 62 Expect.fail('Failed to run pub: $error'); | |
| 63 }; | |
| 64 | |
| 65 process.onExit = (exitCode) { | |
| 66 Expect.equals(exitCode, 0, 'Pub returned non-zero exit code.'); | |
| 67 validateOutput(expectedOutput, output); | |
| 68 }; | |
| 69 } | |
|
nweiz
2012/03/30 00:38:37
How does this async stuff integrate into the testi
Bob Nystrom
2012/03/30 01:06:17
Yeah, this is dead code. The real code is in test_
| |
| OLD | NEW |