2
2
Describe " Convert-LineNumber" {
3
3
# use the integration test code
4
4
BeforeAll {
5
- Build-Module $PSScriptRoot \..\ Integration\ Source1\ build.psd1 - Passthru
5
+ Build-Module $PSScriptRoot / .. / Integration/ Source1/ build.psd1 - Passthru
6
6
Push-Location $PSScriptRoot - StackName Convert-CodeCoverage
7
7
8
- $global :Convert_LineNumber_ModulePath = Convert-Path " .\..\ Integration\ Result1\ Source1\ 1.0.0\ Source1.psm1"
9
- $global :Convert_LineNumber_ModuleSource = Convert-Path " .\..\ Integration\ Source1"
8
+ $global :Convert_LineNumber_ModulePath = Convert-Path " ./../ Integration/ Result1/ Source1/ 1.0.0/ Source1.psm1"
9
+ $global :Convert_LineNumber_ModuleSource = Convert-Path " ./../ Integration/ Source1"
10
10
$global :Convert_LineNumber_ModuleContent = Get-Content $global :Convert_LineNumber_ModulePath
11
+ ${global :\} = [io.path ]::DirectorySeparatorChar
12
+
13
+ $global :TestCases = @ (
14
+ @ { outputLine = 6 ; sourceFile = " .${\} Private${\} GetFinale.ps1" ; sourceLine = 4 }
15
+ @ { outputLine = 18 ; sourceFile = " .${\} Private${\} GetPreview.ps1" ; sourceLine = 7 }
16
+ @ { outputLine = 25 ; sourceFile = " .${\} Public${\} Get-Source.ps1" ; sourceLine = 5 }
17
+ )
11
18
}
12
19
AfterAll {
13
20
Pop-Location - StackName Convert-CodeCoverage
14
21
}
15
22
16
- $TestCases = @ (
17
- @ { outputLine = 6 ; sourceFile = " .\Private\GetFinale.ps1" ; sourceLine = 4 }
18
- @ { outputLine = 18 ; sourceFile = " .\Private\GetPreview.ps1" ; sourceLine = 7 }
19
- @ { outputLine = 25 ; sourceFile = " .\Public\Get-Source.ps1" ; sourceLine = 5 }
20
- )
21
23
22
24
It " Should map line <outputLine> in the Module to line <sourceLine> in the source of <sourceFile>" - TestCases $TestCases {
23
25
param ($outputLine , $sourceFile , $sourceLine )
@@ -35,30 +37,30 @@ Describe "Convert-LineNumber" {
35
37
}
36
38
37
39
It " Should throw if the SourceFile doesn't exist" {
38
- { Convert-LineNumber - SourceFile TestDrive:\ NoSuchFile - SourceLineNumber 10 } |
39
- Should - Throw " 'TestDrive:\ NoSuchFile' does not exist"
40
+ { Convert-LineNumber - SourceFile TestDrive:/ NoSuchFile - SourceLineNumber 10 } |
41
+ Should - Throw " 'TestDrive:/ NoSuchFile' does not exist"
40
42
}
41
43
42
44
It ' Should work with an error PositionMessage' {
43
45
$line = Select-String - Path $Convert_LineNumber_ModulePath ' function Set-Source {' | ForEach-Object LineNumber
44
46
45
47
$SourceLocation = " At ${Convert_LineNumber_ModulePath} :$line char:17" | Convert-LineNumber
46
48
# This test is assuming you built the code on Windows. Should Convert-LineNumber convert the path?
47
- $SourceLocation.SourceFile | Should - Be " .\ Public\ Set-Source.ps1"
49
+ $SourceLocation.SourceFile | Should - Be " .${\} Public${\} Set-Source.ps1"
48
50
$SourceLocation.SourceLineNumber | Should - Be 1
49
51
}
50
52
51
53
It ' Should work with ScriptStackTrace messages' {
52
54
53
- $SourceFile = Join-Path $Convert_LineNumber_ModuleSource Public\ Set-Source.ps1 | Convert-Path
55
+ $SourceFile = Join-Path $Convert_LineNumber_ModuleSource Public/ Set-Source.ps1 | Convert-Path
54
56
55
57
$outputLine = Select-String - Path $Convert_LineNumber_ModulePath " sto͞o′pĭd" | % LineNumber
56
58
$sourceLine = Select-String - Path $SourceFile " sto͞o′pĭd" | % LineNumber
57
59
58
60
$SourceLocation = " At Set-Source, ${Convert_LineNumber_ModulePath} : line $outputLine " | Convert-LineNumber
59
61
60
62
# This test is assuming you built the code on Windows. Should Convert-LineNumber convert the path?
61
- $SourceLocation.SourceFile | Should - Be " .\ Public\ Set-Source.ps1"
63
+ $SourceLocation.SourceFile | Should - Be " .${\} Public${\} Set-Source.ps1"
62
64
$SourceLocation.SourceLineNumber | Should - Be $sourceLine
63
65
}
64
66
@@ -73,7 +75,7 @@ Describe "Convert-LineNumber" {
73
75
74
76
$SourceLocation = $PesterMiss | Convert-LineNumber - Passthru
75
77
# This test is assuming you built the code on Windows. Should Convert-LineNumber convert the path?
76
- $SourceLocation.SourceFile | Should - Be " .\ Public\ Get-Source.ps1"
78
+ $SourceLocation.SourceFile | Should - Be " .${\} Public${\} Get-Source.ps1"
77
79
$SourceLocation.SourceLineNumber | Should - Be 5
78
80
$SourceLocation.Function | Should - Be ' Get-Source'
79
81
}
0 commit comments