Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 15 additions & 14 deletions cli/src/test/all-tests-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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 <source> <target-link>
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
Expand All @@ -104,17 +107,15 @@ function doError() {
}

function doIsMacOs() {
local osType=$(doGetOsType)
if [ "$osType" = "mac-arm64" ] || [ "$osType" = "mac-x64" ]
if [ "${OSTYPE:0:6}" = "darwin" ]
then
return
fi
return 255
}

function doIsWindows() {
local osType=$(doGetOsType)
if [ "$osType" = "windows-x64" ]
if [ "${OSTYPE}" = "cygwin" ] || [ "${OSTYPE}" = "msys" ]
then
return
fi
Expand Down
181 changes: 94 additions & 87 deletions cli/src/test/all-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -118,60 +80,105 @@ 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}"

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