Skip to content

Commit

Permalink
selfupdate is broken #174 : adjust/fix selfupdate test
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Dec 24, 2024
1 parent d3d1c8d commit bdb9259
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 45 deletions.
75 changes: 47 additions & 28 deletions tests/200_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,20 +35,30 @@
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
rm -r "$D"
}

@goal test_err
@depends_on makesure_prepared
@depends_on env_prepared
@use_lib
run_selfupdate

Expand All @@ -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`
{
Expand Down
32 changes: 15 additions & 17 deletions tests/200_update.tush
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bdb9259

Please sign in to comment.