PageRenderTime 31ms CodeModel.GetById 16ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/test/lib/cli/test_cli_08.e

http://github.com/tybor/Liberty
Specman e | 330 lines | 311 code | 11 blank | 8 comment | 0 complexity | acd6729a12802eab06414b88f3343736 MD5 | raw file
  1class TEST_CLI_08
  2--
  3-- Same as TEST_CLI_02 with the special "remaining_parameters" to parse
  4--
  5
  6insert
  7   ARGUMENTS
  8   EIFFELTEST_TOOLS
  9   COMMAND_LINE_ARGUMENT_FACTORY
 10
 11create {}
 12   make
 13
 14feature {}
 15   make
 16      local
 17         foo_option: COMMAND_LINE_TYPED_ARGUMENT[FIXED_STRING]
 18         bar_option: COMMAND_LINE_TYPED_ARGUMENT[INTEGER]
 19      do
 20         foo_option := option_string("f", "foo", "foo", "The foo string")
 21         bar_option := option_integer("b", "bar", "bar", "The bar integer")
 22         create args.make(foo_option and bar_option and remaining_parameters)
 23
 24         -- an empty command line is valid
 25         setup
 26         command_arguments.add_last(once "--")
 27         command_arguments.add_last(once "--foo=ignored")
 28         command_arguments.add_last(once "--bar")
 29         command_arguments.add_last(once "oh well")
 30         assert(args.parse_command_line)
 31         assert(remaining_parameters.item.count = 3)
 32         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
 33         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
 34         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
 35
 36         -- a foo option takes a string
 37         setup
 38         command_arguments.add_last("--foo")
 39         command_arguments.add_last(once "--")
 40         command_arguments.add_last(once "--foo=ignored")
 41         command_arguments.add_last(once "--bar")
 42         command_arguments.add_last(once "oh well")
 43         assert(not args.parse_command_line)
 44         setup
 45         command_arguments.add_last("--foo")
 46         command_arguments.add_last("the foo option")
 47         command_arguments.add_last(once "--")
 48         command_arguments.add_last(once "--foo=ignored")
 49         command_arguments.add_last(once "--bar")
 50         command_arguments.add_last(once "oh well")
 51         assert(args.parse_command_line)
 52         assert(foo_option.item.is_equal("the foo option"))
 53         assert(remaining_parameters.item.count = 3)
 54         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
 55         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
 56         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
 57         setup
 58         command_arguments.add_last("--foo=the foo option")
 59         command_arguments.add_last(once "--")
 60         command_arguments.add_last(once "--foo=ignored")
 61         command_arguments.add_last(once "--bar")
 62         command_arguments.add_last(once "oh well")
 63         assert(args.parse_command_line)
 64         assert(foo_option.item.is_equal("the foo option"))
 65         assert(remaining_parameters.item.count = 3)
 66         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
 67         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
 68         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
 69         setup
 70         command_arguments.add_last("-f")
 71         command_arguments.add_last(once "--")
 72         command_arguments.add_last(once "--foo=ignored")
 73         command_arguments.add_last(once "--bar")
 74         command_arguments.add_last(once "oh well")
 75         assert(not args.parse_command_line)
 76         setup
 77         command_arguments.add_last("-f")
 78         command_arguments.add_last("the foo option")
 79         command_arguments.add_last(once "--")
 80         command_arguments.add_last(once "--foo=ignored")
 81         command_arguments.add_last(once "--bar")
 82         command_arguments.add_last(once "oh well")
 83         assert(args.parse_command_line)
 84         assert(foo_option.item.is_equal("the foo option"))
 85         assert(remaining_parameters.item.count = 3)
 86         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
 87         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
 88         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
 89
 90         -- a bar option takes an integer
 91         setup
 92         command_arguments.add_last("--bar")
 93         command_arguments.add_last(once "--")
 94         command_arguments.add_last(once "--foo=ignored")
 95         command_arguments.add_last(once "--bar")
 96         command_arguments.add_last(once "oh well")
 97         assert(not args.parse_command_line)
 98         setup
 99         command_arguments.add_last("--bar")
100         command_arguments.add_last("the foo option")
101         command_arguments.add_last(once "--")
102         command_arguments.add_last(once "--foo=ignored")
103         command_arguments.add_last(once "--bar")
104         command_arguments.add_last(once "oh well")
105         assert(not args.parse_command_line)
106         setup
107         command_arguments.add_last("--bar")
108         command_arguments.add_last("42")
109         command_arguments.add_last(once "--")
110         command_arguments.add_last(once "--foo=ignored")
111         command_arguments.add_last(once "--bar")
112         command_arguments.add_last(once "oh well")
113         assert(args.parse_command_line)
114         assert(bar_option.item = 42)
115         assert(remaining_parameters.item.count = 3)
116         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
117         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
118         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
119         setup
120         command_arguments.add_last("--bar=42")
121         command_arguments.add_last(once "--")
122         command_arguments.add_last(once "--foo=ignored")
123         command_arguments.add_last(once "--bar")
124         command_arguments.add_last(once "oh well")
125         assert(args.parse_command_line)
126         assert(bar_option.item = 42)
127         assert(remaining_parameters.item.count = 3)
128         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
129         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
130         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
131         setup
132         command_arguments.add_last("-b")
133         command_arguments.add_last(once "--")
134         command_arguments.add_last(once "--foo=ignored")
135         command_arguments.add_last(once "--bar")
136         command_arguments.add_last(once "oh well")
137         assert(not args.parse_command_line)
138         setup
139         command_arguments.add_last("-b")
140         command_arguments.add_last("the foo option")
141         command_arguments.add_last(once "--")
142         command_arguments.add_last(once "--foo=ignored")
143         command_arguments.add_last(once "--bar")
144         command_arguments.add_last(once "oh well")
145         assert(not args.parse_command_line)
146         setup
147         command_arguments.add_last("-b")
148         command_arguments.add_last("42")
149         command_arguments.add_last(once "--")
150         command_arguments.add_last(once "--foo=ignored")
151         command_arguments.add_last(once "--bar")
152         command_arguments.add_last(once "oh well")
153         assert(args.parse_command_line)
154         assert(bar_option.item = 42)
155         assert(remaining_parameters.item.count = 3)
156         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
157         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
158         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
159
160         -- can have both foo and bar...
161         setup
162         command_arguments.add_last("--foo")
163         command_arguments.add_last("the foo z'option")
164         command_arguments.add_last("--bar")
165         command_arguments.add_last("42")
166         command_arguments.add_last(once "--")
167         command_arguments.add_last(once "--foo=ignored")
168         command_arguments.add_last(once "--bar")
169         command_arguments.add_last(once "oh well")
170         assert(args.parse_command_line)
171         assert(foo_option.item.is_equal("the foo z'option"))
172         assert(bar_option.item = 42)
173         assert(remaining_parameters.item.count = 3)
174         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
175         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
176         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
177         setup
178         command_arguments.add_last("-f")
179         command_arguments.add_last("the foo z'option")
180         command_arguments.add_last("-b")
181         command_arguments.add_last("42")
182         command_arguments.add_last(once "--")
183         command_arguments.add_last(once "--foo=ignored")
184         command_arguments.add_last(once "--bar")
185         command_arguments.add_last(once "oh well")
186         assert(args.parse_command_line)
187         assert(foo_option.item.is_equal("the foo z'option"))
188         assert(bar_option.item = 42)
189         assert(remaining_parameters.item.count = 3)
190         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
191         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
192         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
193         setup
194         command_arguments.add_last("-f")
195         command_arguments.add_last("the foo z'option")
196         command_arguments.add_last("--bar")
197         command_arguments.add_last("42")
198         command_arguments.add_last(once "--")
199         command_arguments.add_last(once "--foo=ignored")
200         command_arguments.add_last(once "--bar")
201         command_arguments.add_last(once "oh well")
202         assert(args.parse_command_line)
203         assert(foo_option.item.is_equal("the foo z'option"))
204         assert(bar_option.item = 42)
205         assert(remaining_parameters.item.count = 3)
206         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
207         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
208         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
209         setup
210         command_arguments.add_last("--foo")
211         command_arguments.add_last("the foo z'option")
212         command_arguments.add_last("-b")
213         command_arguments.add_last("42")
214         command_arguments.add_last(once "--")
215         command_arguments.add_last(once "--foo=ignored")
216         command_arguments.add_last(once "--bar")
217         command_arguments.add_last(once "oh well")
218         assert(args.parse_command_line)
219         assert(foo_option.item.is_equal("the foo z'option"))
220         assert(bar_option.item = 42)
221         assert(remaining_parameters.item.count = 3)
222         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
223         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
224         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
225         setup
226         command_arguments.add_last("-fb")
227         command_arguments.add_last("the foo z'option")
228         command_arguments.add_last("42")
229         command_arguments.add_last(once "--")
230         command_arguments.add_last(once "--foo=ignored")
231         command_arguments.add_last(once "--bar")
232         command_arguments.add_last(once "oh well")
233         assert(args.parse_command_line)
234         assert(foo_option.item.is_equal("the foo z'option"))
235         assert(bar_option.item = 42)
236         assert(remaining_parameters.item.count = 3)
237         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
238         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
239         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
240
241         -- ... in any order
242         setup
243         command_arguments.add_last("--bar")
244         command_arguments.add_last("42")
245         command_arguments.add_last("--foo")
246         command_arguments.add_last("the foo z'option")
247         command_arguments.add_last(once "--")
248         command_arguments.add_last(once "--foo=ignored")
249         command_arguments.add_last(once "--bar")
250         command_arguments.add_last(once "oh well")
251         assert(args.parse_command_line)
252         assert(foo_option.item.is_equal("the foo z'option"))
253         assert(bar_option.item = 42)
254         assert(remaining_parameters.item.count = 3)
255         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
256         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
257         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
258         setup
259         command_arguments.add_last("-b")
260         command_arguments.add_last("42")
261         command_arguments.add_last("-f")
262         command_arguments.add_last("the foo z'option")
263         command_arguments.add_last(once "--")
264         command_arguments.add_last(once "--foo=ignored")
265         command_arguments.add_last(once "--bar")
266         command_arguments.add_last(once "oh well")
267         assert(args.parse_command_line)
268         assert(foo_option.item.is_equal("the foo z'option"))
269         assert(bar_option.item = 42)
270         assert(remaining_parameters.item.count = 3)
271         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
272         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
273         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
274         setup
275         command_arguments.add_last("--bar")
276         command_arguments.add_last("42")
277         command_arguments.add_last("-f")
278         command_arguments.add_last("the foo z'option")
279         command_arguments.add_last(once "--")
280         command_arguments.add_last(once "--foo=ignored")
281         command_arguments.add_last(once "--bar")
282         command_arguments.add_last(once "oh well")
283         assert(args.parse_command_line)
284         assert(foo_option.item.is_equal("the foo z'option"))
285         assert(bar_option.item = 42)
286         assert(remaining_parameters.item.count = 3)
287         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
288         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
289         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
290         setup
291         command_arguments.add_last("-b")
292         command_arguments.add_last("42")
293         command_arguments.add_last("--foo")
294         command_arguments.add_last("the foo z'option")
295         command_arguments.add_last(once "--")
296         command_arguments.add_last(once "--foo=ignored")
297         command_arguments.add_last(once "--bar")
298         command_arguments.add_last(once "oh well")
299         assert(args.parse_command_line)
300         assert(foo_option.item.is_equal("the foo z'option"))
301         assert(bar_option.item = 42)
302         assert(remaining_parameters.item.count = 3)
303         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
304         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
305         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
306         setup
307         command_arguments.add_last("-bf")
308         command_arguments.add_last("42")
309         command_arguments.add_last("the foo z'option")
310         command_arguments.add_last(once "--")
311         command_arguments.add_last(once "--foo=ignored")
312         command_arguments.add_last(once "--bar")
313         command_arguments.add_last(once "oh well")
314         assert(args.parse_command_line)
315         assert(foo_option.item.is_equal("the foo z'option"))
316         assert(bar_option.item = 42)
317         assert(remaining_parameters.item.count = 3)
318         assert(remaining_parameters.item.item(0).is_equal(once "--foo=ignored"))
319         assert(remaining_parameters.item.item(1).is_equal(once "--bar"))
320         assert(remaining_parameters.item.item(2).is_equal(once "oh well"))
321      end
322
323   setup
324      do
325         command_arguments.make(1)
326      end
327
328   args: COMMAND_LINE_ARGUMENTS
329
330end