|
| 1 | +#requires -Module ModuleBuilder |
| 2 | +Describe "ConvertFrom-SourceLineNumber" { |
| 3 | + # use the integration test code |
| 4 | + BeforeAll { |
| 5 | + Build-Module $PSScriptRoot/../Integration/Source1/build.psd1 -Passthru |
| 6 | + Push-Location $PSScriptRoot -StackName ConvertFrom-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; Module = $Convert_LineNumber_ModulePath } |
| 15 | + @{ outputLine = 24; sourceFile = ".${\}Private${\}GetFinale.ps1"; sourceLine = 4; Module = $Convert_LineNumber_ModulePath } |
| 16 | + @{ outputLine = 43; sourceFile = ".${\}Public${\}Get-Source.ps1"; sourceLine = 5; Module = $Convert_LineNumber_ModulePath } |
| 17 | + ) |
| 18 | + } |
| 19 | + AfterAll { |
| 20 | + Pop-Location -StackName ConvertFrom-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, $module) |
| 26 | + |
| 27 | + $sourcePath = Join-Path $Convert_LineNumber_ModuleSource $SourceFile | Convert-Path |
| 28 | + $OutputLocation = ConvertFrom-SourceLineNumber $sourcePath $sourceLine -Module $module |
| 29 | + $OutputLocation.Script | Should -Be $Convert_LineNumber_ModulePath |
| 30 | + $OutputLocation.Line | Should -Be $outputLine |
| 31 | + |
| 32 | + $line = (Get-Content $sourcePath)[$sourceLine - 1] |
| 33 | + try { |
| 34 | + $Convert_LineNumber_ModuleContent[$OutputLocation.Line - 1] | Should -Be $line |
| 35 | + } catch { |
| 36 | + throw "Failed to match module line $outputLine to $($sourceFile) line $($sourceLine).`nExpected $($Convert_LineNumber_ModuleContent[$OutputLocation.Line - 1])`nBut got $line" |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + It "Should warn if the SourceFile doesn't exist" { |
| 41 | + ConvertFrom-SourceLineNumber -SourceFile TestDrive:/NoSuchFile -SourceLineNumber 10 -Module $Convert_LineNumber_ModulePath -WarningVariable Warns |
| 42 | + $Warns | Should -Be "'TestDrive:/NoSuchFile' not found in $Convert_LineNumber_ModulePath" |
| 43 | + } |
| 44 | +} |
0 commit comments