Skip to content

Commit

Permalink
Use declare -p to list test arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
UrsaDK committed Dec 16, 2024
1 parent 3f298f2 commit 9b94aad
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 56 deletions.
16 changes: 8 additions & 8 deletions test/bats/github_13.bats
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ export GETOPTS_LONG_TEST_BIN='getopts_long-no_shortspec'
compare '-t -- -v user_val' \
'--toggle -- --variable=user_val' \
'/^\$@: /d'
expect "${bash_getopts[6]}" == '$@: -v user_val'
expect "${getopts_long[6]}" == '$@: --variable=user_val'
expect "${bash_getopts[6]}" == '$@: ([0]="-v" [1]="user_val")'
expect "${getopts_long[6]}" == '$@: ([0]="--variable=user_val")'
}
@test "${FEATURE}: terminator followed by long variable, verbose" {
compare '-t -- -v user_val' \
'--toggle -- --variable=user_val' \
'/^\$@: /d'
expect "${bash_getopts[6]}" == '$@: -v user_val'
expect "${getopts_long[6]}" == '$@: --variable=user_val'
expect "${bash_getopts[6]}" == '$@: ([0]="-v" [1]="user_val")'
expect "${getopts_long[6]}" == '$@: ([0]="--variable=user_val")'
}

@test "${FEATURE}: long variable followed by terminator, silent" {
Expand All @@ -78,15 +78,15 @@ export GETOPTS_LONG_TEST_BIN='getopts_long-no_shortspec'
'/^(OPTIND|\$@): /d'
expect "${bash_getopts[5]}" == 'OPTIND: 4'
expect "${getopts_long[5]}" == 'OPTIND: 3'
expect "${bash_getopts[6]}" == '$@: -t'
expect "${getopts_long[6]}" == '$@: --toggle'
expect "${bash_getopts[6]}" == '$@: ([0]="-t")'
expect "${getopts_long[6]}" == '$@: ([0]="--toggle")'
}
@test "${FEATURE}: long variable followed by terminator, verbose" {
compare '-v user_val -- -t' \
'--variable=user_val -- --toggle' \
'/^(OPTIND|\$@): /d'
expect "${bash_getopts[5]}" == 'OPTIND: 4'
expect "${getopts_long[5]}" == 'OPTIND: 3'
expect "${bash_getopts[6]}" == '$@: -t'
expect "${getopts_long[6]}" == '$@: --toggle'
expect "${bash_getopts[6]}" == '$@: ([0]="-t")'
expect "${getopts_long[6]}" == '$@: ([0]="--toggle")'
}
16 changes: 8 additions & 8 deletions test/bats/invalid_arguments.bats
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ load ../test_helper
@test "${FEATURE}: short option, terminator, extra arguments, silent" {
compare '-i -- user_arg' \
'-i -- user_arg'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}
@test "${FEATURE}: short option, terminator, extra arguments, verbose" {
compare '-i -- user_arg' \
'-i -- user_arg' \
's/getopts_long-verbose/getopts-verbose/g'
expect "${getopts_long[7]}" == '$@: user_arg'
expect "${getopts_long[7]}" == '$@: ([0]="user_arg")'
}

@test "${FEATURE}: long option, terminator, extra arguments, silent" {
Expand All @@ -70,38 +70,38 @@ load ../test_helper
'/^INVALID OPTION -- /d'
expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG="i"'
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="invalid"'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}
@test "${FEATURE}: long option, terminator, extra arguments, verbose" {
compare '-i -- user_arg' \
'--invalid -- user_arg' \
's/getopts_long-verbose: (.*) invalid$/getopts-verbose: \1 i/g'
expect "${getopts_long[7]}" == '$@: user_arg'
expect "${getopts_long[7]}" == '$@: ([0]="user_arg")'
}

# terminator followed by options

@test "${FEATURE}: terminator, short option, extra arguments, silent" {
compare '-- -i user_arg' \
'-- -i user_arg'
expect "${getopts_long[5]}" == '$@: -i user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="-i" [1]="user_arg")'
}
@test "${FEATURE}: terminator, short option, extra arguments, verbose" {
compare '-- -i user_arg' \
'-- -i user_arg' \
's/getopts_long-verbose/getopts-verbose/g'
expect "${getopts_long[5]}" == '$@: -i user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="-i" [1]="user_arg")'
}

@test "${FEATURE}: terminator, long option, extra arguments, silent" {
compare '-- -i user_arg' \
'-- --invalid user_arg' \
'/^\$@: /d'
expect "${getopts_long[5]}" == '$@: --invalid user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="--invalid" [1]="user_arg")'
}
@test "${FEATURE}: terminator, long option, extra arguments, verbose" {
compare '-- -i user_arg' \
'-- --invalid user_arg' \
'/^\$@: /d'
expect "${getopts_long[5]}" == '$@: --invalid user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="--invalid" [1]="user_arg")'
}
4 changes: 2 additions & 2 deletions test/bats/no_arguments.bats
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ load ../test_helper
@test "${FEATURE}: terminator, extra arguments, silent" {
compare '-- user_arg' \
'-- user_arg'
expect "${getopts_long[5]}" == '$@: user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="user_arg")'
}
@test "${FEATURE}: terminator, extra arguments, verbose" {
compare '-- user_arg' \
'-- user_arg'
expect "${getopts_long[5]}" == '$@: user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="user_arg")'
}
16 changes: 8 additions & 8 deletions test/bats/option_supplied.bats
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ load ../test_helper
@test "${FEATURE}: short option, terminator, extra arguments, silent" {
compare '-o user_val -- user_arg' \
'-o user_val -- user_arg'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}
@test "${FEATURE}: short option, terminator, extra arguments, verbose" {
compare '-o user_val -- user_arg' \
'-o user_val -- user_arg'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}

@test "${FEATURE}: long option, terminator, extra arguments, silent" {
compare '-o user_val -- user_arg' \
'--option user_val -- user_arg'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}
@test "${FEATURE}: long option, terminator, extra arguments, verbose" {
compare '-o user_val -- user_arg' \
'--option user_val -- user_arg'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}

# multiple same arguments
Expand Down Expand Up @@ -97,25 +97,25 @@ load ../test_helper
@test "${FEATURE}: terminator, short option, extra arguments, silent" {
compare '-- -o user_val user_arg' \
'-- -o user_val user_arg'
expect "${getopts_long[5]}" == '$@: -o user_val user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="-o" [1]="user_val" [2]="user_arg")'
}
@test "${FEATURE}: terminator, short option, extra arguments, verbose" {
compare '-- -o user_val user_arg' \
'-- -o user_val user_arg'
expect "${getopts_long[5]}" == '$@: -o user_val user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="-o" [1]="user_val" [2]="user_arg")'
}

@test "${FEATURE}: terminator, long option, extra arguments, silent" {
compare '-- -o user_val user_arg' \
'-- --option user_val user_arg' \
'/^\$@: /d'
expect "${getopts_long[5]}" == '$@: --option user_val user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="--option" [1]="user_val" [2]="user_arg")'
}
@test "${FEATURE}: terminator, long option, extra arguments, verbose" {
compare '-- -o user_val user_arg' \
'-- --option user_val user_arg' \
'/^\$@: /d'
expect "${getopts_long[5]}" == '$@: --option user_val user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="--option" [1]="user_val" [2]="user_arg")'
}

# option without an argument
Expand Down
16 changes: 8 additions & 8 deletions test/bats/toggle_triggered.bats
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ load ../test_helper
@test "${FEATURE}: short option, terminator, extra arguments, silent" {
compare '-t -- user_arg' \
'-t -- user_arg'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}
@test "${FEATURE}: short option, terminator, extra arguments, verbose" {
compare '-t -- user_arg' \
'-t -- user_arg'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}

@test "${FEATURE}: long option, terminator, extra arguments, silent" {
compare '-t -- user_arg' \
'--toggle -- user_arg'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}
@test "${FEATURE}: long option, terminator, extra arguments, verbose" {
compare '-t -- user_arg' \
'--toggle -- user_arg'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}

# multiple same arguments
Expand Down Expand Up @@ -97,23 +97,23 @@ load ../test_helper
@test "${FEATURE}: terminator, short option, extra arguments, silent" {
compare '-- -t user_arg' \
'-- -t user_arg'
expect "${getopts_long[5]}" == '$@: -t user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="-t" [1]="user_arg")'
}
@test "${FEATURE}: terminator, short option, extra arguments, verbose" {
compare '-- -t user_arg' \
'-- -t user_arg'
expect "${getopts_long[5]}" == '$@: -t user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="-t" [1]="user_arg")'
}

@test "${FEATURE}: terminator, long option, extra arguments, silent" {
compare '-- -t user_arg' \
'-- --toggle user_arg' \
'/^\$@: /d'
expect "${getopts_long[5]}" == '$@: --toggle user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="--toggle" [1]="user_arg")'
}
@test "${FEATURE}: terminator, long option, extra arguments, verbose" {
compare '-- -t user_arg' \
'-- --toggle user_arg' \
'/^\$@: /d'
expect "${getopts_long[5]}" == '$@: --toggle user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="--toggle" [1]="user_arg")'
}
16 changes: 8 additions & 8 deletions test/bats/value_supplied.bats
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,27 @@ load ../test_helper
@test "${FEATURE}: short option, terminator, extra arguments, silent" {
compare '-v user_val -- user_arg' \
'-v user_val -- user_arg'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}
@test "${FEATURE}: short option, terminator, extra arguments, verbose" {
compare '-v user_val -- user_arg' \
'-v user_val -- user_arg'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
}

@test "${FEATURE}: long option, terminator, extra arguments, silent" {
compare '-v user_val -- user_arg' \
'--variable=user_val -- user_arg' \
'/^OPTIND: /d'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
expect "${bash_getopts[5]}" == 'OPTIND: 4'
expect "${getopts_long[5]}" == 'OPTIND: 3'
}
@test "${FEATURE}: long option, terminator, extra arguments, verbose" {
compare '-v user_val -- user_arg' \
'--variable=user_val -- user_arg' \
'/^OPTIND: /d'
expect "${getopts_long[6]}" == '$@: user_arg'
expect "${getopts_long[6]}" == '$@: ([0]="user_arg")'
expect "${bash_getopts[5]}" == 'OPTIND: 4'
expect "${getopts_long[5]}" == 'OPTIND: 3'
}
Expand Down Expand Up @@ -121,25 +121,25 @@ load ../test_helper
@test "${FEATURE}: terminator, short option, extra arguments, silent" {
compare '-- -v user_val user_arg' \
'-- -v user_val user_arg'
expect "${getopts_long[5]}" == '$@: -v user_val user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="-v" [1]="user_val" [2]="user_arg")'
}
@test "${FEATURE}: terminator, short option, extra arguments, verbose" {
compare '-- -v user_val user_arg' \
'-- -v user_val user_arg'
expect "${getopts_long[5]}" == '$@: -v user_val user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="-v" [1]="user_val" [2]="user_arg")'
}

@test "${FEATURE}: terminator, long option, extra arguments, silent" {
compare '-- -v user_val user_arg' \
'-- --variable=user_val user_arg' \
'/^\$@: /d'
expect "${getopts_long[5]}" == '$@: --variable=user_val user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="--variable=user_val" [1]="user_arg")'
}
@test "${FEATURE}: terminator, long option, extra arguments, verbose" {
compare '-- -v user_val user_arg' \
'-- --variable=user_val user_arg' \
'/^\$@: /d'
expect "${getopts_long[5]}" == '$@: --variable=user_val user_arg'
expect "${getopts_long[5]}" == '$@: ([0]="--variable=user_val" [1]="user_arg")'
}

# variable without an argument
Expand Down
4 changes: 3 additions & 1 deletion test/bin/getopts-silent
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts-verbose
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts_long-github_26-silent
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts_long-github_26-verbose
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts_long-longspec_with_dash-silent
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts_long-longspec_with_dash-verbose
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts_long-longspec_with_dash_colon-silent
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts_long-longspec_with_dash_colon-verbose
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts_long-no_shortspec-silent
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts_long-no_shortspec-verbose
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts_long-shortspec_with_dash-silent
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts_long-shortspec_with_dash-verbose
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
4 changes: 3 additions & 1 deletion test/bin/getopts_long-silent
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ echo "OPTERR: ${OPTERR}"
echo "OPTKEY: ${OPTKEY}"
echo "OPTARG: ${OPTARG}"
echo "OPTIND: ${OPTIND}"
echo "\$@: ${*}"

args=("$@")
declare -p args | sed -e 's/declare -a args=/$@: /'
Loading

0 comments on commit 9b94aad

Please sign in to comment.