Skip to content

Commit 48442b9

Browse files
Enhance path normalization in run-tool-tests.sh and add integration test script
- Updated path normalization logic in run-tool-tests.sh to handle both macOS and Linux environments more effectively by using the repository root directory. - Introduced a new integration test script (test-tools.sh) to automate testing for each tool in the plugins/tools directory, logging failures and providing feedback on test results.
1 parent 579b70a commit 48442b9

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

integration-tests/test-tools.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Initialize failed tools file
4+
rm -f /tmp/failed_tools.txt
5+
touch /tmp/failed_tools.txt
6+
7+
# Run tests for each tool directory
8+
for tool_dir in plugins/tools/*/; do
9+
tool_name=$(basename "$tool_dir")
10+
if [ -d "$tool_dir/test/src" ]; then
11+
echo "Running tests for $tool_name..."
12+
./run-tool-tests.sh "$tool_name" || {
13+
echo "❌ Test failed for $tool_name"
14+
echo "$tool_name" >>/tmp/failed_tools.txt
15+
}
16+
fi
17+
done
18+
19+
# Check if any tools failed
20+
if [ -s /tmp/failed_tools.txt ] && [ "$(wc -l </tmp/failed_tools.txt)" -gt 0 ]; then
21+
echo -e "\n❌ The following tools failed their tests:"
22+
cat /tmp/failed_tools.txt
23+
echo "::error::Some tool tests failed. Please check the logs above for details."
24+
exit 1
25+
else
26+
echo "✅ All tool tests passed successfully!"
27+
fi

run-tool-tests.sh

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
# Function to normalize paths in a file
44
normalize_paths() {
55
local file=$1
6-
local path_prefix
6+
# Get the repository root directory (5 levels up from current test/src directory)
7+
local repo_root=$(cd ../../../../.. && pwd)
78

9+
# Normalize absolute paths to relative ones for consistent testing
810
if [[ "$OSTYPE" == "darwin"* ]]; then
9-
path_prefix="/Users/runner/work/codacy-cli-v2/codacy-cli-v2/"
11+
# Replace absolute paths with relative paths in URI contexts
12+
sed -i '' "s#file://${repo_root}/plugins/tools/#file:///plugins/tools/#g" "$file"
13+
sed -i '' "s#${repo_root}/plugins/tools/#/plugins/tools/#g" "$file"
14+
# Handle CI runner paths for macOS
15+
sed -i '' "s#file:///Users/runner/work/codacy-cli-v2/codacy-cli-v2/plugins/tools/#file:///plugins/tools/#g" "$file"
16+
sed -i '' "s#/Users/runner/work/codacy-cli-v2/codacy-cli-v2/plugins/tools/#/plugins/tools/#g" "$file"
1017
else
11-
path_prefix="/home/runner/work/codacy-cli-v2/codacy-cli-v2/"
12-
fi
13-
14-
if [[ "$OSTYPE" == "darwin"* ]]; then
15-
sed -i '' "s|file://${path_prefix}|file:///|g" "$file"
16-
sed -i '' "s|${path_prefix}|/|g" "$file"
17-
else
18-
sed -i "s|file://${path_prefix}|file:///|g" "$file"
19-
sed -i "s|${path_prefix}|/|g" "$file"
18+
# Replace absolute paths with relative paths in URI contexts
19+
sed -i "s#file://${repo_root}/plugins/tools/#file:///plugins/tools/#g" "$file"
20+
sed -i "s#${repo_root}/plugins/tools/#/plugins/tools/#g" "$file"
21+
# Handle CI runner paths for Linux
22+
sed -i "s#file:///home/runner/work/codacy-cli-v2/codacy-cli-v2/plugins/tools/#file:///plugins/tools/#g" "$file"
23+
sed -i "s#/home/runner/work/codacy-cli-v2/codacy-cli-v2/plugins/tools/#/plugins/tools/#g" "$file"
2024
fi
2125
}
2226

0 commit comments

Comments
 (0)