Skip to content

Commit 7592a23

Browse files
committed
fix(#194): standardize formatting of try-catch-finally blocks across multiple scripts
1 parent 4fc419d commit 7592a23

27 files changed

Lines changed: 183 additions & 366 deletions

tests/BuildOptions.TestSupport.ps1

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ function Get-BuiltModuleFilePath {
8989
try {
9090
$info = Get-NovaProjectInfo
9191
return (Join-Path $ProjectRoot ("dist/{0}/{0}.psm1" -f $info.ProjectName))
92-
}
93-
finally {
92+
} finally {
9493
Pop-Location
9594
}
9695
}
@@ -110,8 +109,7 @@ function Invoke-TestProjectBuild {
110109
}
111110

112111
return $psm1
113-
}
114-
finally {
112+
} finally {
115113
Pop-Location
116114
}
117115
}
@@ -153,8 +151,7 @@ function Get-TestProjectInfoValue {
153151
Push-Location -LiteralPath $ProjectRoot
154152
try {
155153
return (Get-NovaProjectInfo).$PropertyName
156-
}
157-
finally {
154+
} finally {
158155
Pop-Location
159156
}
160157
}
@@ -226,17 +223,15 @@ function Assert-InvokeNovaBuildThrows {
226223
Push-Location -LiteralPath $ProjectRoot
227224
try {
228225
Invoke-NovaBuild
229-
}
230-
finally {
226+
} finally {
231227
Pop-Location
232228
}
233229
}
234230

235231
$thrown = $null
236232
try {
237233
& $invokeAction
238-
}
239-
catch {
234+
} catch {
240235
$thrown = $_
241236
}
242237

@@ -324,8 +319,7 @@ function Invoke-TestProjectTests {
324319
$scriptPath = Join-Path $ProjectRoot 'Run-TestNovaBuild.ps1'
325320
$testCommand = if ($BuildBeforeTest) {
326321
'Test-NovaBuild -Build'
327-
}
328-
else {
322+
} else {
329323
@(
330324
'Invoke-NovaBuild'
331325
'Test-NovaBuild'
@@ -345,8 +339,7 @@ $testCommand
345339
ExitCode = $LASTEXITCODE
346340
Output = @($output)
347341
}
348-
}
349-
finally {
342+
} finally {
350343
Remove-Item -LiteralPath $scriptPath -Force -ErrorAction SilentlyContinue
351344
}
352345
}

tests/BuildOptions.Tests.ps1

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ Describe 'Invoke-NovaBuild options' {
9595
$thrown = $null
9696
try {
9797
Get-ExampleConfiguration
98-
}
99-
catch {
98+
} catch {
10099
$thrown = $_
101100
}
102101

@@ -140,8 +139,7 @@ Describe 'Invoke-NovaBuild options' {
140139

141140
$LASTEXITCODE | Should -Be 0 -Because (@($output) -join [Environment]::NewLine)
142141
$report | Should -Match 'PSScriptAnalyzer: no findings\.'
143-
}
144-
finally {
142+
} finally {
145143
Remove-Item -LiteralPath (Join-Path $repoRoot 'src/resources/example/dist') -Recurse -Force -ErrorAction SilentlyContinue
146144
Remove-Item -LiteralPath $exampleArtifactsRoot -Recurse -Force -ErrorAction SilentlyContinue
147145
}
@@ -214,8 +212,7 @@ Describe 'Invoke-NovaBuild options' {
214212
Push-Location -LiteralPath $root
215213
try {
216214
(Get-NovaProjectInfo).SetSourcePath | Should -BeTrue
217-
}
218-
finally {
215+
} finally {
219216
Pop-Location
220217
}
221218

@@ -351,12 +348,10 @@ Describe 'Invoke-NovaBuild options' {
351348
Push-Location -LiteralPath $root
352349
try {
353350
Invoke-NovaBuild
354-
}
355-
finally {
351+
} finally {
356352
Pop-Location
357353
}
358-
}
359-
catch {
354+
} catch {
360355
$thrown = $_
361356
}
362357

tests/CiCoverage.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ Describe 'CodeScene Cobertura remapping helpers' {
143143
$thrown = $null
144144
try {
145145
Convert-CoberturaCoverageToSourcePath -CoveragePath $coveragePath -BuiltModulePath $builtModulePath -RepoRoot $repoRoot
146-
}
147-
catch {
146+
} catch {
148147
$thrown = $_
149148
}
150149

tests/CliHelperCoverage.Tests.ps1

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ Describe 'Targeted coverage for smaller CLI helper internals' {
4545
$directHelpUsageError = $null
4646
try {
4747
Assert-NovaCliHelpUsageSupported -Tokens @('--help', 'build')
48-
}
49-
catch {
48+
} catch {
5049
$directHelpUsageError = $_
5150
}
5251

@@ -60,8 +59,7 @@ Describe 'Targeted coverage for smaller CLI helper internals' {
6059
$rootHelpUsageError = $null
6160
try {
6261
Get-NovaCliHelpRequest -Command '--help' -Arguments @('--help')
63-
}
64-
catch {
62+
} catch {
6563
$rootHelpUsageError = $_
6664
}
6765

@@ -75,8 +73,7 @@ Describe 'Targeted coverage for smaller CLI helper internals' {
7573
$subcommandHelpUsageError = $null
7674
try {
7775
Get-NovaCliHelpRequest -Command 'build' -Arguments @('--help', 'extra')
78-
}
79-
catch {
76+
} catch {
8077
$subcommandHelpUsageError = $_
8178
}
8279

@@ -99,8 +96,7 @@ Describe 'Targeted coverage for smaller CLI helper internals' {
9996
$result.Verbose | Should -BeTrue
10097
$result.WhatIf | Should -BeTrue
10198
$result.Confirm | Should -BeFalse
102-
}
103-
finally {
99+
} finally {
104100
$WhatIfPreference = $previousWhatIfPreference
105101
}
106102
}

tests/CliSharedParser.Tests.ps1

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,21 @@ Describe 'CLI shared parser helpers' {
7373
$usageError = $null
7474
try {
7575
Get-NovaCliModeArgumentValue -Arguments @('--enable', '--disable') -Definition $notificationDefinition
76-
}
77-
catch {
76+
} catch {
7877
$usageError = $_
7978
}
8079

8180
$unknownArgumentError = $null
8281
try {
8382
Get-NovaCliModeArgumentValue -Arguments @('--bogus') -Definition $notificationDefinition
84-
}
85-
catch {
83+
} catch {
8684
$unknownArgumentError = $_
8785
}
8886

8987
$updateUsageError = $null
9088
try {
9189
Get-NovaCliModeArgumentValue -Arguments @('--bogus') -Definition $updateDefinition
92-
}
93-
catch {
90+
} catch {
9491
$updateUsageError = $_
9592
}
9693

tests/CoverageCompletion.Tests.ps1

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ Describe 'Coverage completion for remaining low-coverage helpers' {
6666
if ($IsWindows) {
6767
$pattern | Should -Be '\\Documents\\PowerShell\\Modules'
6868
$message | Should -Be "No windows module path matching $pattern found"
69-
}
70-
else {
69+
} else {
7170
$pattern | Should -Be '/\.local/share/powershell/Modules$'
7271
$message | Should -Be "No macOS/Linux module path matching $pattern found in PSModulePath."
7372
}
@@ -89,13 +88,11 @@ Describe 'Coverage completion for remaining low-coverage helpers' {
8988
if ($TargetIsWindows) {
9089
$pattern | Should -Be ([regex]::Escape('\Documents\PowerShell\Modules'))
9190
$message | Should -Be "No windows module path matching $pattern found"
92-
}
93-
else {
91+
} else {
9492
$pattern | Should -Be '/\.local/share/powershell/Modules$'
9593
$message | Should -Be "No macOS/Linux module path matching $pattern found in PSModulePath."
9694
}
97-
}
98-
finally {
95+
} finally {
9996
Remove-Variable -Name IsWindows -Force -ErrorAction SilentlyContinue
10097
}
10198
}
@@ -210,8 +207,7 @@ Describe 'Coverage completion for remaining low-coverage helpers' {
210207
Assert-MockCalled Write-Message -Times 1 -ParameterFilter {
211208
$Text -eq $PromptCase.ExpectedValidationMessage -and $color -eq 'Yello'
212209
}
213-
}
214-
else {
210+
} else {
215211
Assert-MockCalled Write-Message -Times 0
216212
}
217213
}
@@ -225,8 +221,7 @@ Describe 'Coverage completion for remaining low-coverage helpers' {
225221

226222
if ($Default -eq 'MANDATORY') {
227223
$hostUi.State.FieldDescriptions[0].DefaultValue | Should -BeNullOrEmpty
228-
}
229-
else {
224+
} else {
230225
$hostUi.State.FieldDescriptions[0].DefaultValue | Should -Be $Default
231226
}
232227
}
@@ -370,8 +365,7 @@ Describe 'Coverage completion for remaining low-coverage helpers' {
370365
$thrown = $null
371366
try {
372367
Assert-BuiltModuleHasNoDuplicateFunctionName -ProjectInfo ([pscustomobject]@{ModuleFilePSM1 = '/tmp/missing.psm1'})
373-
}
374-
catch {
368+
} catch {
375369
$thrown = $_
376370
}
377371

@@ -396,8 +390,7 @@ Describe 'Coverage completion for remaining low-coverage helpers' {
396390
$thrown = $null
397391
try {
398392
Assert-BuiltModuleHasNoDuplicateFunctionName -ProjectInfo ([pscustomobject]@{ModuleFilePSM1 = '/tmp/bad.psm1'})
399-
}
400-
catch {
393+
} catch {
401394
$thrown = $_
402395
}
403396

@@ -427,8 +420,7 @@ Describe 'Coverage completion for remaining low-coverage helpers' {
427420
$thrown = $null
428421
try {
429422
Assert-BuiltModuleHasNoDuplicateFunctionName -ProjectInfo ([pscustomobject]@{ModuleFilePSM1 = '/tmp/empty.psm1'})
430-
}
431-
catch {
423+
} catch {
432424
$thrown = $_
433425
}
434426

tests/CoverageGaps.BuildInternals.Tests.ps1

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ Describe 'Coverage gaps for build and duplicate-analysis internals' {
125125
$thrown = $null
126126
try {
127127
Assert-NovaPublicFunctionFileLayout -ProjectInfo $projectInfo
128-
}
129-
catch {
128+
} catch {
130129
$thrown = $_
131130
}
132131

@@ -281,8 +280,7 @@ Describe 'Coverage gaps for build and duplicate-analysis internals' {
281280
$thrown = $null
282281
try {
283282
Build-Help
284-
}
285-
catch {
283+
} catch {
286284
$thrown = $_
287285
}
288286

@@ -344,8 +342,7 @@ Describe 'Coverage gaps for build and duplicate-analysis internals' {
344342

345343
try {
346344
Build-Help
347-
}
348-
finally {
345+
} finally {
349346
Remove-Item function:Import-MarkdownCommandHelp -ErrorAction SilentlyContinue
350347
Remove-Item function:Export-MamlCommandHelp -ErrorAction SilentlyContinue
351348
}
@@ -386,8 +383,7 @@ Describe 'Coverage gaps for build and duplicate-analysis internals' {
386383
{Build-Help} | Should -Not -Throw
387384
Assert-MockCalled Get-NovaHelpLocale -Times 0
388385
Assert-MockCalled Rename-Item -Times 0
389-
}
390-
finally {
386+
} finally {
391387
Remove-Item function:Import-MarkdownCommandHelp -ErrorAction SilentlyContinue
392388
Remove-Item function:Export-MamlCommandHelp -ErrorAction SilentlyContinue
393389
}
@@ -445,8 +441,7 @@ Describe 'Coverage gaps for build and duplicate-analysis internals' {
445441
$thrown = $null
446442
try {
447443
Build-Help
448-
}
449-
catch {
444+
} catch {
450445
$thrown = $_
451446
}
452447

@@ -455,8 +450,7 @@ Describe 'Coverage gaps for build and duplicate-analysis internals' {
455450
$thrown.CategoryInfo.Category | Should -Be ([System.Management.Automation.ErrorCategory]::ObjectNotFound)
456451
$thrown.TargetObject | Should -Be '/tmp/dist/NovaModuleTools'
457452
Assert-MockCalled Rename-Item -Times 0
458-
}
459-
finally {
453+
} finally {
460454
Remove-Item function:Import-MarkdownCommandHelp -ErrorAction SilentlyContinue
461455
Remove-Item function:Export-MamlCommandHelp -ErrorAction SilentlyContinue
462456
}
@@ -485,8 +479,7 @@ Describe 'Coverage gaps for build and duplicate-analysis internals' {
485479
$missingSourceError = $null
486480
try {
487481
Build-Module -ProjectInfo $projectInfo
488-
}
489-
catch {
482+
} catch {
490483
$missingSourceError = $_
491484
}
492485

@@ -502,8 +495,7 @@ Describe 'Coverage gaps for build and duplicate-analysis internals' {
502495
$psm1WriteError = $null
503496
try {
504497
Build-Module -ProjectInfo $projectInfo
505-
}
506-
catch {
498+
} catch {
507499
$psm1WriteError = $_
508500
}
509501

@@ -611,8 +603,7 @@ Describe 'Coverage gaps for build and duplicate-analysis internals' {
611603
ProjectName = 'NovaModuleTools'
612604
ManifestFilePSD1 = '/tmp/NovaModuleTools.psd1'
613605
})
614-
}
615-
catch {
606+
} catch {
616607
$thrown = $_
617608
}
618609

tests/CoverageGaps.Cli.OverrideWarning.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ Describe 'Coverage gaps for CLI override-warning parsing' {
5151
$thrown = $null
5252
try {
5353
ConvertFrom-NovaPackageCliArgument -Arguments @('--local')
54-
}
55-
catch {
54+
} catch {
5655
$thrown = $_
5756
}
5857

0 commit comments

Comments
 (0)