Skip to content

Commit 4fe9c77

Browse files
Enhance integration test script with detailed logging
- Added environment information output including OS and PowerShell version. - Improved directory comparison logging to show normalized paths and contents. - Enhanced error handling with detailed messages during test execution. - Updated test execution logging for better clarity on test progress. These changes improve the visibility and traceability of the integration tests, making it easier to diagnose issues and understand the test flow.
1 parent e263772 commit 4fe9c77

1 file changed

Lines changed: 75 additions & 5 deletions

File tree

integration-tests/run.ps1

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ $ErrorActionPreference = "Stop"
55
$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
66
$CLI_PATH = Join-Path (Get-Location) "cli-v2.exe"
77

8+
Write-Host "=== Environment Information ==="
89
Write-Host "Script directory: $SCRIPT_DIR"
910
Write-Host "Current working directory: $(Get-Location)"
11+
Write-Host "CLI Path: $CLI_PATH"
12+
Write-Host "OS: $([System.Environment]::OSVersion.Platform)"
13+
Write-Host "PowerShell Version: $($PSVersionTable.PSVersion)"
14+
Write-Host "==============================`n"
1015

1116
# Check if API token is provided for token-based test
1217
if (-not $env:CODACY_API_TOKEN) {
@@ -17,6 +22,7 @@ if (-not $env:CODACY_API_TOKEN) {
1722
function Normalize-Config {
1823
param ([string]$file)
1924

25+
Write-Host "Normalizing config file: $file"
2026
$ext = [System.IO.Path]::GetExtension($file).TrimStart('.')
2127

2228
switch ($ext) {
@@ -79,18 +85,50 @@ function Compare-Files {
7985
[string]$label
8086
)
8187

88+
Write-Host "`n=== Starting Directory Comparison ==="
89+
Write-Host "Comparing directories:"
90+
Write-Host "Expected dir: $expectedDir"
91+
Write-Host "Actual dir: $actualDir"
92+
Write-Host "Label: $label"
93+
94+
# Normalize paths to use the current OS's path separator
95+
$expectedDir = $expectedDir.Replace('/', [System.IO.Path]::DirectorySeparatorChar).Replace('\', [System.IO.Path]::DirectorySeparatorChar)
96+
$actualDir = $actualDir.Replace('/', [System.IO.Path]::DirectorySeparatorChar).Replace('\', [System.IO.Path]::DirectorySeparatorChar)
97+
98+
Write-Host "Normalized paths:"
99+
Write-Host "Expected dir (normalized): $expectedDir"
100+
Write-Host "Actual dir (normalized): $actualDir"
101+
102+
# List directory contents before comparison
103+
Write-Host "`nExpected directory contents:"
104+
Get-ChildItem -Path $expectedDir -Recurse | ForEach-Object {
105+
Write-Host " $($_.FullName.Replace($expectedDir, ''))"
106+
}
107+
108+
Write-Host "`nActual directory contents:"
109+
Get-ChildItem -Path $actualDir -Recurse | ForEach-Object {
110+
Write-Host " $($_.FullName.Replace($actualDir, ''))"
111+
}
112+
82113
# Compare files
83114
Get-ChildItem -Path $expectedDir -File | ForEach-Object {
84115
$actualFile = Join-Path $actualDir $_.Name
85-
116+
Write-Host "`nChecking file: $($_.Name)"
117+
Write-Host "Expected file: $($_.FullName)"
118+
Write-Host "Actual file: $actualFile"
86119

87120
if (-not (Test-Path $actualFile)) {
88121
Write-Host "$label/$($_.Name) does not exist in actual output"
89122
Write-Host "Expected: $($_.FullName)"
90123
Write-Host "Actual should be: $actualFile"
124+
Write-Host "Current directory structure:"
125+
Get-ChildItem -Path $actualDir -Recurse | ForEach-Object {
126+
Write-Host " $($_.FullName)"
127+
}
91128
exit 1
92129
}
93130

131+
Write-Host "Comparing file contents..."
94132
$expectedContent = Normalize-Config $_.FullName
95133
$actualContent = Normalize-Config $actualFile
96134

@@ -113,15 +151,24 @@ function Compare-Files {
113151
# Compare subdirectories
114152
Get-ChildItem -Path $expectedDir -Directory | Where-Object { $_.Name -ne "logs" } | ForEach-Object {
115153
$actualSubDir = Join-Path $actualDir $_.Name
154+
Write-Host "`nChecking subdirectory: $($_.Name)"
155+
Write-Host "Expected dir: $($_.FullName)"
156+
Write-Host "Actual dir: $actualSubDir"
116157

117158
if (-not (Test-Path $actualSubDir)) {
118159
Write-Host "❌ Directory $label/$($_.Name) does not exist in actual output"
119160
Write-Host "Expected: $($_.FullName)"
120161
Write-Host "Actual should be: $actualSubDir"
162+
Write-Host "Current directory structure:"
163+
Get-ChildItem -Path $actualDir -Recurse | ForEach-Object {
164+
Write-Host " $($_.FullName)"
165+
}
121166
exit 1
122167
}
123168
Compare-Files $_.FullName $actualSubDir "$label/$($_.Name)"
124169
}
170+
171+
Write-Host "`n=== Directory Comparison Complete ==="
125172
}
126173

127174
function Run-InitTest {
@@ -131,41 +178,64 @@ function Run-InitTest {
131178
[bool]$useToken
132179
)
133180

134-
Write-Host "Running test: $testName"
181+
Write-Host "`n=== Running Test: $testName ==="
182+
Write-Host "Test directory: $testDir"
183+
Write-Host "Using token: $useToken"
184+
135185
if (-not (Test-Path $testDir)) {
136186
Write-Host "❌ Test directory does not exist: $testDir"
137187
exit 1
138188
}
139189

140190
$originalLocation = Get-Location
141191
try {
192+
Write-Host "Changing to test directory: $testDir"
142193
Set-Location $testDir
143-
if (Test-Path ".codacy") { Remove-Item -Recurse -Force ".codacy" }
194+
Write-Host "Current location: $(Get-Location)"
195+
196+
if (Test-Path ".codacy") {
197+
Write-Host "Removing existing .codacy directory"
198+
Remove-Item -Recurse -Force ".codacy"
199+
}
144200

145201
if ($useToken) {
146202
if (-not $env:CODACY_API_TOKEN) {
147203
Write-Host "❌ Skipping token-based test: CODACY_API_TOKEN not set"
148204
return
149205
}
206+
Write-Host "Running CLI with token..."
150207
& $CLI_PATH init --api-token $env:CODACY_API_TOKEN --organization troubleshoot-codacy-dev --provider gh --repository codacy-cli-test
151208
} else {
209+
Write-Host "Running CLI without token..."
152210
& $CLI_PATH init
153211
}
154212

213+
Write-Host "`nVerifying directory structure after CLI execution:"
214+
Get-ChildItem -Recurse | ForEach-Object {
215+
Write-Host " $($_.FullName)"
216+
}
217+
155218
Compare-Files "expected" ".codacy" "Test $testName"
156219
Write-Host "✅ Test $testName completed successfully"
157220
Write-Host "----------------------------------------"
158221
}
222+
catch {
223+
Write-Host "❌ Error during test execution:"
224+
Write-Host $_.Exception.Message
225+
Write-Host $_.ScriptStackTrace
226+
exit 1
227+
}
159228
finally {
229+
Write-Host "Returning to original location: $originalLocation"
160230
Set-Location $originalLocation
161231
}
162232
}
163233

164234
# Run tests
165-
Write-Host "Starting integration tests..."
235+
Write-Host "`n=== Starting Integration Tests ==="
166236
Write-Host "----------------------------------------"
167237

168238
Run-InitTest (Join-Path $SCRIPT_DIR "init-without-token") "init-without-token" $false
169239
Run-InitTest (Join-Path $SCRIPT_DIR "init-with-token") "init-with-token" $true
170240

171-
Write-Host "All tests completed successfully! 🎉"
241+
Write-Host "`nAll tests completed successfully! 🎉"

0 commit comments

Comments
 (0)