Skip to content

Commit 34e4749

Browse files
committed
learned a thing or two about powershell return values :)
1 parent 2d38ace commit 34e4749

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed

scripts/matrix_testing/CreateMatrixTestReport.ps1

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,11 @@ $jobRows = $queriesToCheck | ForEach-Object -ThrottleLimit $NumThreads -Parallel
322322
###########################################################
323323
# Push context
324324
###########################################################
325-
$context = Push-CompilerSpecificFiles -Configuration $using:Configuration -Language $using:Language -FileSet (Get-CompilerSpecificFiles -TestDirectory $testDirectory)
325+
$fileSet = (Get-CompilerSpecificFiles -Configuration $using:Configuration -Language $using:Language -TestDirectory $testDirectory)
326+
327+
if($fileSet){
328+
$context = Push-CompilerSpecificFiles -Configuration $using:Configuration -Language $using:Language -FileSet $fileSet
329+
}
326330

327331
Write-Host "Compiling database in $testDirectory..." -NoNewline
328332

@@ -400,16 +404,15 @@ $jobRows = $queriesToCheck | ForEach-Object -ThrottleLimit $NumThreads -Parallel
400404
}
401405

402406
return $row
403-
}catch {
404-
Write-Host "Unknown error processing rule."
405-
return $row
406407
}finally {
407408

408409
###########################################################
409410
###########################################################
410411
# Context is restored here
411412
###########################################################
412-
Pop-CompilerSpecificFiles -Context $context
413+
if($context){
414+
Pop-CompilerSpecificFiles -Context $context
415+
}
413416
}
414417
}
415418

scripts/matrix_testing/Get-CompilerSpecificFiles.ps1

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ function Get-CompilerSpecificFiles {
66
[Parameter(Mandatory)]
77
[ValidateSet('c', 'cpp')]
88
[string]
9+
$Language,
10+
[Parameter(Mandatory)]
11+
[string]
912
$TestDirectory
10-
)
11-
13+
)
1214
#
1315
# Convention is as follows:
1416
#
@@ -19,9 +21,16 @@ function Get-CompilerSpecificFiles {
1921
#
2022
# file.expected is used for all compilers
2123
# file.expected.<configuration> is used for <configuration>
22-
$sourceFiles = Get-ChildItem -Filter "*.$Language.$Configuration"
24+
Write-Host "Scanning for compiler specific files in $TestDirectory"
25+
26+
foreach($f in (Get-ChildItem -Filter "*.$Language.$Configuration" $TestDirectory)){
27+
Write-Host "Found file $f..."
28+
$f
29+
}
2330

24-
$expectedFiles = Get-ChildItem -Filter "*.expected.$Configuration"
31+
foreach($f in (Get-ChildItem -Filter "*.expected.$Configuration" $TestDirectory)){
32+
Write-Host "Found file $f..."
33+
$f
34+
}
2535

26-
return $sourceFiles + $expectedFiles
2736
}

scripts/matrix_testing/NewDatabaseForRule.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function New-Database-For-Rule {
2121

2222
Write-Host "Creating Database for Rule $RuleName..."
2323

24-
$cppFiles = Get-ChildItem $RuleTestDir/*.c*
24+
$cppFiles = Get-ChildItem $RuleTestDir/*.$Language
2525
$cppFilesString = ([String]::Join(' ', $cppFiles))
2626
Write-Host "Found '.cpp' files $cppFilesString."
2727

scripts/matrix_testing/Pop-CompilerSpecificFiles.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ function Pop-CompilerSpecificFiles {
99
$origin = $context.origin
1010
$temp = $context.temp
1111

12-
if(-Not $temp -eq $null){
12+
if($temp){
1313
Write-Host "Restoring $temp -> $origin"
14-
Move-Item -Force -Path $temp $origin
14+
Copy-Item -Force -Path $temp -Destination $origin
1515
}else {
1616
# otherwise we just need to delete the origin
1717
Write-Host "Removing unneeded context item $origin"
18-
Remove-Item -Force $origin
18+
Remove-Item -Force $origin
1919
}
2020
}
2121

scripts/matrix_testing/Push-CompilerSpecificFiles.ps1

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ function Push-CompilerSpecificFiles {
1010
$Language
1111
)
1212

13-
$context = @()
14-
15-
1613
# for each file, move it to a temporary ___location
1714
foreach($f in $FileSet){
18-
1915
#
2016
# Convention is as follows:
2117
#
@@ -35,27 +31,30 @@ function Push-CompilerSpecificFiles {
3531
# file afterwards.
3632

3733
# transform the compiler specific file to the generic one
38-
$originFile = Get-Item $f.FullName.Replace(".$Configuration", "")
34+
$originFilePath = $f.FullName.Replace(".$Configuration", "")
3935

4036
# IF it exists, copy the originFile to a temp ___location and replace it
4137
# with the specific file.
42-
if($originFile.Exists){
38+
if(Test-Path $originFilePath){
39+
40+
$originFile = Get-Item $originFilePath
41+
4342
Write-Host "Moving generic file $originFile to $tmp..."
4443
Move-Item -Force -Path $originFile -Destination $tmp
4544
Write-Host "Copying $f to generic file $originFile"
46-
Copy-Item -Path $f -Destination $originFile
45+
Copy-Item -Path $f -Destination $originFile
4746

48-
$context += @{"origin"=$originFile; "temp"=$tmp;}
47+
@{"origin"=$originFile; "temp"=$tmp;}
4948
}else{
49+
50+
$originFile = New-Item $originFilePath
51+
5052
Write-Host "Copying $f to generic file $originFile"
51-
Copy-Item -Path $f -Destination $originFile
53+
Copy-Item -Path $f -Destination $originFile
5254

53-
# we set $temp to $null since we don't want to copy anything
55+
#we set $temp to $null since we don't want to copy anything
5456
# back
55-
$context += @{"origin"=$originFile; "temp"=$null;}
57+
@{"origin"=$originFile; "temp"=$null;}
5658
}
5759
}
58-
59-
return $context
60-
6160
}

0 commit comments

Comments
 (0)