Skip to content

Commit 24cb209

Browse files
committed
simplify
1 parent f845936 commit 24cb209

1 file changed

Lines changed: 16 additions & 51 deletions

File tree

integration-tests/run.ps1

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Stop on first error
22
$ErrorActionPreference = "Stop"
33

4-
# Get the absolute path of the script's directory
4+
# Get the absolute path of the script's directory and CLI path
55
$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
66
$CLI_PATH = Join-Path (Get-Location) "cli-v2.exe"
77

@@ -15,34 +15,22 @@ if (-not $env:CODACY_API_TOKEN) {
1515

1616
# Function to normalize and sort configuration values
1717
function Normalize-Config {
18-
param (
19-
[string]$file
20-
)
18+
param ([string]$file)
2119

2220
$ext = [System.IO.Path]::GetExtension($file).TrimStart('.')
2321

2422
switch ($ext) {
25-
{ $_ -in @('yaml', 'yml') } {
26-
# For YAML files, use yq to sort
27-
# Note: Requires yq to be installed on Windows
28-
yq e '.' $file | Sort-Object
29-
}
23+
{ $_ -in @('yaml', 'yml') } { yq e '.' $file | Sort-Object }
3024
{ $_ -in @('rc', 'conf', 'ini', 'xml') } {
31-
# For other config files, sort values after '=' and keep other lines
3225
Get-Content $file | ForEach-Object {
3326
if ($_ -match '^[^#].*=.*,') {
3427
$parts = $_ -split '='
3528
$values = $parts[1] -split ',' | Sort-Object
3629
"$($parts[0])=$($values -join ',')"
37-
} else {
38-
$_
39-
}
30+
} else { $_ }
4031
} | Sort-Object
4132
}
42-
default {
43-
# For other files, just sort
44-
Get-Content $file | Sort-Object
45-
}
33+
default { Get-Content $file | Sort-Object }
4634
}
4735
}
4836

@@ -53,13 +41,11 @@ function Compare-Files {
5341
[string]$label
5442
)
5543

56-
# Compare files in current directory
44+
# Compare files
5745
Get-ChildItem -Path $expectedDir -File | ForEach-Object {
58-
$filename = $_.Name
59-
$actualFile = Join-Path $actualDir $filename
60-
46+
$actualFile = Join-Path $actualDir $_.Name
6147
if (-not (Test-Path $actualFile)) {
62-
Write-Host "$label/$filename does not exist in actual output"
48+
Write-Host "$label/$($_.Name) does not exist in actual output"
6349
Write-Host "Expected: $($_.FullName)"
6450
Write-Host "Actual should be: $actualFile"
6551
exit 1
@@ -69,7 +55,7 @@ function Compare-Files {
6955
$actualContent = Normalize-Config $actualFile
7056

7157
if (Compare-Object $expectedContent $actualContent) {
72-
Write-Host "$label/$filename does not match expected"
58+
Write-Host "$label/$($_.Name) does not match expected"
7359
Write-Host "=== Expected (normalized) ==="
7460
$expectedContent
7561
Write-Host "=== Actual (normalized) ==="
@@ -78,30 +64,21 @@ function Compare-Files {
7864
Compare-Object $expectedContent $actualContent
7965
Write-Host "==================="
8066
exit 1
81-
} else {
82-
Write-Host "$label/$filename matches expected"
8367
}
68+
Write-Host "$label/$($_.Name) matches expected"
8469
}
8570

8671
# Compare subdirectories
87-
Get-ChildItem -Path $expectedDir -Directory | ForEach-Object {
88-
$dirname = $_.Name
89-
if ($dirname -eq "logs") { return }
90-
91-
# Handle .codacy directory specially
92-
if ($dirname -eq ".codacy") {
93-
$actualSubDir = $actualDir
94-
} else {
95-
$actualSubDir = Join-Path $actualDir $dirname
96-
}
72+
Get-ChildItem -Path $expectedDir -Directory | Where-Object { $_.Name -ne "logs" } | ForEach-Object {
73+
$actualSubDir = if ($_.Name -eq ".codacy") { $actualDir } else { Join-Path $actualDir $_.Name }
9774

9875
if (-not (Test-Path $actualSubDir)) {
99-
Write-Host "❌ Directory $label/$dirname does not exist in actual output"
76+
Write-Host "❌ Directory $label/$($_.Name) does not exist in actual output"
10077
Write-Host "Expected: $($_.FullName)"
10178
Write-Host "Actual should be: $actualSubDir"
10279
exit 1
10380
}
104-
Compare-Files $_.FullName $actualSubDir "$label/$dirname"
81+
Compare-Files $_.FullName $actualSubDir "$label/$($_.Name)"
10582
}
10683
}
10784

@@ -118,17 +95,10 @@ function Run-InitTest {
11895
exit 1
11996
}
12097

121-
# Store the original location
12298
$originalLocation = Get-Location
123-
12499
try {
125-
# Change to the test directory
126100
Set-Location $testDir
127-
128-
# Remove existing .codacy directory if it exists
129-
if (Test-Path ".codacy") {
130-
Remove-Item -Recurse -Force ".codacy"
131-
}
101+
if (Test-Path ".codacy") { Remove-Item -Recurse -Force ".codacy" }
132102

133103
if ($useToken) {
134104
if (-not $env:CODACY_API_TOKEN) {
@@ -140,25 +110,20 @@ function Run-InitTest {
140110
& $CLI_PATH init
141111
}
142112

143-
# Compare files using relative paths
144113
Compare-Files "expected" ".codacy" "Test $testName"
145114
Write-Host "✅ Test $testName completed successfully"
146115
Write-Host "----------------------------------------"
147116
}
148117
finally {
149-
# Always return to the original location
150118
Set-Location $originalLocation
151119
}
152120
}
153121

154-
# Run both tests
122+
# Run tests
155123
Write-Host "Starting integration tests..."
156124
Write-Host "----------------------------------------"
157125

158-
# Test 1: Init without token
159126
Run-InitTest (Join-Path $SCRIPT_DIR "init-without-token") "init-without-token" $false
160-
161-
# Test 2: Init with token
162127
Run-InitTest (Join-Path $SCRIPT_DIR "init-with-token") "init-with-token" $true
163128

164129
Write-Host "All tests completed successfully! 🎉"

0 commit comments

Comments
 (0)