PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/test/lib/cli/test_cli_02.e

http://github.com/tybor/Liberty
Specman e | 167 lines | 151 code | 11 blank | 5 comment | 0 complexity | 2b434a681b5cb92fe239deee22890c13 MD5 | raw file
  1class TEST_CLI_02
  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      do
 17         foo_option := option_string("f", "foo", "foo", "The foo string")
 18         bar_option := option_integer("b", "bar", "bar", "The bar integer")
 19         create args.make(foo_option and bar_option)
 20
 21         -- an empty command line is valid
 22         setup
 23         assert(args.parse_command_line)
 24
 25         -- a foo option takes a string
 26         setup
 27         command_arguments.add_last("--foo")
 28         assert(not args.parse_command_line)
 29         setup
 30         command_arguments.add_last("--foo")
 31         command_arguments.add_last("the foo option")
 32         assert(args.parse_command_line)
 33         assert(foo_option.item.is_equal("the foo option"))
 34         setup
 35         command_arguments.add_last("--foo=the foo option")
 36         assert(args.parse_command_line)
 37         assert(foo_option.item.is_equal("the foo option"))
 38         setup
 39         command_arguments.add_last("-f")
 40         assert(not args.parse_command_line)
 41         setup
 42         command_arguments.add_last("-f")
 43         command_arguments.add_last("the foo option")
 44         assert(args.parse_command_line)
 45         assert(foo_option.item.is_equal("the foo option"))
 46
 47         -- a bar option takes an integer
 48         setup
 49         command_arguments.add_last("--bar")
 50         assert(not args.parse_command_line)
 51         setup
 52         command_arguments.add_last("--bar")
 53         command_arguments.add_last("the foo option")
 54         assert(not args.parse_command_line)
 55         setup
 56         command_arguments.add_last("--bar")
 57         command_arguments.add_last("42")
 58         assert(args.parse_command_line)
 59         assert(bar_option.item = 42)
 60         setup
 61         command_arguments.add_last("--bar=42")
 62         assert(args.parse_command_line)
 63         assert(bar_option.item = 42)
 64         setup
 65         command_arguments.add_last("-b")
 66         assert(not args.parse_command_line)
 67         setup
 68         command_arguments.add_last("-b")
 69         command_arguments.add_last("the foo option")
 70         assert(not args.parse_command_line)
 71         setup
 72         command_arguments.add_last("-b")
 73         command_arguments.add_last("42")
 74         assert(args.parse_command_line)
 75         assert(bar_option.item = 42)
 76
 77         -- can have both foo and bar...
 78         setup
 79         command_arguments.add_last("--foo")
 80         command_arguments.add_last("the foo z'option")
 81         command_arguments.add_last("--bar")
 82         command_arguments.add_last("42")
 83         assert(args.parse_command_line)
 84         assert(foo_option.item.is_equal("the foo z'option"))
 85         assert(bar_option.item = 42)
 86         setup
 87         command_arguments.add_last("-f")
 88         command_arguments.add_last("the foo z'option")
 89         command_arguments.add_last("-b")
 90         command_arguments.add_last("42")
 91         assert(args.parse_command_line)
 92         assert(foo_option.item.is_equal("the foo z'option"))
 93         assert(bar_option.item = 42)
 94         setup
 95         command_arguments.add_last("-f")
 96         command_arguments.add_last("the foo z'option")
 97         command_arguments.add_last("--bar")
 98         command_arguments.add_last("42")
 99         assert(args.parse_command_line)
100         assert(foo_option.item.is_equal("the foo z'option"))
101         assert(bar_option.item = 42)
102         setup
103         command_arguments.add_last("--foo")
104         command_arguments.add_last("the foo z'option")
105         command_arguments.add_last("-b")
106         command_arguments.add_last("42")
107         assert(args.parse_command_line)
108         assert(foo_option.item.is_equal("the foo z'option"))
109         assert(bar_option.item = 42)
110         setup
111         command_arguments.add_last("-fb")
112         command_arguments.add_last("the foo z'option")
113         command_arguments.add_last("42")
114         assert(args.parse_command_line)
115         assert(foo_option.item.is_equal("the foo z'option"))
116         assert(bar_option.item = 42)
117
118         -- ... in any order
119         setup
120         command_arguments.add_last("--bar")
121         command_arguments.add_last("42")
122         command_arguments.add_last("--foo")
123         command_arguments.add_last("the foo z'option")
124         assert(args.parse_command_line)
125         assert(foo_option.item.is_equal("the foo z'option"))
126         assert(bar_option.item = 42)
127         setup
128         command_arguments.add_last("-b")
129         command_arguments.add_last("42")
130         command_arguments.add_last("-f")
131         command_arguments.add_last("the foo z'option")
132         assert(args.parse_command_line)
133         assert(foo_option.item.is_equal("the foo z'option"))
134         assert(bar_option.item = 42)
135         setup
136         command_arguments.add_last("--bar")
137         command_arguments.add_last("42")
138         command_arguments.add_last("-f")
139         command_arguments.add_last("the foo z'option")
140         assert(args.parse_command_line)
141         assert(foo_option.item.is_equal("the foo z'option"))
142         assert(bar_option.item = 42)
143         setup
144         command_arguments.add_last("-b")
145         command_arguments.add_last("42")
146         command_arguments.add_last("--foo")
147         command_arguments.add_last("the foo z'option")
148         assert(args.parse_command_line)
149         assert(foo_option.item.is_equal("the foo z'option"))
150         assert(bar_option.item = 42)
151         setup
152         command_arguments.add_last("-bf")
153         command_arguments.add_last("42")
154         command_arguments.add_last("the foo z'option")
155         assert(args.parse_command_line)
156         assert(foo_option.item.is_equal("the foo z'option"))
157         assert(bar_option.item = 42)
158      end
159
160   setup
161      do
162         command_arguments.make(1)
163      end
164
165   args: COMMAND_LINE_ARGUMENTS
166
167end