Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit a00c99d

Browse files
committed
Style changes
1 parent 5410716 commit a00c99d

15 files changed

+228
-265
lines changed
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
Describe -Name "Simple Validation of PSGallery" {
2-
It "The PowerShell Gallery should be responsive" {
3-
$request = [System.Net.WebRequest]::Create("http://psget/psgallery")
4-
$response = $Request.GetResponse()
5-
$response.StatusCode | Should be OK
1+
Describe -Name 'Simple Validation of PSGallery' {
2+
It 'The PowerShell Gallery should be responsive' {
3+
$response = Invoke-WebRequest -Uri 'https://www.powershellgallery.com'
4+
$response.StatusCode | Should be 200
65
}
76
}
8-

OperationValidation/OperationValidation.psd1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ RequiredModules = @('Pester')
6161
# TypesToProcess = @()
6262

6363
# Format files (.ps1xml) to be loaded when importing this module
64-
FormatsToProcess = @("OperationValidation.Format.ps1xml")
64+
FormatsToProcess = @('OperationValidation.Format.ps1xml')
6565

6666
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
6767
# NestedModules = @()
6868

6969
# Functions to export from this module
70-
FunctionsToExport = @('Get-OperationValidation','Invoke-OperationValidation')
70+
FunctionsToExport = @(
71+
'Get-OperationValidation'
72+
'Invoke-OperationValidation'
73+
)
7174

7275
# Cmdlets to export from this module
7376
# CmdletsToExport = '*'
@@ -92,11 +95,16 @@ FileList = @(
9295
'Diagnostics\Comprehensive\PSGallery.Comprehensive.Tests.ps1'
9396
'Diagnostics\Simple\PSGallery.Simple.Tests.ps1'
9497
'Private\Convert-TestResult.ps1'
98+
'Private\Get-ModuleList.ps1'
99+
'Private\Get-TestCaseNamesFromAst.ps1'
100+
'Private\Get-TestFromAst.ps1'
95101
'Private\Get-TestFromScript.ps1'
102+
'Private\Get-TestName.ps1'
96103
'Private\New-OperationValidationFailure.ps1'
97104
'Private\New-OperationValidationInfo.ps1'
98105
'Private\New-OperationValidationInfo.ps1'
99106
'Private\New-OperationValidationResult.ps1'
107+
'Private\Parse-Psd1.ps1'
100108
'Public\Get-OperationValidation.ps1'
101109
'Public\Invoke-OperationValidation.ps1'
102110
)

OperationValidation/OperationValidation.psm1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
$script:pathSeparator = [IO.Path]::PathSeparator
33

44
# Dot source public/private functions
5-
$public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse -ErrorAction SilentlyContinue )
5+
$public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse -ErrorAction SilentlyContinue )
66
$private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -Recurse -ErrorAction SilentlyContinue )
77
foreach($import in @($public + $private)) {
8-
. $import.fullname
8+
try {
9+
. $import.FullName
10+
} catch {
11+
throw "Unable to dot source [$($import.FullName)]"
12+
}
913
}
1014

1115
Export-ModuleMember -Function $public.Basename

OperationValidation/Private/Convert-TestResult.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Emit an object which can be used in reporting
33
Function Convert-TestResult {
44
param (
5-
[Parameter(Mandatory = $true)]
5+
[Parameter(Mandatory)]
66
$result,
77

88
[string]$ModuleName
@@ -18,14 +18,14 @@ Function Convert-TestResult {
1818
$TestName = '{0}:{1}:{2}' -f $testResult.Describe, $testResult.Context, $testResult.Name
1919

2020
$newOVResultParams = @{
21-
Name = $TestName
22-
FileName = $result.path
23-
Result = $testresult.result
21+
Name = $TestName
22+
FileName = $result.path
23+
Result = $testresult.result
2424
RawResult = $testResult
25-
Error = $TestError
25+
Error = $TestError
2626
}
2727
if (-not [string]::IsNullOrEmpty($ModuleName)) {
28-
$newOVResultParams['Module'] = $ModuleName
28+
$newOVResultParams.Module = $ModuleName
2929
}
3030
New-OperationValidationResult @newOVResultParams
3131
}

OperationValidation/Private/Get-ModuleList.ps1

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,62 @@
11
function Get-ModuleList {
22
[cmdletbinding(DefaultParameterSetName = 'Name')]
33
param (
4-
[Parameter(Mandatory = $true, ParameterSetName = 'Name')]
4+
[Parameter(
5+
Mandatory,
6+
ParameterSetName = 'Name'
7+
)]
58
[string[]]$Name,
69

7-
[Parameter(Mandatory = $true, ParameterSetName = 'Path')]
10+
[Parameter(
11+
Mandatory,
12+
ParameterSetName = 'Path'
13+
)]
814
[string[]]$Path,
915

1016
[version]$Version
1117
)
1218

13-
if ($PSCmdlet.ParameterSetName -eq 'Name')
14-
{
19+
if ($PSCmdlet.ParameterSetName -eq 'Name') {
1520
$pathsToSearch = $env:PSModulePath.Trim($script:pathSeparator).Split($script:pathSeparator)
16-
}
17-
elseIf ($PSCmdlet.ParameterSetName -eq 'Path')
18-
{
21+
} elseIf ($PSCmdlet.ParameterSetName -eq 'Path') {
1922
$pathsToSearch = $Path
2023
}
2124

22-
foreach($p in $pathsToSearch)
23-
{
24-
if ( Test-Path -Path $p )
25-
{
26-
foreach($modDir in Get-ChildItem -Path $p -Directory)
27-
{
25+
foreach($p in $pathsToSearch) {
26+
if (Test-Path -Path $p) {
27+
foreach($modDir in Get-ChildItem -Path $p -Directory) {
2828
Write-Debug "Checking for OVF in [$modDir]"
2929

30-
if ($PSCmdlet.ParameterSetName -eq 'Path')
31-
{
30+
if ($PSCmdlet.ParameterSetName -eq 'Path') {
3231
$Name = $modDir.Name
3332
}
3433

35-
foreach ($n in $Name )
36-
{
37-
if ( $modDir.Name -like $n )
38-
{
34+
foreach ($n in $Name ) {
35+
if ( $modDir.Name -like $n ) {
3936
# now determine if there's a diagnostics directory, or a version
40-
if ( Test-Path -Path (Join-Path -Path $modDir.FullName -ChildPath 'Diagnostics'))
41-
{
37+
if ( Test-Path -Path (Join-Path -Path $modDir.FullName -ChildPath 'Diagnostics')) {
4238
# Did we specify a specific version to find?
43-
if ($PSBoundParameters.ContainsKey('Version'))
44-
{
39+
if ($PSBoundParameters.ContainsKey('Version')) {
4540
$manifestFile = Get-ChildItem -Path $modDir.FullName -Filter "$($modDir.Name).psd1" | Select-Object -First 1
46-
if ($manifestFile -and (Test-Path -Path $manifestFile.FullName))
47-
{
41+
if ($manifestFile -and (Test-Path -Path $manifestFile.FullName)) {
4842
Write-Verbose $manifestFile
4943
$manifest = Test-ModuleManifest -Path $manifestFile.FullName -Verbose:$false
50-
if ($manifest.Version -eq $Version)
51-
{
44+
if ($manifest.Version -eq $Version) {
5245
$modDir.FullName
5346
break
5447
}
5548
}
56-
}
57-
else
58-
{
49+
} else {
5950
$modDir.FullName
6051
break
6152
}
6253
}
6354

6455
# Get latest version if no specific version specified
65-
if ($PSBoundParameters.ContainsKey('Version'))
66-
{
56+
if ($PSBoundParameters.ContainsKey('Version')) {
6757
$versionDirectories = Get-Childitem -Path $modDir.FullName -Directory |
6858
Where-Object { $_.name -as [version] -and $_.Name -eq $Version }
69-
}
70-
else
71-
{
59+
} else {
7260
$versionDirectories = Get-Childitem -Path $modDir.FullName -Directory |
7361
Where-Object { $_.name -as [version] }
7462
}
@@ -80,17 +68,14 @@ function Get-ModuleList {
8068
$DiagnosticDir = $potentialDiagnostics |
8169
Sort-Object {$_.name -as [version]} |
8270
Select-Object -Last 1
83-
if ( $DiagnosticDir )
84-
{
71+
if ( $DiagnosticDir ) {
8572
$DiagnosticDir.FullName
8673
break
8774
}
8875
}
8976
}
9077
}
91-
}
92-
else
93-
{
78+
} else {
9479
Write-Error -Message "Could not access [$p]. Does it exist?"
9580
}
9681
}

OperationValidation/Private/Get-TestCaseNamesFromAst.ps1

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ function Get-TestCaseNamesFromAst {
55
)
66

77
$eb = $ast.EndBlock
8-
foreach($statement in $eb.Statements)
9-
{
10-
if ( $statement -isnot "System.Management.Automation.Language.PipelineAst" )
11-
{
8+
foreach($statement in $eb.Statements) {
9+
if ($statement -isnot 'System.Management.Automation.Language.PipelineAst') {
1210
continue
1311
}
14-
$CommandAst = $statement.PipelineElements[0].CommandElements[0]
12+
$commandAst = $statement.PipelineElements[0].CommandElements[0]
1513

16-
if ( $CommandAst.Value -eq "It" )
17-
{
14+
if ($commandAst.Value -eq 'It') {
1815
Get-TestName $CommandAst
1916
}
2017
}

OperationValidation/Private/Get-TestFromAst.ps1

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@ function Get-TestFromAst {
55
)
66

77
$eb = $ast.EndBlock
8-
foreach($statement in $eb.Statements)
9-
{
10-
if ( $statement -isnot "System.Management.Automation.Language.PipelineAst" )
11-
{
8+
foreach($statement in $eb.Statements) {
9+
if ($statement -isnot 'System.Management.Automation.Language.PipelineAst') {
1210
continue
1311
}
14-
$CommandAst = $statement.PipelineElements[0].CommandElements[0]
12+
$commandAst = $statement.PipelineElements[0].CommandElements[0]
1513

16-
if ( $CommandAst.Value -eq "Describe" )
17-
{
18-
Get-TestName $CommandAst
14+
if ($commandAst.Value -eq 'Describe') {
15+
Get-TestName $commandAst
1916
}
2017
}
2118
}

OperationValidation/Private/Get-TestFromScript.ps1

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

2-
function Get-TestFromScript
3-
{
2+
function Get-TestFromScript {
43
param (
54
[parameter(Mandatory)]
65
[string]$ScriptPath
@@ -17,20 +16,16 @@ function Get-TestFromScript
1716
}, $true) |
1817
ForEach-Object {
1918
# This is the name of the 'describe' block
20-
for ($x = 0; $x -lt $_.CommandElements.Count; $x++)
21-
{
19+
for ($x = 0; $x -lt $_.CommandElements.Count; $x++) {
2220
# Name parameter is named
23-
if ($_.CommandElements[$x] -is [System.Management.Automation.Language.CommandParameterAst] -and $_.CommandElements[$x].ParameterName -eq 'Name')
24-
{
21+
if ($_.CommandElements[$x] -is [System.Management.Automation.Language.CommandParameterAst] -and $_.CommandElements[$x].ParameterName -eq 'Name') {
2522
$describeName = $_.CommandElements[$x + 1].value
26-
}
27-
# if we have a string without a parameter name, return first hit. Name parameter is at position 0.
28-
ElseIf (($_.CommandElements[$x] -is [System.Management.Automation.Language.StringConstantExpressionAst]) -and ($_.CommandElements[$x - 1] -is [System.Management.Automation.Language.StringConstantExpressionAst]))
29-
{
23+
} elseIf (($_.CommandElements[$x] -is [System.Management.Automation.Language.StringConstantExpressionAst]) -and ($_.CommandElements[$x - 1] -is [System.Management.Automation.Language.StringConstantExpressionAst])) {
24+
# if we have a string without a parameter name, return first hit. Name parameter is at position 0.
3025
$describeName = $_.CommandElements[$x].value
3126
}
3227
}
33-
$item = [PSCustomObject][ordered]@{
28+
$item = [pscustomobject][ordered]@{
3429
Name = $describeName
3530
Tags = @()
3631
}

OperationValidation/Private/Get-TestName.ps1

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ function Get-TestName {
44
$ast
55
)
66

7-
for($i = 1; $i -lt $ast.Parent.CommandElements.Count; $i++)
8-
{
9-
if ( $ast.Parent.CommandElements[$i] -is "System.Management.Automation.Language.CommandParameterAst") { $i++; continue }
10-
if ( $ast.Parent.CommandElements[$i] -is "System.Management.Automation.Language.ScriptBlockExpressionAst" ) { continue }
11-
if ( $ast.Parent.CommandElements[$i] -is "System.Management.Automation.Language.StringConstantExpressionAst" ) { return $ast.Parent.CommandElements[$i].Value }
7+
for($i = 1; $i -lt $ast.Parent.CommandElements.Count; $i++) {
8+
if ($ast.Parent.CommandElements[$i] -is 'System.Management.Automation.Language.CommandParameterAst') {
9+
$i++; continue
10+
}
11+
if ($ast.Parent.CommandElements[$i] -is 'System.Management.Automation.Language.ScriptBlockExpressionAst') {
12+
continue
13+
}
14+
if ($ast.Parent.CommandElements[$i] -is 'System.Management.Automation.Language.StringConstantExpressionAst') {
15+
return $ast.Parent.CommandElements[$i].Value
16+
}
1217
}
13-
throw "Could not determine test name"
18+
19+
throw 'Could not determine test name'
1420
}
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11

2-
function New-OperationValidationFailure
3-
{
2+
function New-OperationValidationFailure {
43
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='*')]
54
param (
6-
[Parameter(Mandatory=$true)][string]$StackTrace,
7-
[Parameter(Mandatory=$true)][string]$FailureMessage
5+
[Parameter(Mandatory)]
6+
[string]$StackTrace,
7+
8+
[Parameter(Mandatory)]
9+
[string]$FailureMessage
810
)
11+
912
$o = [pscustomobject]@{
10-
StackTrace = $StackTrace
13+
PSTypeName = 'OperationValidationFailure'
14+
StackTrace = $StackTrace
1115
FailureMessage = $FailureMessage
12-
}
13-
$o.psobject.Typenames.Insert(0,"OperationValidationFailure")
14-
$ToString = { return $this.StackTrace }
15-
Add-Member -inputobject $o -membertype ScriptMethod -Name ToString -Value $toString -Force
16+
}
17+
$toString = { return $this.StackTrace }
18+
Add-Member -Inputobject $o -MemberType ScriptMethod -Name ToString -Value $toString -Force
1619
$o
1720
}

0 commit comments

Comments
 (0)