@@ -72,6 +72,36 @@ void main() {
72
72
expect (command.stringArgDeprecated ('key' ), 'value' );
73
73
expect (() => command.stringArgDeprecated ('empty' ), throwsA (const TypeMatcher <ArgumentError >()));
74
74
});
75
+
76
+ testUsingContext ('List<String> safe argResults' , () async {
77
+ final DummyFlutterCommand command = DummyFlutterCommand (
78
+ commandFunction: () async {
79
+ return const FlutterCommandResult (ExitStatus .success);
80
+ }
81
+ );
82
+ final FlutterCommandRunner runner = FlutterCommandRunner (verboseHelp: true );
83
+ command.argParser.addMultiOption (
84
+ 'key' ,
85
+ allowed: < String > ['a' , 'b' , 'c' ],
86
+ );
87
+ // argResults will be null at this point, if attempt to read them is made,
88
+ // exception `Null check operator used on a null value` would be thrown.
89
+ expect (() => command.stringsArg ('key' ), throwsA (const TypeMatcher <TypeError >()));
90
+
91
+ runner.addCommand (command);
92
+ await runner.run (< String > ['dummy' , '--key' , 'a' ]);
93
+
94
+ // throws error when trying to parse non-existent key.
95
+ expect (() => command.stringsArg ('empty' ),throwsA (const TypeMatcher <ArgumentError >()));
96
+
97
+ expect (command.stringsArg ('key' ), < String > ['a' ]);
98
+
99
+ await runner.run (< String > ['dummy' , '--key' , 'a' , '--key' , 'b' ]);
100
+ expect (command.stringsArg ('key' ), < String > ['a' , 'b' ]);
101
+
102
+ await runner.run (< String > ['dummy' ]);
103
+ expect (command.stringsArg ('key' ), < String > []);
104
+ });
75
105
}
76
106
77
107
void verifyCommandRunner (CommandRunner <Object > runner) {
0 commit comments