From 0de84b69c1911ca3968946eed738cc31a61d9b35 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Tue, 4 Jun 2024 16:30:22 +0200 Subject: [PATCH] fix(common): output correct parameter values Previously with the right number of parameters that take values and the right order it could happen that a parameter value got replaced by an action when the script output the parameters. This change fixes this. Fixes: #11676 --- resources/build/test/test.sh | 49 ++++++++++++++++++++++++++++-------- resources/builder.inc.sh | 1 + 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/resources/build/test/test.sh b/resources/build/test/test.sh index 3b902f0f78..60c86072b0 100755 --- a/resources/build/test/test.sh +++ b/resources/build/test/test.sh @@ -111,7 +111,9 @@ builder_describe \ ":engine Thomas, y'know" \ "--power,-p Use powerful mode" \ "--zoom,-z Use zoom mode" \ - "--feature=FOO Enable feature foo" + "--feature=FOO Enable feature foo" \ + "--bar=BAR Enable bar" \ + "--baz=BAZ Enable baz" #---------------------------------------------------------------------- # Test --options @@ -132,21 +134,39 @@ else builder_die "FAIL: --zoom option not found" fi +function verify_option() { + local OPTIONNAME=$1 + local VARIABLE=$2 + local EXCPECTED=$3 + + if builder_has_option ${OPTIONNAME}; then + if [[ ${!VARIABLE} == ${EXCPECTED} ]]; then + echo "PASS: ${OPTIONNAME} option variable \$${VARIABLE} has expected value '${EXCPECTED}'" + else + builder_die "FAIL: ${OPTIONNAME} option variable \$${VARIABLE} had value '${!VARIABLE}' but should have had '${EXCPECTED}'" + fi + else + builder_die "FAIL: ${OPTIONNAME} option not found" + fi +} + #---------------------------------------------------------------------- # Test --feature echo -e "${COLOR_BLUE}## Testing: builder_parse --feature xyzzy${COLOR_RESET}" builder_parse --feature xyzzy -if builder_has_option --feature; then - if [[ $FOO == xyzzy ]]; then - echo "PASS: --feature option variable \$FOO has expected value 'xyzzy'" - else - builder_die "FAIL: --feature option variable \$FOO had value '$FOO' but should have had 'xyzzy'" - fi -else - builder_die "FAIL: --feature option not found" -fi +verify_option --feature FOO xyzzy + +#---------------------------------------------------------------------- +# Test --feature --bar --baz + +echo -e "${COLOR_BLUE}## Testing: builder_parse --feature xyzzy --bar abc --baz def test${COLOR_RESET}" +builder_parse --feature xyzzy --bar abc --baz def test + +verify_option --feature FOO xyzzy +verify_option --bar BAR abc +verify_option --baz BAZ def builder_parse -- one two "three four five" if [[ ${builder_extra_params[0]} != "one" ]]; then @@ -159,6 +179,15 @@ if [[ ${builder_extra_params[2]} != "three four five" ]]; then builder_die "FAIL: -- extra parameter 'three four five' not found" fi +#---------------------------------------------------------------------- +# Test output of: --feature --bar --baz (#11676) +echo -e "${COLOR_BLUE}## Testing output of: builder_parse --feature xyzzy --bar abc --baz def test${COLOR_RESET}" +parse_output=$(builder_parse --feature xyzzy --bar abc --baz def test) +expected="$(builder_echo setmark "test.sh parameters: <--feature xyzzy --bar abc --baz def test>")" +if [[ "${parse_output[*]}" != "${expected}" ]]; then + builder_die "FAIL: Wrong output for '--feature xyzzy --bar abc --baz def test':\n Actual : ${parse_output[*]}\n Expected: ${expected}" +fi + # Run tests based in separate scripts to facilitate their operation #---------------------------------------------------------------------- diff --git a/resources/builder.inc.sh b/resources/builder.inc.sh index c33a2785f9..9dc7f17994 100755 --- a/resources/builder.inc.sh +++ b/resources/builder.inc.sh @@ -1344,6 +1344,7 @@ _builder_parse_expanded_parameters() { _builder_chosen_options+=("$key") if [[ ! -z ${_builder_options_var[$key]+x} ]]; then shift + n=$((n + 1)) # Set the variable associated with this option to the next parameter value # A little bit of hoop jumping here to avoid issues with cygwin paths being # corrupted too early in the game