11Describe " ConvertTo-SourceLineNumber" {
2+ BeforeDiscovery {
3+ $TestCases = @ (
4+ @ { outputLine = 40 ; sourceFile = " .${\} Private${\} TestUnExportedAliases.ps1" ; sourceLine = 13 }
5+ @ { outputLine = 48 ; sourceFile = " .${\} Public${\} Get-Source.ps1" ; sourceLine = 5 }
6+ @ { outputLine = 56 ; sourceFile = " .${\} Public${\} Set-Source.ps1" ; sourceLine = 3 }
7+ )
8+ }
29 # use the integration test code
310 BeforeAll {
411 Build-Module $PSScriptRoot / ../ Integration/ Source1/ build.psd1 - Passthru
@@ -8,12 +15,6 @@ Describe "ConvertTo-SourceLineNumber" {
815 $global :Convert_LineNumber_ModuleSource = Convert-Path " ./../Integration/Source1"
916 $global :Convert_LineNumber_ModuleContent = Get-Content $global :Convert_LineNumber_ModulePath
1017 ${global :\} = [io.path ]::DirectorySeparatorChar
11-
12- $global :TestCases = @ (
13- @ { outputLine = 40 ; sourceFile = " .${\} Private${\} TestUnExportedAliases.ps1" ; sourceLine = 13 }
14- @ { outputLine = 48 ; sourceFile = " .${\} Public${\} Get-Source.ps1" ; sourceLine = 5 }
15- @ { outputLine = 56 ; sourceFile = " .${\} Public${\} Set-Source.ps1" ; sourceLine = 3 }
16- )
1718 }
1819 AfterAll {
1920 Pop-Location - StackName ConvertTo-SourceLineNumber
@@ -28,7 +29,7 @@ Describe "ConvertTo-SourceLineNumber" {
2829
2930 $line = (Get-Content (Join-Path $Convert_LineNumber_ModuleSource $SourceLocation.SourceFile ))[$SourceLocation.SourceLineNumber - 1 ]
3031 try {
31- $Convert_LineNumber_ModuleContent [$outputLine -1 ] | Should - Be $line
32+ $Convert_LineNumber_ModuleContent [$outputLine - 1 ] | Should - Be $line
3233 } catch {
3334 throw " Failed to match module line $outputLine to $ ( $SourceLocation.SourceFile ) line $ ( $SourceLocation.SourceLineNumber ) .`n Expected $Line `n But got $ ( $Convert_LineNumber_ModuleContent [$outputLine -1 ]) "
3435 }
@@ -40,7 +41,7 @@ Describe "ConvertTo-SourceLineNumber" {
4041 }
4142
4243 It ' Should work with an error PositionMessage' {
43- $line = Select-String - Path $Convert_LineNumber_ModulePath ' function Set-Source {' | ForEach-Object LineNumber
44+ $line = ( Select-String - Path $Convert_LineNumber_ModulePath ' function Set-Source {' ). LineNumber
4445
4546 $SourceLocation = " At ${Convert_LineNumber_ModulePath} :$line char:17" | ConvertTo-SourceLineNumber
4647 $SourceLocation.SourceFile | Should - Be " .${\} Public${\} Set-Source.ps1"
@@ -51,8 +52,11 @@ Describe "ConvertTo-SourceLineNumber" {
5152
5253 $SourceFile = Join-Path $Convert_LineNumber_ModuleSource (Join-Path Public Set-Source.ps1 ) | Convert-Path
5354
54- $outputLine = Select-String - Path $Convert_LineNumber_ModulePath " sto͞o′pĭd" | ForEach-Object LineNumber
55- $sourceLine = Select-String - Path $SourceFile " sto͞o′pĭd" | ForEach-Object LineNumber
55+ $outputLine = (Select-String - Path $Convert_LineNumber_ModulePath " sto͞o′pĭd" ).LineNumber
56+ $sourceLine = (Select-String - Path $SourceFile " sto͞o′pĭd" ).LineNumber
57+
58+ $sourceLine | Should - BeGreaterThan 0 - Because " the test string 'sto͞o′pĭd' is definitely found in the source file"
59+ $outputLine | Should - BeGreaterThan 0 - Because " the test string 'sto͞o′pĭd' should be found in the module"
5660
5761 $SourceLocation = " At Set-Source, ${Convert_LineNumber_ModulePath} : line $outputLine " | ConvertTo-SourceLineNumber
5862 $SourceLocation.SourceFile | Should - Be " .${\} Public${\} Set-Source.ps1"
0 commit comments