Skip to content

Commit bcaff26

Browse files
author
Kapil Borle
committed
Add tests for ScriptPath and ScriptName properties
1 parent da74804 commit bcaff26

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ Describe "Test Path" {
124124
}
125125
}
126126

127+
Context "DiagnosticRecord " {
128+
It "has valid ScriptPath and ScriptName properties when an input file is given" {
129+
$scriptName = "TestScript.ps1"
130+
$scriptPath = Join-Path $directory $scriptName
131+
$expectedScriptPath = Resolve-Path $directory\TestScript.ps1
132+
$diagnosticRecords = Invoke-ScriptAnalyzer $scriptPath -IncludeRule "PSAvoidUsingEmptyCatchBlock"
133+
$diagnosticRecords[0].ScriptPath | Should Be $expectedScriptPath.Path
134+
$diagnosticRecords[0].ScriptName | Should Be $scriptName
135+
}
136+
137+
It "has empty ScriptPath and ScriptName properties when a script definition is given" {
138+
$diagnosticRecords = Invoke-ScriptAnalyzer -ScriptDefinition gci -IncludeRule "PSAvoidUsingCmdletAliases"
139+
$diagnosticRecords[0].ScriptPath | Should Be ([System.String]::Empty)
140+
$diagnosticRecords[0].ScriptName | Should Be ([System.String]::Empty)
141+
}
142+
}
143+
127144
if (!$testingLibraryUsage)
128145
{
129146
#There is probably a more concise way to do this but for now we will settle for this!
@@ -177,7 +194,6 @@ Describe "Test Path" {
177194
Write-Output $writeHostViolation.Count
178195
$globalVarsViolation.Count -eq 1 -and $writeHostViolation.Count -eq 1 | Should Be $true
179196
}
180-
181197
}
182198
}
183199

0 commit comments

Comments
 (0)