/test/lib/cli/test_cli_07.e
Specman e | 82 lines | 72 code | 9 blank | 1 comment | 1 complexity | 52a906ce950cb1519737a728af879a31 MD5 | raw file
1class TEST_CLI_07 2 3insert 4 ARGUMENTS 5 EIFFELTEST_TOOLS 6 COMMAND_LINE_ARGUMENT_CUSTOM_FACTORY[AUX_CLI_07_CUSTOM_OPTION] 7 8create {} 9 make 10 11feature {} 12 make 13 local 14 custom_option: COMMAND_LINE_TYPED_ARGUMENT[TRAVERSABLE[AUX_CLI_07_CUSTOM_OPTION]] 15 do 16 custom_option := option_customs("c", "custom", "custom", "The custom option", agent validate(?), agent decode(?)) 17 create args.make(custom_option and no_parameters) 18 19 -- check the custom option building 20 setup 21 command_arguments.add_last("-c") 22 command_arguments.add_last("foo") 23 assert(args.parse_command_line) 24 assert(custom_option.item.count = 1) 25 assert(custom_option.item.first.items.count = 1) 26 assert(custom_option.item.first.items.fast_reference_at("foo".intern) = Void) 27 setup 28 command_arguments.add_last("-c") 29 command_arguments.add_last("foo = ") 30 assert(args.parse_command_line) 31 assert(custom_option.item.count = 1) 32 assert(custom_option.item.first.items.count = 1) 33 assert(custom_option.item.first.items.fast_reference_at("foo".intern).is_empty) 34 setup 35 command_arguments.add_last("-cc") 36 command_arguments.add_last("foo=something") 37 command_arguments.add_last("bar=anything") 38 assert(args.parse_command_line) 39 assert(custom_option.item.count = 2) 40 assert(custom_option.item.first.items.count = 1) 41 assert(custom_option.item.first.items.fast_reference_at("foo".intern).is_equal("something")) 42 assert(custom_option.item.last.items.count = 1) 43 assert(custom_option.item.last.items.fast_reference_at("bar".intern).is_equal("anything")) 44 setup 45 command_arguments.add_last("-c") 46 command_arguments.add_last("foo=something") 47 command_arguments.add_last("-c") 48 command_arguments.add_last("bar=anything") 49 assert(args.parse_command_line) 50 assert(custom_option.item.count = 2) 51 assert(custom_option.item.first.items.count = 1) 52 assert(custom_option.item.first.items.fast_reference_at("foo".intern).is_equal("something")) 53 assert(custom_option.item.last.items.count = 1) 54 assert(custom_option.item.last.items.fast_reference_at("bar".intern).is_equal("anything")) 55 setup 56 command_arguments.add_last("-c") 57 command_arguments.add_last("foo = something else; bar = anything else ") 58 assert(args.parse_command_line) 59 assert(custom_option.item.count = 1) 60 assert(custom_option.item.first.items.count = 2) 61 assert(custom_option.item.first.items.fast_reference_at("foo".intern).is_equal("something else")) 62 assert(custom_option.item.first.items.fast_reference_at("bar".intern).is_equal("anything else")) 63 end 64 65 setup 66 do 67 command_arguments.make(1) 68 end 69 70 args: COMMAND_LINE_ARGUMENTS 71 72 validate (arg: STRING): BOOLEAN 73 do 74 Result := not arg.is_empty 75 end 76 77 decode (arg: STRING): AUX_CLI_07_CUSTOM_OPTION 78 do 79 create Result.make(arg) 80 end 81 82end