From bdb92590112a66543b3af30f2f680ec68ec55b14 Mon Sep 17 00:00:00 2001 From: xonixx Date: Wed, 25 Dec 2024 00:03:14 +0200 Subject: [PATCH] selfupdate is broken #174 : adjust/fix selfupdate test --- tests/200_update.sh | 75 +++++++++++++++++++++++++++---------------- tests/200_update.tush | 32 +++++++++--------- 2 files changed, 62 insertions(+), 45 deletions(-) diff --git a/tests/200_update.sh b/tests/200_update.sh index 747608f..92a96c4 100644 --- a/tests/200_update.sh +++ b/tests/200_update.sh @@ -5,21 +5,19 @@ @define D '/tmp/dirXXX with spaces' #@define D '/tmp/dirXXX' -@goal makesure_prepared +@goal env_prepared [[ -d "$D" ]] && rm -r "$D" mkdir "$D" - awk -v X="$(cd "$MYDIR/.."; pwd)" '/AWK_DIR=/{ $0 = "AWK_DIR=" X } 1' "../$MAKESURE" > "$D/$MAKESURE" - chmod +x "$D/$MAKESURE" # cat "$D/$MAKESURE"; exit - export NEXT_VERSION=XXX - if [[ "$("$D/$MAKESURE" --version)" != "XXX" ]] - then - # this is compiled version - awk '/^exec/ { sub(/Version=[0-9.]+/,"Version=XXX") } 1' "$D/$MAKESURE" > "$D/$MAKESURE"_1 - cat "$D/$MAKESURE"_1 > "$D/$MAKESURE" - rm "$D/$MAKESURE"_1 - fi +# export NEXT_VERSION=0.9.22 # TODO calc by subtracting 1 +# if [[ "$("$D/$MAKESURE" --version)" != "$NEXT_VERSION" ]] +# then +# # this is compiled version +# awk '/^exec/ { sub(/Version=[0-9.]+/,"Version=XXX") } 1' "$D/$MAKESURE" > "$D/$MAKESURE"_1 +# cat "$D/$MAKESURE"_1 > "$D/$MAKESURE" +# rm "$D/$MAKESURE"_1 +# fi for cmd in awk mktemp rm cp dirname cat chmod do @@ -37,12 +35,22 @@ done @lib + function prepare_makesure() { + awk -v X="$(cd "$MYDIR/.."; pwd)" '/AWK_DIR=/{ $0 = "AWK_DIR=" X } 1' "../$MAKESURE" > "$D/$MAKESURE" + chmod +x "$D/$MAKESURE" + } function run_selfupdate() { export PATH="$D" - export NEXT_VERSION=XXX + + prepare_makesure + export NEXT_VERSION=0.9.22 # TODO calc by subtracting 1 "$D/$MAKESURE" --version echo 'selfupdate 1' "$D/$MAKESURE" --selfupdate + + local latestVersion="$("$D/$MAKESURE" --version)" + prepare_makesure + export NEXT_VERSION="$latestVersion" echo 'selfupdate 2' "$D/$MAKESURE" --selfupdate "$D/$MAKESURE" --version @@ -50,7 +58,7 @@ } @goal test_err -@depends_on makesure_prepared +@depends_on env_prepared @use_lib run_selfupdate @@ -65,26 +73,37 @@ run_selfupdate # TODO is it possible to test via native wget if available? +#@goal wget_prepared +#@depends_on env_prepared +# cmd="wget" +# +# echo $'#!/bin/sh +#echo "running wget" +## fake wget with curl +#exec awk -v CURL="'$(command -v curl)$'" -v a1="$1" -v a2="$2" -v a3="$3" \' +#BEGIN { +#sub(/-q/,"-s",a1) +#sub(/-O/,"-o",a3) +##print(CURL " " a1 " " a2 " " a3) +#system(CURL " " a1 " " a2 " " a3) +#}\' +#' > "$D/$cmd" +# +# chmod +x "$D/$cmd" + @goal wget_prepared -@depends_on makesure_prepared +@depends_on env_prepared cmd="wget" - - echo $'#!/bin/sh -echo "running wget" -# fake wget with curl -exec awk -v CURL="'$(command -v curl)$'" -v a1="$1" -v a2="$2" -v a3="$3" \' -BEGIN { -sub(/-q/,"-s",a1) -sub(/-O/,"-o",a3) -#print(CURL " " a1 " " a2 " " a3) -system(CURL " " a1 " " a2 " " a3) -}\' -' > "$D/$cmd" - + cmd1=`command -v $cmd` + { + echo "#!/bin/sh" + echo 'echo "running wget"' + echo "exec $cmd1 \"\$@\"" + } > "$D/$cmd" chmod +x "$D/$cmd" @goal curl_prepared -@depends_on makesure_prepared +@depends_on env_prepared cmd="curl" cmd1=`command -v $cmd` { diff --git a/tests/200_update.tush b/tests/200_update.tush index 43ff0e1..84c531b 100644 --- a/tests/200_update.tush +++ b/tests/200_update.tush @@ -1,40 +1,38 @@ -$ ./$MAKESURE -f tests/200_update.sh test_err -| goal 'makesure_prepared' ... +$ { ./$MAKESURE -f tests/200_update.sh test_err; echo 'exit_code '$?; } | awk '/^exit_code/ { exit $2 } { gsub(/[0-9][0-9.]+/,"VER") } 1' +| goal 'env_prepared' ... | goal 'test_err' ... -| XXX +| VER | selfupdate 1 | goal 'test_err' failed @ wget/curl not found @ Please use manual update: https://makesure.dev/Installation.html ? 1 -$ ./$MAKESURE -f tests/200_update.sh test_wget | awk '{ sub(/[0-9][0-9.]+/,"YYY") } 1' -| goal 'makesure_prepared' ... +$ ./$MAKESURE -f tests/200_update.sh test_wget | awk '{ gsub(/[0-9][0-9.]+/,"VER") } 1' +| goal 'env_prepared' ... | goal 'wget_prepared' ... | goal 'test_wget' ... -| XXX +| VER | selfupdate 1 | running wget | running wget -| updated XXX -> YYY +| updated VER -> VER | selfupdate 2 | running wget -| running wget -| you have latest version YYY installed -| YYY +| you have latest version VER installed +| VER -$ ./$MAKESURE -f tests/200_update.sh test_curl | awk '{ sub(/[0-9][0-9.]+/,"YYY") } 1' -| goal 'makesure_prepared' ... +$ ./$MAKESURE -f tests/200_update.sh test_curl | awk '{ gsub(/[0-9][0-9.]+/,"VER") } 1' +| goal 'env_prepared' ... | goal 'curl_prepared' ... | goal 'test_curl' ... -| XXX +| VER | selfupdate 1 | running curl | running curl -| updated XXX -> YYY +| updated VER -> VER | selfupdate 2 | running curl -| running curl -| you have latest version YYY installed -| YYY +| you have latest version VER installed +| VER