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

Commit 3fde749

Browse files
committed
Deal with single Pester test files that are not part of a module correctly
Fixed #3 where an error would be generated when using Invoke-OperationValidation with the -TestFilePath parameter against a Pester test file with a short path.
1 parent f78d624 commit 3fde749

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1717
### Fixed
1818

1919
- PR25 Discovery Pester 'Describe' block names when the -Name parameter is used (via @GitAMBS)
20+
- Fixed #3 where an error would be generated when using Invoke-OperationValidation with the -TestFilePath parameter
21+
against a Pester test file with a short path.
2022

2123
## [1.0.1] - 2015-12-05
2224

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11

2-
# emit an object which can be used in reporting
3-
Function Convert-TestResult
4-
{
5-
param ( $result )
6-
foreach ( $testResult in $result.TestResult )
7-
{
2+
# Emit an object which can be used in reporting
3+
Function Convert-TestResult {
4+
param (
5+
[Parameter(Mandatory = $true)]
6+
$result,
7+
8+
[string]$ModuleName
9+
)
10+
11+
foreach ( $testResult in $result.TestResult ) {
812
$testError = $null
9-
if ( $testResult.Result -eq "Failed" )
10-
{
11-
Write-Verbose -message "Creating error object"
12-
$testError = new-OperationValidationFailure -Stacktrace $testResult.StackTrace -FailureMessage $testResult.FailureMessage
13+
if ( $testResult.Result -eq 'Failed' ) {
14+
Write-Verbose -message 'Creating error object'
15+
$testError = New-OperationValidationFailure -Stacktrace $testResult.StackTrace -FailureMessage $testResult.FailureMessage
16+
}
17+
18+
$TestName = '{0}:{1}:{2}' -f $testResult.Describe, $testResult.Context, $testResult.Name
19+
20+
$newOVResultParams = @{
21+
Name = $TestName
22+
FileName = $result.path
23+
Result = $testresult.result
24+
RawResult = $testResult
25+
Error = $TestError
26+
}
27+
if (-not [string]::IsNullOrEmpty($ModuleName)) {
28+
$newOVResultParams['Module'] = $ModuleName
1329
}
14-
$Module = $result.Path.split([io.path]::DirectorySeparatorChar)[-4]
15-
$TestName = "{0}:{1}:{2}" -f $testResult.Describe,$testResult.Context,$testResult.Name
16-
New-OperationValidationResult -Module $Module -Name $TestName -FileName $result.path -Result $testresult.result -RawResult $testResult -Error $TestError
30+
New-OperationValidationResult @newOVResultParams
1731
}
1832
}

OperationValidation/Private/New-OperationValidationResult.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ function New-OperationValidationResult
33
{
44
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='*')]
55
param (
6-
[Parameter(Mandatory=$true)][string]$Module,
76
[Parameter(Mandatory=$true)][string]$FileName,
87
[Parameter(Mandatory=$true)][string]$Name,
98
[Parameter(Mandatory=$true)][string]$Result,
9+
[Parameter()][string]$Module,
1010
[Parameter()][object]$RawResult,
1111
[Parameter()][object]$Error
1212
)

OperationValidation/Public/Invoke-OperationValidation.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ function Invoke-OperationValidation
314314
if ($testResult)
315315
{
316316
Add-member -InputObject $testResult -MemberType NoteProperty -Name Path -Value $ti.FilePath
317-
Convert-TestResult -Result $testResult -ModuleName $ModuleName
317+
Convert-TestResult -Result $testResult -ModuleName $ti.ModuleName
318318
}
319319
}
320320
}

0 commit comments

Comments
 (0)