Skip to content

Commit 00af2b5

Browse files
authored
Add a basic test for each of the three "cat" commands (#1945)
Contributes to #1803. Followup to #1902. * Move cat_no_hash.dart from lib to bin Fixes #1927 * Add a basic test for each of the three "cat" commands * Ensure that there are no errors when dcat or dcat1 are run
1 parent bb4c54f commit 00af2b5

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed
File renamed without changes.

examples/misc/test/bin_test.dart

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import 'dart:convert';
2+
import 'dart:io';
3+
4+
import 'package:test/test.dart';
5+
6+
import '../bin/cat_no_hash.dart' as cat_no_hash;
7+
8+
void main() {
9+
const pathToQuotes = 'test_data/quote.txt';
10+
11+
test('cat_no_hash', () {
12+
final quotes = File(pathToQuotes);
13+
expect(quotes.readAsStringSync(), contains('#'));
14+
15+
expect(
16+
() => cat_no_hash.main([quotes.path]),
17+
prints(
18+
isNot(contains('#')),
19+
));
20+
});
21+
22+
test('dcat', () async {
23+
final procResult = await Process.run(
24+
'dart', ['--enable-asserts', 'bin/dcat.dart', '-n', pathToQuotes]);
25+
expect(
26+
procResult.stdout,
27+
allOf(
28+
startsWith('1'), // Line number
29+
contains('Dr. Seuss'),
30+
endsWith('Nietzsche\n'),
31+
));
32+
});
33+
34+
test('dcat1', () async {
35+
const greeting = '¡Hola, Mundo!';
36+
final process =
37+
await Process.start('dart', ['--enable-asserts', 'bin/dcat1.dart']);
38+
process.stdin.writeln(greeting);
39+
final output = await process.stdout.transform(Utf8Decoder()).join('');
40+
final errors = await process.stderr.transform(Utf8Decoder()).join('');
41+
42+
expect(await process.exitCode, 0);
43+
expect(output, contains('You typed: $greeting'));
44+
expect(errors, isEmpty);
45+
});
46+
}

examples/misc/test_data/quote.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Be yourself. Everyone else is taken. -Oscar Wilde
2+
Don't cry because it's over, smile because it happened. -Dr. Seuss
3+
You only live once, but if you do it right, once is enough. -Mae West
4+
# This is a comment line.
5+
That which does not kill us makes us stronger. -Nietzsche

src/_tutorials/language/streams.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ It first converts the data from UTF8 and then runs it through
357357
a [LineSplitter.][LineSplitter]
358358
All lines are printed, except any that begin with a hashtag, `#`.
359359

360-
<?code-excerpt "misc/lib/tutorial/cat_no_hash.dart"?>
360+
<?code-excerpt "misc/bin/cat_no_hash.dart"?>
361361
{% prettify dart %}
362362
import 'dart:convert';
363363
import 'dart:io';

0 commit comments

Comments
 (0)