-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhandle_completion_command_test.dart
More file actions
111 lines (93 loc) · 2.86 KB
/
handle_completion_command_test.dart
File metadata and controls
111 lines (93 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import 'package:args/command_runner.dart';
import 'package:cli_completion/cli_completion.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
class MockLogger extends Mock implements Logger {}
class _TestCompletionCommandRunner extends CompletionCommandRunner<int> {
_TestCompletionCommandRunner() : super('test', 'Test command runner') {
final subCommand = _TestCommand(
name: 'subcommand',
description: 'level 1',
);
addCommand(subCommand);
final subSubCommand = _TestCommand(
name: 'subsubcommand2',
description: 'level 2',
);
subCommand.addSubcommand(subSubCommand);
}
@override
String get executableName => 'test_cli';
@override
// Override acceptable for test files
// ignore: overridden_fields
final Logger completionLogger = MockLogger();
}
class _TestCommand extends Command<int> {
_TestCommand({
required this.name,
required this.description,
});
@override
final String description;
@override
final String name;
}
void main() {
group('HandleCompletionRequestCommand', () {
late _TestCompletionCommandRunner commandRunner;
setUp(() {
commandRunner = _TestCompletionCommandRunner();
});
test('can be instantiated', () {
expect(HandleCompletionRequestCommand<int>(), isNotNull);
});
test('is hidden', () {
expect(HandleCompletionRequestCommand<int>().hidden, isTrue);
});
test('description', () {
expect(
HandleCompletionRequestCommand<int>().description,
'Handles shell completion (should never be called manually)',
);
});
group('run', () {
test('should display completion', () async {
final output = StringBuffer();
when(() {
commandRunner.completionLogger.info(any());
}).thenAnswer((invocation) {
output.writeln(invocation.positionalArguments.first);
});
const line = 'test_cli ';
commandRunner.environmentOverride = {
'SHELL': '/foo/bar/zsh',
'COMP_LINE': line,
'COMP_POINT': '${line.length}',
'COMP_CWORD': '2',
};
await commandRunner.run(['completion']);
expect(output.toString(), '''
subcommand:level 1
--help:Print this usage information.
''');
});
test('should suppress error messages', () async {
final output = StringBuffer();
when(() {
commandRunner.completionLogger.info(any());
}).thenThrow(Exception('oh no'));
const line = 'test_cli ';
commandRunner.environmentOverride = {
'SHELL': '/foo/bar/zsh',
'COMP_LINE': line,
'COMP_POINT': '${line.length}',
'COMP_CWORD': '2',
};
await commandRunner.run(['completion']);
expect(output.toString(), '');
});
});
});
}