PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/test/lib/cli/test_cli_05.e

http://github.com/tybor/Liberty
Specman e | 90 lines | 74 code | 11 blank | 5 comment | 0 complexity | 8f57391881386edf1600720466d8171a MD5 | raw file
 1class TEST_CLI_05
 2
 3insert
 4   ARGUMENTS
 5   EIFFELTEST_TOOLS
 6   COMMAND_LINE_ARGUMENT_FACTORY
 7
 8create {}
 9   make
10
11feature {}
12   make
13      local
14         foo_option: COMMAND_LINE_TYPED_ARGUMENT[FIXED_STRING]
15         bar_option: COMMAND_LINE_TYPED_ARGUMENT[INTEGER]
16         arg1: COMMAND_LINE_TYPED_ARGUMENT[FIXED_STRING]
17         arg2: COMMAND_LINE_TYPED_ARGUMENT[FIXED_STRING]
18      do
19         foo_option := option_string("f", "foo", "foo", "The foo string")
20         bar_option := option_integer("b", "bar", "bar", "The bar integer")
21         arg1 := positional_string("arg1", "The first positional parameter")
22         arg2 := positional_string("arg2", "The second positional parameter")
23         create args.make(foo_option and bar_option and arg1 and arg2)
24
25         -- positional arguments are mandatory
26         assert(arg1.is_mandatory)
27         assert(arg2.is_mandatory)
28
29         -- an empty command line is not valid
30         setup
31         assert(not args.parse_command_line)
32
33         -- an option alone is not valid
34         setup
35         command_arguments.add_last("--bar=42")
36         assert(not args.parse_command_line)
37
38         -- must have at least both positional arguments
39         setup
40         command_arguments.add_last("first arg")
41         command_arguments.add_last("second arg")
42         assert(args.parse_command_line)
43         assert(arg1.item.is_equal("first arg"))
44         assert(arg2.item.is_equal("second arg"))
45
46         -- options may be freely intermixed
47         setup
48         command_arguments.add_last("first arg")
49         command_arguments.add_last("-bf")
50         command_arguments.add_last("42")
51         command_arguments.add_last("the foo z'option")
52         command_arguments.add_last("second arg")
53         assert(args.parse_command_line)
54         assert(arg1.item.is_equal("first arg"))
55         assert(arg2.item.is_equal("second arg"))
56         assert(foo_option.item.is_equal("the foo z'option"))
57         assert(bar_option.item = 42)
58         setup
59         command_arguments.add_last("--foo")
60         command_arguments.add_last("the foo z'option")
61         command_arguments.add_last("first arg")
62         command_arguments.add_last("second arg")
63         command_arguments.add_last("-b")
64         command_arguments.add_last("42")
65         assert(args.parse_command_line)
66         assert(arg1.item.is_equal("first arg"))
67         assert(arg2.item.is_equal("second arg"))
68         assert(foo_option.item.is_equal("the foo z'option"))
69         assert(bar_option.item = 42)
70         setup
71         command_arguments.add_last("--foo")
72         command_arguments.add_last("the foo z'option")
73         command_arguments.add_last("--bar=42")
74         command_arguments.add_last("first arg")
75         command_arguments.add_last("second arg")
76         assert(args.parse_command_line)
77         assert(arg1.item.is_equal("first arg"))
78         assert(arg2.item.is_equal("second arg"))
79         assert(foo_option.item.is_equal("the foo z'option"))
80         assert(bar_option.item = 42)
81      end
82
83   setup
84      do
85         command_arguments.make(1)
86      end
87
88   args: COMMAND_LINE_ARGUMENTS
89
90end