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

Commit 8447666

Browse files
committed
Add version property to test info object
1 parent ffda8a7 commit 8447666

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

Modules/OperationValidation/OperationValidation.Format.ps1xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@
4646
</CustomItem>
4747
</Frame>
4848

49+
<Text>Version: </Text>
50+
<Frame>
51+
<LeftIndent>4</LeftIndent>
52+
<CustomItem>
53+
<ExpressionBinding>
54+
<PropertyName>Version</PropertyName>
55+
</ExpressionBinding>
56+
<NewLine/>
57+
</CustomItem>
58+
</Frame>
59+
4960
<Text>Type: </Text>
5061
<Frame>
5162
<LeftIndent>4</LeftIndent>

Modules/OperationValidation/OperationValidation.psm1

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function new-OperationValidationInfo
4646
[Parameter()][string[]]$TestCases,
4747
[Parameter(Mandatory=$true)][ValidateSet("None","Simple","Comprehensive")][string]$Type,
4848
[Parameter()][string]$modulename,
49+
[Parameter()][Version]$Version,
4950
[Parameter()][hashtable]$Parameters
5051
)
5152
$o = [pscustomobject]@{
@@ -55,6 +56,7 @@ function new-OperationValidationInfo
5556
TestCases = $testCases
5657
Type = $type
5758
ModuleName = $modulename
59+
Version = $Version
5860
ScriptParameters = $Parameters
5961
}
6062
$o.psobject.Typenames.Insert(0,"OperationValidationInfo")
@@ -69,7 +71,6 @@ function Get-TestFromScript
6971
param ( [string]$scriptPath )
7072
$errs = $null
7173
$tok =[System.Management.Automation.PSParser]::Tokenize((get-content -read 0 -Path $scriptPath), [ref]$Errs)
72-
write-verbose -Message $scriptPath
7374

7475
for($i = 0; $i -lt $tok.count; $i++) {
7576
if ( $tok[$i].type -eq "Command" -and $tok[$i].content -eq "Describe" )
@@ -285,20 +286,31 @@ param (
285286
foreach($module in $moduleCollection)
286287
{
287288
Write-Progress -Activity ("Searching for Diagnostics in " + $module) -PercentComplete ($count++/$moduleCount*100) -status " "
288-
$diagnosticsDir=$module + "\Diagnostics"
289+
$diagnosticsDir = "$module\Diagnostics"
290+
291+
# Get the module manifest so we can pull out the version
292+
$moduleName = Split-Path -Path $module -Leaf
293+
$manifestFile = Get-ChildItem -Path $module -Filter "$moduleName.psd1"
294+
if (-not $manifestFile) {
295+
# We may be in a "version" directory so get the actual module name from the parent directory
296+
$parent = (Split-Path -Path $module -Parent).Name
297+
$manifestFile = Get-ChildItem -Path $module -Filter "$parent.psd1"
298+
}
299+
$manifest = Test-ModuleManifest -Path $manifestFile.FullName -Verbose:$false
300+
289301
if ( test-path -path $diagnosticsDir )
290302
{
291303
foreach($dir in $testType)
292304
{
293-
$testDir = "$diagnosticsDir\$dir"
294-
write-verbose -Message "SPECIFIC TEST: $testDir"
305+
$testDir = Join-Path -Path $diagnosticsDir -ChildPath $dir
306+
write-verbose -Message "TEST DIR: $testDir"
295307
if ( ! (test-path -path $testDir) )
296308
{
297309
continue
298310
}
299311
foreach($file in get-childitem -path $testDir -filter *.tests.ps1)
300312
{
301-
Write-Verbose -Message $file.fullname
313+
Write-Verbose -Message "PESTER TEST: $($file.fullname)"
302314

303315
# Pull out parameters to Pester script if they exist
304316
$script = Get-Command -Name $file.fullname
@@ -311,7 +323,16 @@ param (
311323

312324
$testNames = @(Get-TestFromScript -scriptPath $file.FullName)
313325
foreach ($testName in $testNames) {
314-
New-OperationValidationInfo -FilePath $file.Fullname -File $file.Name -Type $dir -Name $testName -ModuleName $Module -Parameters $parameters
326+
$modInfoParams = @{
327+
FilePath = $file.Fullname
328+
File = $file.Name
329+
Type = $dir
330+
Name = $testName
331+
ModuleName = $Module
332+
Version = [version]$manifest.Version
333+
Parameters = $parameters
334+
}
335+
New-OperationValidationInfo @modInfoParams
315336
}
316337
}
317338
}
@@ -431,7 +452,7 @@ function Invoke-OperationValidation
431452
}
432453
}
433454

434-
Write-Verbose -Message ("EXECUTING: {0} {1}" -f $ti.FilePath,($ti.Name -join ","))
455+
Write-Verbose -Message ("EXECUTING: {0} [{1}]" -f $ti.FilePath,($ti.Name -join ","))
435456
foreach($ti in $testinfo)
436457
{
437458
$pesterParams = @{
@@ -446,7 +467,7 @@ function Invoke-OperationValidation
446467
Write-Verbose -Message 'Test has script parameters'
447468
if ($PSBoundParameters.ContainsKey('Overrides'))
448469
{
449-
Write-Verbose -Message "Overriding with parameters:`n$($Overrides | Format-List -Property * | Out-String)"
470+
Write-Verbose -Message "Overriding with parameters:`n$($Overrides | Format-Table -Property Key, Value | Out-String)"
450471
$pesterParams.Script = @{
451472
Path = $ti.FilePath
452473
Parameters = $Overrides

0 commit comments

Comments
 (0)