Skip to content

Commit f4db12f

Browse files
committed
Rename tests for ConvertTo-SourceLineNumber
1 parent 3b4b5f6 commit f4db12f

1 file changed

Lines changed: 82 additions & 82 deletions

File tree

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
1-
#requires -Module ModuleBuilder
2-
Describe "Convert-LineNumber" {
3-
# use the integration test code
4-
BeforeAll {
5-
Build-Module $PSScriptRoot/../Integration/Source1/build.psd1 -Passthru
6-
Push-Location $PSScriptRoot -StackName Convert-CodeCoverage
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"
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-
)
18-
}
19-
AfterAll {
20-
Pop-Location -StackName Convert-CodeCoverage
21-
}
22-
23-
24-
It "Should map line <outputLine> in the Module to line <sourceLine> in the source of <sourceFile>" -TestCases $TestCases {
25-
param($outputLine, $sourceFile, $sourceLine)
26-
27-
$SourceLocation = Convert-LineNumber $Convert_LineNumber_ModulePath $outputLine
28-
$SourceLocation.SourceFile | Should -Be $SourceFile
29-
$SourceLocation.SourceLineNumber | Should -Be $SourceLine
30-
31-
$line = (Get-Content (Join-Path $Convert_LineNumber_ModuleSource $SourceLocation.SourceFile))[$SourceLocation.SourceLineNumber - 1]
32-
try {
33-
$Convert_LineNumber_ModuleContent[$outputLine -1] | Should -Be $line
34-
} catch {
35-
throw "Failed to match module line $outputLine to $($SourceLocation.SourceFile) line $($SourceLocation.SourceLineNumber).`nExpected $Line`nBut got $($Convert_LineNumber_ModuleContent[$outputLine -1])"
36-
}
37-
}
38-
39-
It "Should throw if the SourceFile doesn't exist" {
40-
{ Convert-LineNumber -SourceFile TestDrive:/NoSuchFile -SourceLineNumber 10 } |
41-
Should -Throw "'TestDrive:/NoSuchFile' does not exist"
42-
}
43-
44-
It 'Should work with an error PositionMessage' {
45-
$line = Select-String -Path $Convert_LineNumber_ModulePath 'function Set-Source {' | ForEach-Object LineNumber
46-
47-
$SourceLocation = "At ${Convert_LineNumber_ModulePath}:$line char:17" | Convert-LineNumber
48-
# This test is assuming you built the code on Windows. Should Convert-LineNumber convert the path?
49-
$SourceLocation.SourceFile | Should -Be ".${\}Public${\}Set-Source.ps1"
50-
$SourceLocation.SourceLineNumber | Should -Be 1
51-
}
52-
53-
It 'Should work with ScriptStackTrace messages' {
54-
55-
$SourceFile = Join-Path $Convert_LineNumber_ModuleSource Public/Set-Source.ps1 | Convert-Path
56-
57-
$outputLine = Select-String -Path $Convert_LineNumber_ModulePath "sto͞o′pĭd" | % LineNumber
58-
$sourceLine = Select-String -Path $SourceFile "sto͞o′pĭd" | % LineNumber
59-
60-
$SourceLocation = "At Set-Source, ${Convert_LineNumber_ModulePath}: line $outputLine" | Convert-LineNumber
61-
62-
# This test is assuming you built the code on Windows. Should Convert-LineNumber convert the path?
63-
$SourceLocation.SourceFile | Should -Be ".${\}Public${\}Set-Source.ps1"
64-
$SourceLocation.SourceLineNumber | Should -Be $sourceLine
65-
}
66-
67-
It 'Should pass through InputObject for updating objects like CodeCoverage or ErrorRecord' {
68-
$PesterMiss = [PSCustomObject]@{
69-
# Note these don't really matter, but they're passed through
70-
Function = 'Get-Source'
71-
# these are pipeline bound
72-
File = $Convert_LineNumber_ModulePath
73-
Line = 25 # 1 offset with the Using Statement introduced in MoveUsingStatements
74-
}
75-
76-
$SourceLocation = $PesterMiss | Convert-LineNumber -Passthru
77-
# This test is assuming you built the code on Windows. Should Convert-LineNumber convert the path?
78-
$SourceLocation.SourceFile | Should -Be ".${\}Public${\}Get-Source.ps1"
79-
$SourceLocation.SourceLineNumber | Should -Be 5
80-
$SourceLocation.Function | Should -Be 'Get-Source'
81-
}
82-
}
1+
#requires -Module ModuleBuilder
2+
Describe "ConvertTo-SourceLineNumber" {
3+
# use the integration test code
4+
BeforeAll {
5+
Build-Module $PSScriptRoot/../Integration/Source1/build.psd1 -Passthru
6+
Push-Location $PSScriptRoot -StackName ConvertTo-SourceLineNumber
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"
10+
$global:Convert_LineNumber_ModuleContent = Get-Content $global:Convert_LineNumber_ModulePath
11+
${global:\} = [io.path]::DirectorySeparatorChar
12+
13+
$global:TestCases = @(
14+
@{ outputLine = 18; sourceFile = ".${\}Private${\}Get-TestNotExportedAliases.ps1"; sourceLine = 13 }
15+
@{ outputLine = 24; sourceFile = ".${\}Private${\}GetFinale.ps1"; sourceLine = 4 }
16+
@{ outputLine = 43; sourceFile = ".${\}Public${\}Get-Source.ps1"; sourceLine = 5 }
17+
)
18+
}
19+
AfterAll {
20+
Pop-Location -StackName ConvertTo-SourceLineNumber
21+
}
22+
23+
24+
It "Should map line <outputLine> in the Module to line <sourceLine> in the source of <sourceFile>" -TestCases $TestCases {
25+
param($outputLine, $sourceFile, $sourceLine)
26+
27+
$SourceLocation = ConvertTo-SourceLineNumber $Convert_LineNumber_ModulePath $outputLine
28+
$SourceLocation.SourceFile | Should -Be $SourceFile
29+
$SourceLocation.SourceLineNumber | Should -Be $SourceLine
30+
31+
$line = (Get-Content (Join-Path $Convert_LineNumber_ModuleSource $SourceLocation.SourceFile))[$SourceLocation.SourceLineNumber - 1]
32+
try {
33+
$Convert_LineNumber_ModuleContent[$outputLine -1] | Should -Be $line
34+
} catch {
35+
throw "Failed to match module line $outputLine to $($SourceLocation.SourceFile) line $($SourceLocation.SourceLineNumber).`nExpected $Line`nBut got $($Convert_LineNumber_ModuleContent[$outputLine -1])"
36+
}
37+
}
38+
39+
It "Should throw if the SourceFile doesn't exist" {
40+
{ Convert-LineNumber -SourceFile TestDrive:/NoSuchFile -SourceLineNumber 10 } |
41+
Should -Throw "'TestDrive:/NoSuchFile' does not exist"
42+
}
43+
44+
It 'Should work with an error PositionMessage' {
45+
$line = Select-String -Path $Convert_LineNumber_ModulePath 'function Set-Source {' | ForEach-Object LineNumber
46+
47+
$SourceLocation = "At ${Convert_LineNumber_ModulePath}:$line char:17" | Convert-LineNumber
48+
# This test is assuming you built the code on Windows. Should Convert-LineNumber convert the path?
49+
$SourceLocation.SourceFile | Should -Be ".${\}Public${\}Set-Source.ps1"
50+
$SourceLocation.SourceLineNumber | Should -Be 1
51+
}
52+
53+
It 'Should work with ScriptStackTrace messages' {
54+
55+
$SourceFile = Join-Path $Convert_LineNumber_ModuleSource Public/Set-Source.ps1 | Convert-Path
56+
57+
$outputLine = Select-String -Path $Convert_LineNumber_ModulePath "sto͞o′pĭd" | % LineNumber
58+
$sourceLine = Select-String -Path $SourceFile "sto͞o′pĭd" | % LineNumber
59+
60+
$SourceLocation = "At Set-Source, ${Convert_LineNumber_ModulePath}: line $outputLine" | Convert-LineNumber
61+
62+
# This test is assuming you built the code on Windows. Should Convert-LineNumber convert the path?
63+
$SourceLocation.SourceFile | Should -Be ".${\}Public${\}Set-Source.ps1"
64+
$SourceLocation.SourceLineNumber | Should -Be $sourceLine
65+
}
66+
67+
It 'Should pass through InputObject for updating objects like CodeCoverage or ErrorRecord' {
68+
$PesterMiss = [PSCustomObject]@{
69+
# Note these don't really matter, but they're passed through
70+
Function = 'Get-Source'
71+
# these are pipeline bound
72+
File = $Convert_LineNumber_ModulePath
73+
Line = 43 # 1 offset with the Using Statement introduced in MoveUsingStatements
74+
}
75+
76+
$SourceLocation = $PesterMiss | Convert-LineNumber -Passthru
77+
# This test is assuming you built the code on Windows. Should Convert-LineNumber convert the path?
78+
$SourceLocation.SourceFile | Should -Be ".${\}Public${\}Get-Source.ps1"
79+
$SourceLocation.SourceLineNumber | Should -Be 5
80+
$SourceLocation.Function | Should -Be 'Get-Source'
81+
}
82+
}

0 commit comments

Comments
 (0)