Skip to content

Commit 2b96d6d

Browse files
committed
Add a regression test for Prefix + Suffix
Shows that #40 is really fixed
1 parent 2c0baf8 commit 2b96d6d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Source/Private/SetModuleContent.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function SetModuleContent {
4848
Write-Verbose "Adding $SourceName"
4949
$SetContent.Process("#Region '$SourceName' 0")
5050
Get-Content $SourceName -OutVariable source | ForEach-Object { $SetContent.Process($_) }
51-
$SetContent.Process("#EndRegion '$SourceName' $($Source.Count)")
51+
$SetContent.Process("#EndRegion '$SourceName' $($Source.Count+1)")
5252
} else {
5353
if(!$ContentStarted) {
5454
$SetContent.Process("#Region 'PREFIX' 0")

Tests/Integration/Source1.Tests.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,32 @@ Describe "Regression test for #88 not copying prefix files" -Tag Integration, Re
172172
$ModuleInfo[0] | Should -be "using module Configuration"
173173
}
174174
}
175+
176+
Describe "Regression test for #40.2 not copying suffix if prefix" -Tag Integration, Regression {
177+
Copy-Item $PSScriptRoot\Source1 TestDrive:\Source1 -Recurse
178+
179+
New-Item TestDrive:\Source1\_GlobalScope.ps1 -Value '$Global:Module = "Testing"'
180+
181+
$metadata = Import-Metadata TestDrive:\Source1\build.psd1
182+
$metadata += @{
183+
Prefix = ".\_GlobalScope.ps1"
184+
Suffix = ".\_GlobalScope.ps1"
185+
}
186+
$metadata | Export-Metadata TestDrive:\Source1\build.psd1
187+
188+
$Output = Build-Module TestDrive:\Source1 -Passthru
189+
190+
$Metadata = Import-Metadata $Output.Path
191+
192+
It "Should inject the content of the _GlobalScope file at the TOP and BOTTOM" {
193+
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")
194+
$Code = Get-Content $Module
195+
$Code[0] | Should -be "using module ModuleBuilder" # because we moved it, from GetFinale
196+
$Code[1] | Should -be "#Region '.\_GlobalScope.ps1' 0"
197+
$Code[2] | Should -be '$Global:Module = "Testing"'
198+
199+
$Code[-3] | Should -be '$Global:Module = "Testing"'
200+
$Code[-2] | Should -be "#EndRegion '.\_GlobalScope.ps1' 2"
201+
$Code[-1] | Should -be ""
202+
}
203+
}

0 commit comments

Comments
 (0)