From 4acfbdeade98124dffcff8f6d75a681aa98395fe Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 1 Apr 2021 18:26:18 +0200 Subject: [PATCH] Fix oopsies, fix and add test for ynh_setup_source with patch --- data/helpers.d/utils | 6 ++++-- tests/test_helpers.d/ynhtest_setup_source.sh | 20 ++++++++++++++++++-- tests/test_helpers.sh | 6 ++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/data/helpers.d/utils b/data/helpers.d/utils index 942f6b34d..e651a5f77 100644 --- a/data/helpers.d/utils +++ b/data/helpers.d/utils @@ -217,11 +217,13 @@ ynh_setup_source () { fi # Apply patches - if (( $(find $YNH_APP_BASEDIR/sources/patches/ -type f -name "${source_id}-*.patch" 2> /dev/null | wc --lines) > "0" )) + local patches_folder=$(realpath $YNH_APP_BASEDIR/sources/patches/) + if (( $(find $patches_folder -type f -name "${source_id}-*.patch" 2> /dev/null | wc --lines) > "0" )) then (cd "$dest_dir" - for p in $YNH_APP_BASEDIR/sources/patches/${source_id}-*.patch + for p in $patches_folder/${source_id}-*.patch do + echo $p patch --strip=1 < $p done) || ynh_die --message="Unable to apply patches" fi diff --git a/tests/test_helpers.d/ynhtest_setup_source.sh b/tests/test_helpers.d/ynhtest_setup_source.sh index cd28bc933..69edf8ac9 100644 --- a/tests/test_helpers.d/ynhtest_setup_source.sh +++ b/tests/test_helpers.d/ynhtest_setup_source.sh @@ -28,7 +28,6 @@ ynhtest_setup_source_nominal() { test -e "$final_path/index.html" } - ynhtest_setup_source_nominal_upgrade() { final_path="$(mktemp -d -p $VAR_WWW)" _make_dummy_src > ../conf/dummy.src @@ -36,7 +35,6 @@ ynhtest_setup_source_nominal_upgrade() { ynh_setup_source --dest_dir="$final_path" --source_id="dummy" test "$(cat $final_path/index.html)" == "Lorem Ipsum" - echo $? # Except index.html to get overwritten during next ynh_setup_source echo "IEditedYou!" > $final_path/index.html @@ -63,3 +61,21 @@ ynhtest_setup_source_with_keep() { test "$(cat $final_path/index.html)" == "IEditedYou!" test "$(cat $final_path/test.txt)" == "IEditedYou!" } + +ynhtest_setup_source_with_patch() { + final_path="$(mktemp -d -p $VAR_WWW)" + _make_dummy_src > ../conf/dummy.src + + mkdir -p ../sources/patches + cat > ../sources/patches/dummy-index.html.patch << EOF +--- a/index.html ++++ b/index.html +@@ -1 +1,1 @@ +-Lorem Ipsum ++Lorem Ipsum dolor sit amet +EOF + + ynh_setup_source --dest_dir="$final_path" --source_id="dummy" + + test "$(cat $final_path/index.html)" == "Lorem Ipsum dolor sit amet" +} diff --git a/tests/test_helpers.sh b/tests/test_helpers.sh index 15879a18a..6a5f29bf1 100644 --- a/tests/test_helpers.sh +++ b/tests/test_helpers.sh @@ -34,10 +34,10 @@ trap cleanup EXIT SIGINT # Dummy http server, to serve archives for ynh_setup_source HTTPSERVER_DIR=$(mktemp -d) HTTPSERVER_PORT=1312 -pushd "$HTTPSERVER_DIR" +pushd "$HTTPSERVER_DIR" >/dev/null python -m SimpleHTTPServer $HTTPSERVER_PORT &>/dev/null & HTTPSERVER="$!" -popd +popd >/dev/null VAR_WWW=$(mktemp -d)/var/www mkdir -p $VAR_WWW @@ -54,8 +54,6 @@ TESTS=$(declare -F | grep ' ynhtest_' | awk '{print $3}') global_result=0 -echo $TESTS - for TEST in $TESTS do log_test $TEST