Skip to content

Commit 3bf0153

Browse files
authored
#1666: fixed integration-tests (#1686)
1 parent 87b1f4e commit 3bf0153

3 files changed

Lines changed: 110 additions & 101 deletions

File tree

cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ public Path backup(Path fileOrFolder) {
304304
if ((fileOrFolder != null) && (Files.isSymbolicLink(fileOrFolder) || isJunction(fileOrFolder))) {
305305
delete(fileOrFolder);
306306
} else if ((fileOrFolder != null) && Files.exists(fileOrFolder)) {
307+
this.context.trace("Going to backup {}", fileOrFolder);
307308
LocalDateTime now = LocalDateTime.now();
308309
String date = DateTimeUtil.formatDate(now, true);
309310
String time = DateTimeUtil.formatTime(now);

cli/src/test/all-tests-functions.sh

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ function doIdeCreate () {
1515
ide --batch -d create "${TEST_PROJECT_NAME}" "${settings_url}"
1616

1717
echo "Switching to directory: ${IDE_ROOT}/${TEST_PROJECT_NAME}"
18-
cd "${IDE_ROOT}/${TEST_PROJECT_NAME}" || exit
18+
cd "${IDE_ROOT}/${TEST_PROJECT_NAME}" || exit 1
1919
}
2020

2121
function doIdeCreateCleanup () {
2222
rm -rf "${IDE_ROOT:?}/${TEST_PROJECT_NAME}"
2323
}
2424

25-
function doDownloadSnapshot () {
25+
function doDownloadRelease () {
2626
mkdir -p "$WORK_DIR_INTEG_TEST"
2727
if [ "$1" != "" ]; then
2828
if [ -f "$1" ] && [[ $1 == *.tar.gz ]]; then
29-
echo "Local snapshot given. Copying to directory: ${WORK_DIR_INTEG_TEST}"
29+
echo "Local release given. Copying to directory: ${WORK_DIR_INTEG_TEST}"
3030
cp "$1" "$IDEASY_COMPRESSED_FILE"
3131
else
3232
echo "Expected a file ending with tar.gz - Given: ${1}"
@@ -77,15 +77,18 @@ function doGetOsType() {
7777
echo "$osType"
7878
}
7979

80-
81-
function doExtract() {
82-
echo "Extracting IDEasy archive: ${IDEASY_COMPRESSED_FILE} to: ${IDEASY_DIR}"
83-
if [ -f "${IDEASY_COMPRESSED_FILE:?}" ]; then
84-
tar xfz "${IDEASY_COMPRESSED_FILE:?}" --directory "${IDEASY_DIR:?}" || exit 1
85-
else
86-
echo "Could not find and extract release ${IDEASY_COMPRESSED_FILE:?}"
80+
# doCreateLink <source> <target-link>
81+
function doCreateLink() {
82+
echo "creating link from $1 to $2 in $PWD"
83+
if [ ! -e "$1" ]; then
84+
echo "Source file to link does not exist!"
8785
exit 1
8886
fi
87+
if doIsWindows; then
88+
cmd //c "mklink /J $(cygpath -w $2) $(cygpath -w $1)" || exit 1
89+
else
90+
ln -s "$1" "$2"
91+
fi
8992
}
9093

9194
# $@: success message
@@ -104,17 +107,15 @@ function doError() {
104107
}
105108

106109
function doIsMacOs() {
107-
local osType=$(doGetOsType)
108-
if [ "$osType" = "mac-arm64" ] || [ "$osType" = "mac-x64" ]
110+
if [ "${OSTYPE:0:6}" = "darwin" ]
109111
then
110112
return
111113
fi
112114
return 255
113115
}
114116

115117
function doIsWindows() {
116-
local osType=$(doGetOsType)
117-
if [ "$osType" = "windows-x64" ]
118+
if [ "${OSTYPE}" = "cygwin" ] || [ "${OSTYPE}" = "msys" ]
118119
then
119120
return
120121
fi

cli/src/test/all-tests.sh

Lines changed: 94 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,6 @@
22
#set -e
33
#set -o pipefail
44

5-
# Workaround to create license.agreement file and simulate a proper installation.
6-
mkdir -p "${HOME}"/.ide
7-
touch "${HOME}"/.ide/.license.agreement
8-
9-
source "$(dirname "${0}")"/all-tests-functions.sh
10-
11-
# Remove side-effects
12-
BAK_IDE_ROOT="${IDE_ROOT}"
13-
BAK_PATH="${PATH}"
14-
DEBUG_INTEGRATION_TEST_PREFIX="${HOME}/tmp/ideasy-integration-test-debug"
15-
16-
# Create backups of shell RC files to prevent destroying user's existing configuration
17-
BAK_BASHRC=""
18-
BAK_ZSHRC=""
19-
if [ -f "$HOME/.bashrc" ]; then
20-
BAK_BASHRC="$HOME/.bashrc.ideasy-test-backup"
21-
cp "$HOME/.bashrc" "$BAK_BASHRC"
22-
fi
23-
if [ -f "$HOME/.zshrc" ]; then
24-
BAK_ZSHRC="$HOME/.zshrc.ideasy-test-backup"
25-
cp "$HOME/.zshrc" "$BAK_ZSHRC"
26-
fi
27-
28-
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
29-
305
function doRestoreRcFiles() {
316
# Restore shell RC files from backups to preserve user's existing configuration
327
if [ -n "$BAK_BASHRC" ] && [ -f "$BAK_BASHRC" ]; then
@@ -40,30 +15,17 @@ function doRestoreRcFiles() {
4015
}
4116

4217
function doResetVariables() {
43-
IDE_HOME="${DEBUG_INTEGRATION_TEST}/home-dir"
18+
IDE_HOME="${DEBUG_INTEGRATION_TEST}"
4419
export IDE_ROOT="${IDE_HOME}/projects"
4520
IDEASY_DIR="${IDE_ROOT}/_ide"
46-
FUNCTIONS="${IDEASY_DIR}/installation/functions"
47-
IDE="${DEBUG_INTEGRATION_TEST}/home-dir/projects/_ide/bin/${BINARY_FILE_NAME}"
21+
IDEASY_INSTALLATION_DIR="${IDEASY_DIR}/installation"
22+
FUNCTIONS="${IDEASY_INSTALLATION_DIR}/functions"
23+
IDEASY_RELEASE_DIR_RELATIVE="software/maven/ideasy/ideasy/test"
24+
IDEASY_RELEASE_DIR="${IDEASY_DIR}/${IDEASY_RELEASE_DIR_RELATIVE}"
25+
IDE="${IDEASY_INSTALLATION_DIR}/bin/${BINARY_FILE_NAME}"
4826
TEST_RESULTS_FILE="${IDE_ROOT}/testResults"
4927
}
5028

51-
# Switch IDEasy binary file name based on github workflow matrix.os name (first argument of all-tests.sh)
52-
BINARY_FILE_NAME="ideasy"
53-
if doIsWindows; then
54-
BINARY_FILE_NAME="ideasy.exe"
55-
fi
56-
57-
START_TIME=$(date '+%Y-%m-%d_%H-%M-%S')
58-
DEBUG_INTEGRATION_TEST="${DEBUG_INTEGRATION_TEST_PREFIX}-${START_TIME}"
59-
doResetVariables
60-
61-
test_files_directory=$(realpath "$0" | xargs dirname)
62-
63-
success=0
64-
failure=0
65-
total=0
66-
6729
function doTestsInner() {
6830
# Note: requires var test_files_directory to be set.
6931
for testpath in "${test_files_directory:?}/integration-tests"/*; do
@@ -118,60 +80,105 @@ function doTests () {
11880
exit 0
11981
}
12082

121-
function main () {
122-
echo "Running integration tests from directory: ${test_files_directory}"
83+
# Workaround to create license.agreement file and simulate a proper installation.
84+
mkdir -p "${HOME}"/.ide
85+
touch "${HOME}"/.ide/.license.agreement
86+
87+
source "$(dirname "${0}")"/all-tests-functions.sh
88+
89+
# Remove side-effects
90+
BAK_IDE_ROOT="${IDE_ROOT}"
91+
BAK_PATH="${PATH}"
92+
DEBUG_INTEGRATION_TEST="${HOME}/tmp/ideasy-integration-test-debug"
93+
if [ -e "${DEBUG_INTEGRATION_TEST}" ]; then
94+
echo "Deleting previous test folder ${DEBUG_INTEGRATION_TEST}"
95+
rm -rf "${DEBUG_INTEGRATION_TEST}"
96+
fi
97+
# Create backups of shell RC files to prevent destroying user's existing configuration
98+
BAK_BASHRC=""
99+
BAK_ZSHRC=""
100+
if [ -f "$HOME/.bashrc" ]; then
101+
BAK_BASHRC="$HOME/.bashrc.ideasy-test-backup"
102+
cp "$HOME/.bashrc" "$BAK_BASHRC"
103+
fi
104+
if [ -f "$HOME/.zshrc" ]; then
105+
BAK_ZSHRC="$HOME/.zshrc.ideasy-test-backup"
106+
cp "$HOME/.zshrc" "$BAK_ZSHRC"
107+
fi
108+
109+
trap "export PATH=\"${BAK_PATH}\" && export IDE_ROOT=\"${BAK_IDE_ROOT}\" && doRestoreRcFiles && echo \"PATH, IDE_ROOT, and shell RC files restored\"" EXIT
110+
111+
# Switch IDEasy binary file name based on github workflow matrix.os name (first argument of all-tests.sh)
112+
BINARY_FILE_NAME="ideasy"
113+
if doIsWindows; then
114+
BINARY_FILE_NAME="ideasy.exe"
115+
fi
116+
117+
doResetVariables
118+
test_files_directory=$(realpath "$0" | xargs dirname)
119+
120+
success=0
121+
failure=0
122+
total=0
123+
124+
echo "Running integration tests from directory: ${test_files_directory}"
123125

124-
# rm -rf "${DEBUG_INTEGRATION_TEST_PREFIX}"
125126
# Only need to mkdir once:
126127
echo "Creating IDEasy directory at: ${IDEASY_DIR}"
127128
mkdir -p "${IDEASY_DIR}"
128129

129130
echo "Switching directory to: ${IDEASY_DIR}"
130131
cd "${IDEASY_DIR}" || exit
131132

132-
# Determine IDEasy release to use for testing (default: downloads latest release)
133-
# NOTE: For debugging purposes, if you want to avoid download time, you can
134-
# uncomment var snapshot, set it to a local compressed IDEasy release and
135-
# give it to 'doDownloadSnapshot' as first argument..
136-
local snapshot=""
137-
#snapshot="$HOME/tmp/downloads/ide-cli-2025.04.001-20250404.093145-4-linux-x64.tar.gz"
138-
doDownloadSnapshot "${snapshot}"
139-
# Extract IDEasy and setup
140-
doExtract
141-
142-
# source ./bin/ide
143-
echo "Switching directory to: ${IDE_ROOT}"
144-
cd "${IDE_ROOT}" || exit
145-
146-
# upgrade to latest snapshot
147-
echo "Upgrading IDEasy to latest SNAPSHOT"
148-
$IDE -d --batch upgrade --mode=snapshot || echo "Upgrade failed, continuing with downloaded version"
149-
150-
# source functions (resets IDEasy)
151-
echo "Sourcing functions to: ${FUNCTIONS}"
152-
# Add IDE bin to PATH so ideasy command can be found
153-
export PATH="${IDEASY_DIR}/bin:$PATH"
154-
# Try installation path first, then fall back to root
155-
if [ -f "${FUNCTIONS:?}" ]; then
156-
source "${FUNCTIONS:?}"
157-
elif [ -f "${IDEASY_DIR}/functions" ]; then
158-
echo "Using functions from root: ${IDEASY_DIR}/functions"
159-
source "${IDEASY_DIR}/functions"
160-
else
161-
echo "ERROR: Could not find functions file"
162-
exit 1
163-
fi
133+
# Determine IDEasy release to use for testing (default: downloads latest release)
134+
# NOTE: For debugging purposes, if you want to avoid download time, you can
135+
# uncomment var snapshot, set it to a local compressed IDEasy release
136+
local_release=""
137+
#snapshot="$HOME/tmp/downloads/ide-cli-2025.04.001-20250404.093145-4-linux-x64.tar.gz"
138+
doDownloadRelease "${local_release}"
139+
# Extract IDEasy and setup
140+
mkdir -p "${IDEASY_RELEASE_DIR}"
141+
echo "Extracting IDEasy archive ${IDEASY_COMPRESSED_FILE} to ${IDEASY_RELEASE_DIR}"
142+
tar xfz "${IDEASY_COMPRESSED_FILE:?}" --directory "${IDEASY_RELEASE_DIR}" || exit 1
143+
cd ${IDEASY_DIR}
144+
doCreateLink ${IDEASY_RELEASE_DIR_RELATIVE} installation
145+
# avoid cloning urls on every run in local execution
146+
IDE_URLS="${BAK_IDE_ROOT}/_ide/urls"
147+
if [ -d "${IDE_URLS}" ]; then
148+
doCreateLink "$IDE_URLS" urls
149+
fi
164150

165-
echo "Checking version after upgrade"
166-
ide -v
151+
echo "Switching directory to: ${IDE_ROOT}"
152+
cd "${IDE_ROOT}" || exit 1
153+
154+
155+
# upgrade to latest snapshot
156+
echo "Upgrading IDEasy to latest SNAPSHOT"
157+
$IDE -d --batch upgrade --mode=snapshot || exit 1 #echo "Upgrade failed, continuing with downloaded version"
158+
159+
# source functions (resets IDEasy)
160+
echo "Sourcing functions from: ${FUNCTIONS}"
161+
# Add IDE bin to PATH so ideasy command can be found
162+
export PATH="${IDEASY_DIR}/installation/bin:$PATH"
163+
# Try installation path first, then fall back to root
164+
if [ -f "${FUNCTIONS:?}" ]; then
165+
source "${FUNCTIONS:?}"
166+
elif [ -f "${IDEASY_DIR}/functions" ]; then
167+
echo "Using functions from root: ${IDEASY_DIR}/functions"
168+
source "${IDEASY_DIR}/functions"
169+
else
170+
echo "ERROR: Could not find functions file"
171+
exit 1
172+
fi
167173

168-
doIdeCreate
174+
echo "Checking version after upgrade"
175+
which ideasy
176+
ide -v
169177

170-
doTests
178+
doIdeCreate
171179

172-
echo "DONE"
173-
exit 0
174-
}
180+
doTests
175181

176-
main
182+
echo "DONE"
183+
exit 0
177184

0 commit comments

Comments
 (0)