@@ -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 ==="
89Write-Host " Script directory: $SCRIPT_DIR "
910Write-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
1217if (-not $env: CODACY_API_TOKEN ) {
@@ -17,6 +22,7 @@ if (-not $env:CODACY_API_TOKEN) {
1722function 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,16 +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 " `n Expected directory contents:"
104+ Get-ChildItem - Path $expectedDir - Recurse | ForEach-Object {
105+ Write-Host " $ ( $_.FullName.Replace ($expectedDir , ' ' )) "
106+ }
107+
108+ Write-Host " `n Actual 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
116+ Write-Host " `n Checking file: $ ( $_.Name ) "
117+ Write-Host " Expected file: $ ( $_.FullName ) "
118+ Write-Host " Actual file: $actualFile "
119+
85120 if (-not (Test-Path $actualFile )) {
86121 Write-Host " ❌ $label /$ ( $_.Name ) does not exist in actual output"
87122 Write-Host " Expected: $ ( $_.FullName ) "
88123 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+ }
89128 exit 1
90129 }
91130
131+ Write-Host " Comparing file contents..."
92132 $expectedContent = Normalize- Config $_.FullName
93133 $actualContent = Normalize- Config $actualFile
94134
@@ -111,15 +151,24 @@ function Compare-Files {
111151 # Compare subdirectories
112152 Get-ChildItem - Path $expectedDir - Directory | Where-Object { $_.Name -ne " logs" } | ForEach-Object {
113153 $actualSubDir = Join-Path $actualDir $_.Name
154+ Write-Host " `n Checking subdirectory: $ ( $_.Name ) "
155+ Write-Host " Expected dir: $ ( $_.FullName ) "
156+ Write-Host " Actual dir: $actualSubDir "
114157
115158 if (-not (Test-Path $actualSubDir )) {
116159 Write-Host " ❌ Directory $label /$ ( $_.Name ) does not exist in actual output"
117160 Write-Host " Expected: $ ( $_.FullName ) "
118161 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+ }
119166 exit 1
120167 }
121168 Compare-Files $_.FullName $actualSubDir " $label /$ ( $_.Name ) "
122169 }
170+
171+ Write-Host " `n === Directory Comparison Complete ==="
123172}
124173
125174function Run-InitTest {
@@ -129,41 +178,64 @@ function Run-InitTest {
129178 [bool ]$useToken
130179 )
131180
132- 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+
133185 if (-not (Test-Path $testDir )) {
134186 Write-Host " ❌ Test directory does not exist: $testDir "
135187 exit 1
136188 }
137189
138190 $originalLocation = Get-Location
139191 try {
192+ Write-Host " Changing to test directory: $testDir "
140193 Set-Location $testDir
141- 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+ }
142200
143201 if ($useToken ) {
144202 if (-not $env: CODACY_API_TOKEN ) {
145203 Write-Host " ❌ Skipping token-based test: CODACY_API_TOKEN not set"
146204 return
147205 }
206+ Write-Host " Running CLI with token..."
148207 & $CLI_PATH init -- api- token $env: CODACY_API_TOKEN -- organization troubleshoot- codacy- dev -- provider gh -- repository codacy- cli- test
149208 } else {
209+ Write-Host " Running CLI without token..."
150210 & $CLI_PATH init
151211 }
152212
213+ Write-Host " `n Verifying directory structure after CLI execution:"
214+ Get-ChildItem - Recurse | ForEach-Object {
215+ Write-Host " $ ( $_.FullName ) "
216+ }
217+
153218 Compare-Files " expected" " .codacy" " Test $testName "
154219 Write-Host " ✅ Test $testName completed successfully"
155220 Write-Host " ----------------------------------------"
156221 }
222+ catch {
223+ Write-Host " ❌ Error during test execution:"
224+ Write-Host $_.Exception.Message
225+ Write-Host $_.ScriptStackTrace
226+ exit 1
227+ }
157228 finally {
229+ Write-Host " Returning to original location: $originalLocation "
158230 Set-Location $originalLocation
159231 }
160232}
161233
162234# Run tests
163- Write-Host " Starting integration tests... "
235+ Write-Host " `n === Starting Integration Tests === "
164236Write-Host " ----------------------------------------"
165237
166238Run- InitTest (Join-Path $SCRIPT_DIR " init-without-token" ) " init-without-token" $false
167239Run- InitTest (Join-Path $SCRIPT_DIR " init-with-token" ) " init-with-token" $true
168240
169- Write-Host " All tests completed successfully! 🎉"
241+ Write-Host " `n All tests completed successfully! 🎉"
0 commit comments