Skip to content

Commit 1506538

Browse files
authored
test: command test with test_process (#339)
1 parent 2728211 commit 1506538

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

codecov.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ coverage:
2121
paths: null
2222

2323
ignore:
24-
- "example/"
24+
- "examples/**/*"
2525
- "**/*.g.dart"
2626
- "**/*.gen.dart"

packages/command/bin/flutter_gen_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void main(List<String> args) {
4040
}
4141
} on FormatException catch (e) {
4242
stderr.writeAll(
43-
<String>[e.message, 'usage: flutter_gen [options...] ', ''], '\n');
43+
<String>[e.message, 'usage: flutter_gen [options...]', ''], '\n');
4444
return;
4545
}
4646

packages/command/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ dependencies:
1818
args: '>=2.0.0 <3.0.0'
1919

2020
dev_dependencies:
21+
test: '>=1.16.0 <2.0.0'
22+
test_process: '>=2.0.0 <3.0.0'
2123
flutter_lints: '>=2.0.1 <3.0.0'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import 'package:flutter_gen_core/utils/version.dart';
2+
import 'package:test/test.dart';
3+
import 'package:test_process/test_process.dart';
4+
5+
void main() {
6+
test('Execute fluttergen', () async {
7+
final process =
8+
await TestProcess.start('dart', ['bin/flutter_gen_command.dart']);
9+
expect(await process.stdout.next,
10+
equals('$flutterGenVersion Loading ... command/pubspec.yaml'));
11+
await process.shouldExit(0);
12+
});
13+
14+
test('Execute fluttergen --config pubspec.yaml', () async {
15+
var process = await TestProcess.start(
16+
'dart', ['bin/flutter_gen_command.dart', '--config', 'pubspec.yaml']);
17+
expect(await process.stdout.next,
18+
equals('$flutterGenVersion Loading ... command/pubspec.yaml'));
19+
await process.shouldExit(0);
20+
});
21+
22+
test('Execute fluttergen --help', () async {
23+
var process = await TestProcess.start(
24+
'dart', ['bin/flutter_gen_command.dart', '--help']);
25+
expect(await process.stdout.next,
26+
equals('-c, --config Set the path of pubspec.yaml.'));
27+
final line = await process.stdout.next;
28+
expect(line.trim(), equals('(defaults to "pubspec.yaml")'));
29+
await process.shouldExit(0);
30+
});
31+
32+
test('Execute fluttergen --version', () async {
33+
var process = await TestProcess.start(
34+
'dart', ['bin/flutter_gen_command.dart', '--version']);
35+
expect(await process.stdout.next, equals(flutterGenVersion));
36+
await process.shouldExit(0);
37+
});
38+
39+
test('Execute wrong argments with fluttergen --wrong', () async {
40+
var process = await TestProcess.start(
41+
'dart', ['bin/flutter_gen_command.dart', '--wrong']);
42+
expect(await process.stderr.next,
43+
equals('Could not find an option named "wrong".'));
44+
expect(
45+
await process.stderr.next, equals('usage: flutter_gen [options...]'));
46+
await process.shouldExit(0);
47+
});
48+
}

0 commit comments

Comments
 (0)