1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cli: fix failing test on macos/windows

This commit is contained in:
Delyan Angelov 2020-07-18 15:01:54 +03:00
parent e5a508c0d7
commit ca8344460a

View File

@ -51,13 +51,16 @@ fn test_if_command_has_default_version_subcommand_if_version_is_set() {
assert has_command(cmd, 'version') assert has_command(cmd, 'version')
} }
fn flag_should_be_set(cmd cli.Command) ? {
flag := cmd.flags.get_string('flag')?
assert flag == 'value'
}
fn test_if_flag_gets_set() { fn test_if_flag_gets_set() {
mut cmd := cli.Command{ mut cmd := cli.Command{
name: 'command' name: 'command'
execute: fn (cmd cli.Command) ? { execute: flag_should_be_set
flag := cmd.flags.get_string('flag')?
assert flag == 'value'
}
} }
cmd.add_flag(cli.Flag{ cmd.add_flag(cli.Flag{
flag: .string flag: .string
@ -69,10 +72,7 @@ fn test_if_flag_gets_set() {
fn test_if_flag_gets_set_with_abbrev() { fn test_if_flag_gets_set_with_abbrev() {
mut cmd := cli.Command{ mut cmd := cli.Command{
name: 'command' name: 'command'
execute: fn (cmd cli.Command) ? { execute: flag_should_be_set
flag := cmd.flags.get_string('flag')?
assert flag == 'value'
}
} }
cmd.add_flag(cli.Flag{ cmd.add_flag(cli.Flag{
flag: .string flag: .string
@ -83,14 +83,18 @@ fn test_if_flag_gets_set_with_abbrev() {
cmd.parse(['command', '--flag', 'value']) cmd.parse(['command', '--flag', 'value'])
} }
fn flag_should_have_value_of_42(cmd cli.Command) ? {
flag := cmd.flags.get_string('flag')?
assert flag == 'value'
value := cmd.flags.get_int('value')?
assert value == 42
}
fn test_if_multiple_flags_get_set() { fn test_if_multiple_flags_get_set() {
mut cmd := cli.Command{ mut cmd := cli.Command{
name: 'command' name: 'command'
execute: fn (cmd cli.Command) ? { execute: flag_should_have_value_of_42
flag := cmd.flags.get_string('flag')?
value := cmd.flags.get_int('value')?
assert flag == 'value' && value == 42
}
} }
cmd.add_flag(cli.Flag{ cmd.add_flag(cli.Flag{
flag: .string flag: .string
@ -103,6 +107,14 @@ fn test_if_multiple_flags_get_set() {
cmd.parse(['command', '-flag', 'value', '-value', '42']) cmd.parse(['command', '-flag', 'value', '-value', '42'])
} }
fn flag_is_set_in_subcommand(cmd cli.Command) ? {
flag := cmd.flags.get_string('flag') or {
panic(err)
}
assert flag == 'value'
}
fn test_if_flag_gets_set_in_subcommand() { fn test_if_flag_gets_set_in_subcommand() {
mut cmd := cli.Command{ mut cmd := cli.Command{
name: 'command' name: 'command'
@ -110,12 +122,7 @@ fn test_if_flag_gets_set_in_subcommand() {
} }
mut subcmd := cli.Command{ mut subcmd := cli.Command{
name: 'subcommand' name: 'subcommand'
execute: fn (cmd cli.Command) ? { execute: flag_is_set_in_subcommand
flag := cmd.flags.get_string('flag') or {
panic(err)
}
assert flag == 'value'
}
} }
subcmd.add_flag(cli.Flag{ subcmd.add_flag(cli.Flag{
flag: .string flag: .string
@ -137,12 +144,7 @@ fn test_if_global_flag_gets_set_in_subcommand() {
}) })
subcmd := cli.Command{ subcmd := cli.Command{
name: 'subcommand' name: 'subcommand'
execute: fn (cmd cli.Command) { execute: flag_is_set_in_subcommand
flag := cmd.flags.get_string('flag') or {
panic(err)
}
assert flag == 'value'
}
} }
cmd.add_command(subcmd) cmd.add_command(subcmd)
cmd.parse(['command', '-flag', 'value', 'subcommand']) cmd.parse(['command', '-flag', 'value', 'subcommand'])