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

Commit 13a8c75

Browse files
committed
Merge branch 'feat/xplat-support'
2 parents 27a1f09 + 470bdc6 commit 13a8c75

27 files changed

+338
-1055
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## Unreleased
9+
10+
### Added
11+
12+
- Cross platform support
13+
814
## [1.1.0] - 2018-03-13
915

1016
### Added

Modules/OperationValidation/OperationValidation.psm1

-692
This file was deleted.

OperationValidation/Diagnostics/Comprehensive/PSGallery.Comprehensive.Tests.ps1

+25-27
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11

2-
Describe "E2E validation of PSGallery" -Fixture {
2+
Describe 'E2E validation of PSGallery' -Fixture {
33
BeforeAll {
4-
$Repository = "InternalPSGallery"
5-
$ModuleName = "FormatTools"
6-
$Version = "0.5.0"
7-
import-module PowerShellGet -Force
8-
if ( Get-Module -list ${ModuleName} )
9-
{
4+
$repository = 'PSGallery'
5+
$moduleName = 'FormatTools'
6+
$version = '0.5.0'
7+
if (Get-Module -Name $moduleName -ListAvailable) {
108
# the module is already installed
11-
$PSDefaultParameterValues["It:skip"] = $true
9+
$PSDefaultParameterValues['It:skip'] = $true
1210
}
1311
}
1412

15-
It "should return the same number of modules via cmdlets and website" {
16-
$GalleryUrl = "http://psget/psgallery"
17-
# timing window here - between these two operations, modules list may change
18-
$wc = new-object System.Net.WebClient
19-
$modules = Find-Module -Repository InternalPSGallery -ea SilentlyContinue
20-
$page = $wc.downloadstring("${GalleryUrl}/packages").replace("`n","")
21-
$expectedCount = $page -replace ".*There are (\d+) modules.*",'$1'
22-
$modules.Count | Should be $expectedCount
13+
# It 'should return the same number of modules via cmdlets and website' {
14+
# $galleryUrl = 'https://www.powershellgallery.com'
15+
# # timing window here - between these two operations, modules list may change
16+
# $wc = New-Object System.Net.WebClient
17+
# $modules = Find-Module -Repository $repository -ErrorAction SilentlyContinue
18+
# $page = $wc.downloadstring("${galleryUrl}/packages").replace("`n", '')
19+
# $expectedCount = $page -replace ".*There are (\d+) modules.*", '$1'
20+
# $modules.Count | Should be $expectedCount
21+
# }
22+
It -skip:$false 'Should be possible to find a known module' {
23+
$myModule = Find-Module -Repository $repository -Name $moduleName -RequiredVersion $version
24+
$myModule.Name | Should be $moduleName
25+
$myModule.Version | Should be $version
2326
}
24-
It -skip:$false "Should be possible to find a known module" {
25-
$myModule = find-module -repository ${Repository} -Name ${ModuleName} -RequiredVersion ${Version}
26-
$myModule.Name | Should be ${ModuleName}
27-
$myModule.Version | Should be $Version
28-
}
29-
It "Should be possible to install and import a known module" {
30-
install-module -Force -Name ${ModuleName} -RequiredVersion ${Version} -Repository ${Repository} -Scope CurrentUser
31-
$m = Import-Module ${ModuleName} -PassThru
27+
It 'Should be possible to install and import a known module' {
28+
Install-Module -Force -Name $moduleName -RequiredVersion $version -Repository $repository -Scope CurrentUser
29+
$m = Import-Module $moduleName -PassThru
3230
$m.ModuleBase.IndexOf($HOME) | Should be 0
3331
}
32+
3433
AfterAll {
35-
if ( $PSDefaultParameterValues["It:skip"] -ne $true)
36-
{
37-
Uninstall-Module -force -RequiredVersion ${version} -Name ${ModuleName} -ea SilentlyContinue
34+
if ($PSDefaultParameterValues['It:skip'] -ne $true) {
35+
Uninstall-Module -Force -RequiredVersion $version -Name $ModuleName -ErrorAction SilentlyContinue
3836
}
3937
}
4038
}
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

+11-3
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
)
@@ -119,7 +127,7 @@ PrivateData = @{
119127
# IconUri = ''
120128

121129
# ReleaseNotes of this module
122-
# ReleaseNotes = ''
130+
ReleaseNotes = 'https://raw.githubusercontent.com/PowerShell/Operation-Validation-Framework/master/CHANGELOG.md'
123131

124132
} # End of PSData hashtable
125133

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11

2+
$script:pathSeparator = [IO.Path]::PathSeparator
3+
24
# Dot source public/private functions
3-
$public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse -ErrorAction SilentlyContinue )
4-
$private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -Recurse -ErrorAction SilentlyContinue )
5+
$public = @( Get-ChildItem -Path ([IO.Path]::Combine($PSScriptRoot, 'Public', '*.ps1')) -Recurse -ErrorAction SilentlyContinue )
6+
$private = @( Get-ChildItem -Path ([IO.Path]::Combine($PSScriptRoot, 'Private', '*.ps1')) -Recurse -ErrorAction SilentlyContinue )
57
foreach($import in @($public + $private)) {
6-
. $import.fullname
8+
try {
9+
. $import.FullName
10+
} catch {
11+
throw "Unable to dot source [$($import.FullName)]"
12+
}
713
}
814

915
Export-ModuleMember -Function $public.Basename

OperationValidation/Private/Convert-TestResult.ps1

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
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
99
)
1010

11-
foreach ( $testResult in $result.TestResult ) {
11+
foreach ($testResult in $result.TestResult) {
1212
$testError = $null
13-
if ( $testResult.Result -eq 'Failed' ) {
13+
if ($testResult.Result -eq 'Failed') {
1414
Write-Verbose -message 'Creating error object'
1515
$testError = New-OperationValidationFailure -Stacktrace $testResult.StackTrace -FailureMessage $testResult.FailureMessage
1616
}
1717

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

+26-41
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-
{
15-
$pathsToSearch = $env:PSModulePath.Trim(';').Split(';')
16-
}
17-
elseIf ($PSCmdlet.ParameterSetName -eq 'Path')
18-
{
19+
if ($PSCmdlet.ParameterSetName -eq 'Name') {
20+
$pathsToSearch = $env:PSModulePath.Trim($script:pathSeparator).Split($script:pathSeparator)
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

+4-7
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

+5-8
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

+6-11
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
}

0 commit comments

Comments
 (0)