From a9f5bccbbd1b4258cda867c175d778a856196b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Tue, 20 Jan 2026 19:46:39 +0100 Subject: [PATCH] #1666: fixed integration-tests --- .../devonfw/tools/ide/io/FileAccessImpl.java | 1 + cli/src/test/all-tests-functions.sh | 29 +-- cli/src/test/all-tests.sh | 181 +++++++++--------- 3 files changed, 110 insertions(+), 101 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java b/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java index 444e08912f..0f664365ef 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java @@ -304,6 +304,7 @@ public Path backup(Path fileOrFolder) { if ((fileOrFolder != null) && (Files.isSymbolicLink(fileOrFolder) || isJunction(fileOrFolder))) { delete(fileOrFolder); } else if ((fileOrFolder != null) && Files.exists(fileOrFolder)) { + this.context.trace("Going to backup {}", fileOrFolder); LocalDateTime now = LocalDateTime.now(); String date = DateTimeUtil.formatDate(now, true); String time = DateTimeUtil.formatTime(now); diff --git a/cli/src/test/all-tests-functions.sh b/cli/src/test/all-tests-functions.sh index ff296172ea..bf8f9ef560 100644 --- a/cli/src/test/all-tests-functions.sh +++ b/cli/src/test/all-tests-functions.sh @@ -15,18 +15,18 @@ function doIdeCreate () { ide --batch -d create "${TEST_PROJECT_NAME}" "${settings_url}" echo "Switching to directory: ${IDE_ROOT}/${TEST_PROJECT_NAME}" - cd "${IDE_ROOT}/${TEST_PROJECT_NAME}" || exit + cd "${IDE_ROOT}/${TEST_PROJECT_NAME}" || exit 1 } function doIdeCreateCleanup () { rm -rf "${IDE_ROOT:?}/${TEST_PROJECT_NAME}" } -function doDownloadSnapshot () { +function doDownloadRelease () { mkdir -p "$WORK_DIR_INTEG_TEST" if [ "$1" != "" ]; then if [ -f "$1" ] && [[ $1 == *.tar.gz ]]; then - echo "Local snapshot given. Copying to directory: ${WORK_DIR_INTEG_TEST}" + echo "Local release given. Copying to directory: ${WORK_DIR_INTEG_TEST}" cp "$1" "$IDEASY_COMPRESSED_FILE" else echo "Expected a file ending with tar.gz - Given: ${1}" @@ -77,15 +77,18 @@ function doGetOsType() { echo "$osType" } - -function doExtract() { - echo "Extracting IDEasy archive: ${IDEASY_COMPRESSED_FILE} to: ${IDEASY_DIR}" - if [ -f "${IDEASY_COMPRESSED_FILE:?}" ]; then - tar xfz "${IDEASY_COMPRESSED_FILE:?}" --directory "${IDEASY_DIR:?}" || exit 1 - else - echo "Could not find and extract release ${IDEASY_COMPRESSED_FILE:?}" +# doCreateLink +function doCreateLink() { + echo "creating link from $1 to $2 in $PWD" + if [ ! -e "$1" ]; then + echo "Source file to link does not exist!" exit 1 fi + if doIsWindows; then + cmd //c "mklink /J $(cygpath -w $2) $(cygpath -w $1)" || exit 1 + else + ln -s "$1" "$2" + fi } # $@: success message @@ -104,8 +107,7 @@ function doError() { } function doIsMacOs() { - local osType=$(doGetOsType) - if [ "$osType" = "mac-arm64" ] || [ "$osType" = "mac-x64" ] + if [ "${OSTYPE:0:6}" = "darwin" ] then return fi @@ -113,8 +115,7 @@ function doIsMacOs() { } function doIsWindows() { - local osType=$(doGetOsType) - if [ "$osType" = "windows-x64" ] + if [ "${OSTYPE}" = "cygwin" ] || [ "${OSTYPE}" = "msys" ] then return fi diff --git a/cli/src/test/all-tests.sh b/cli/src/test/all-tests.sh index 0b9be1e27c..11171f1261 100755 --- a/cli/src/test/all-tests.sh +++ b/cli/src/test/all-tests.sh @@ -2,31 +2,6 @@ #set -e #set -o pipefail -# Workaround to create license.agreement file and simulate a proper installation. -mkdir -p "${HOME}"/.ide -touch "${HOME}"/.ide/.license.agreement - -source "$(dirname "${0}")"/all-tests-functions.sh - -# Remove side-effects -BAK_IDE_ROOT="${IDE_ROOT}" -BAK_PATH="${PATH}" -DEBUG_INTEGRATION_TEST_PREFIX="${HOME}/tmp/ideasy-integration-test-debug" - -# Create backups of shell RC files to prevent destroying user's existing configuration -BAK_BASHRC="" -BAK_ZSHRC="" -if [ -f "$HOME/.bashrc" ]; then - BAK_BASHRC="$HOME/.bashrc.ideasy-test-backup" - cp "$HOME/.bashrc" "$BAK_BASHRC" -fi -if [ -f "$HOME/.zshrc" ]; then - BAK_ZSHRC="$HOME/.zshrc.ideasy-test-backup" - cp "$HOME/.zshrc" "$BAK_ZSHRC" -fi - -trap "export PATH=\"${BAK_PATH}\" && export IDE_ROOT=\"${BAK_IDE_ROOT}\" && rm -rf \"${DEBUG_INTEGRATION_TEST_PREFIX}\" && doRestoreRcFiles && echo \"PATH, IDE_ROOT, and shell RC files restored\"" EXIT - function doRestoreRcFiles() { # Restore shell RC files from backups to preserve user's existing configuration if [ -n "$BAK_BASHRC" ] && [ -f "$BAK_BASHRC" ]; then @@ -40,30 +15,17 @@ function doRestoreRcFiles() { } function doResetVariables() { - IDE_HOME="${DEBUG_INTEGRATION_TEST}/home-dir" + IDE_HOME="${DEBUG_INTEGRATION_TEST}" export IDE_ROOT="${IDE_HOME}/projects" IDEASY_DIR="${IDE_ROOT}/_ide" - FUNCTIONS="${IDEASY_DIR}/installation/functions" - IDE="${DEBUG_INTEGRATION_TEST}/home-dir/projects/_ide/bin/${BINARY_FILE_NAME}" + IDEASY_INSTALLATION_DIR="${IDEASY_DIR}/installation" + FUNCTIONS="${IDEASY_INSTALLATION_DIR}/functions" + IDEASY_RELEASE_DIR_RELATIVE="software/maven/ideasy/ideasy/test" + IDEASY_RELEASE_DIR="${IDEASY_DIR}/${IDEASY_RELEASE_DIR_RELATIVE}" + IDE="${IDEASY_INSTALLATION_DIR}/bin/${BINARY_FILE_NAME}" TEST_RESULTS_FILE="${IDE_ROOT}/testResults" } -# Switch IDEasy binary file name based on github workflow matrix.os name (first argument of all-tests.sh) -BINARY_FILE_NAME="ideasy" -if doIsWindows; then - BINARY_FILE_NAME="ideasy.exe" -fi - -START_TIME=$(date '+%Y-%m-%d_%H-%M-%S') -DEBUG_INTEGRATION_TEST="${DEBUG_INTEGRATION_TEST_PREFIX}-${START_TIME}" -doResetVariables - -test_files_directory=$(realpath "$0" | xargs dirname) - -success=0 -failure=0 -total=0 - function doTestsInner() { # Note: requires var test_files_directory to be set. for testpath in "${test_files_directory:?}/integration-tests"/*; do @@ -118,10 +80,49 @@ function doTests () { exit 0 } -function main () { - echo "Running integration tests from directory: ${test_files_directory}" +# Workaround to create license.agreement file and simulate a proper installation. +mkdir -p "${HOME}"/.ide +touch "${HOME}"/.ide/.license.agreement + +source "$(dirname "${0}")"/all-tests-functions.sh + +# Remove side-effects +BAK_IDE_ROOT="${IDE_ROOT}" +BAK_PATH="${PATH}" +DEBUG_INTEGRATION_TEST="${HOME}/tmp/ideasy-integration-test-debug" +if [ -e "${DEBUG_INTEGRATION_TEST}" ]; then + echo "Deleting previous test folder ${DEBUG_INTEGRATION_TEST}" + rm -rf "${DEBUG_INTEGRATION_TEST}" +fi +# Create backups of shell RC files to prevent destroying user's existing configuration +BAK_BASHRC="" +BAK_ZSHRC="" +if [ -f "$HOME/.bashrc" ]; then + BAK_BASHRC="$HOME/.bashrc.ideasy-test-backup" + cp "$HOME/.bashrc" "$BAK_BASHRC" +fi +if [ -f "$HOME/.zshrc" ]; then + BAK_ZSHRC="$HOME/.zshrc.ideasy-test-backup" + cp "$HOME/.zshrc" "$BAK_ZSHRC" +fi + +trap "export PATH=\"${BAK_PATH}\" && export IDE_ROOT=\"${BAK_IDE_ROOT}\" && doRestoreRcFiles && echo \"PATH, IDE_ROOT, and shell RC files restored\"" EXIT + +# Switch IDEasy binary file name based on github workflow matrix.os name (first argument of all-tests.sh) +BINARY_FILE_NAME="ideasy" +if doIsWindows; then + BINARY_FILE_NAME="ideasy.exe" +fi + +doResetVariables +test_files_directory=$(realpath "$0" | xargs dirname) + +success=0 +failure=0 +total=0 + +echo "Running integration tests from directory: ${test_files_directory}" - # rm -rf "${DEBUG_INTEGRATION_TEST_PREFIX}" # Only need to mkdir once: echo "Creating IDEasy directory at: ${IDEASY_DIR}" mkdir -p "${IDEASY_DIR}" @@ -129,49 +130,55 @@ function main () { echo "Switching directory to: ${IDEASY_DIR}" cd "${IDEASY_DIR}" || exit - # Determine IDEasy release to use for testing (default: downloads latest release) - # NOTE: For debugging purposes, if you want to avoid download time, you can - # uncomment var snapshot, set it to a local compressed IDEasy release and - # give it to 'doDownloadSnapshot' as first argument.. - local snapshot="" - #snapshot="$HOME/tmp/downloads/ide-cli-2025.04.001-20250404.093145-4-linux-x64.tar.gz" - doDownloadSnapshot "${snapshot}" - # Extract IDEasy and setup - doExtract - - # source ./bin/ide - echo "Switching directory to: ${IDE_ROOT}" - cd "${IDE_ROOT}" || exit - - # upgrade to latest snapshot - echo "Upgrading IDEasy to latest SNAPSHOT" - $IDE -d --batch upgrade --mode=snapshot || echo "Upgrade failed, continuing with downloaded version" - - # source functions (resets IDEasy) - echo "Sourcing functions to: ${FUNCTIONS}" - # Add IDE bin to PATH so ideasy command can be found - export PATH="${IDEASY_DIR}/bin:$PATH" - # Try installation path first, then fall back to root - if [ -f "${FUNCTIONS:?}" ]; then - source "${FUNCTIONS:?}" - elif [ -f "${IDEASY_DIR}/functions" ]; then - echo "Using functions from root: ${IDEASY_DIR}/functions" - source "${IDEASY_DIR}/functions" - else - echo "ERROR: Could not find functions file" - exit 1 - fi +# Determine IDEasy release to use for testing (default: downloads latest release) +# NOTE: For debugging purposes, if you want to avoid download time, you can +# uncomment var snapshot, set it to a local compressed IDEasy release +local_release="" +#snapshot="$HOME/tmp/downloads/ide-cli-2025.04.001-20250404.093145-4-linux-x64.tar.gz" +doDownloadRelease "${local_release}" +# Extract IDEasy and setup +mkdir -p "${IDEASY_RELEASE_DIR}" +echo "Extracting IDEasy archive ${IDEASY_COMPRESSED_FILE} to ${IDEASY_RELEASE_DIR}" +tar xfz "${IDEASY_COMPRESSED_FILE:?}" --directory "${IDEASY_RELEASE_DIR}" || exit 1 +cd ${IDEASY_DIR} +doCreateLink ${IDEASY_RELEASE_DIR_RELATIVE} installation +# avoid cloning urls on every run in local execution +IDE_URLS="${BAK_IDE_ROOT}/_ide/urls" +if [ -d "${IDE_URLS}" ]; then + doCreateLink "$IDE_URLS" urls +fi - echo "Checking version after upgrade" - ide -v +echo "Switching directory to: ${IDE_ROOT}" +cd "${IDE_ROOT}" || exit 1 + + +# upgrade to latest snapshot +echo "Upgrading IDEasy to latest SNAPSHOT" +$IDE -d --batch upgrade --mode=snapshot || exit 1 #echo "Upgrade failed, continuing with downloaded version" + +# source functions (resets IDEasy) +echo "Sourcing functions from: ${FUNCTIONS}" +# Add IDE bin to PATH so ideasy command can be found +export PATH="${IDEASY_DIR}/installation/bin:$PATH" +# Try installation path first, then fall back to root +if [ -f "${FUNCTIONS:?}" ]; then + source "${FUNCTIONS:?}" +elif [ -f "${IDEASY_DIR}/functions" ]; then + echo "Using functions from root: ${IDEASY_DIR}/functions" + source "${IDEASY_DIR}/functions" +else + echo "ERROR: Could not find functions file" + exit 1 +fi - doIdeCreate +echo "Checking version after upgrade" +which ideasy +ide -v - doTests +doIdeCreate - echo "DONE" - exit 0 -} +doTests -main +echo "DONE" +exit 0