Skip to content

Commit d28c47d

Browse files
committed
Add tests to verify prefix works right
1 parent 7d519fa commit d28c47d

File tree

4 files changed

+98
-84
lines changed

4 files changed

+98
-84
lines changed

Source/Private/SetModuleContent.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function SetModuleContent {
3131
[string]$Encoding = $(if($IsCoreCLR) { "UTF8Bom" } else { "UTF8" })
3232
)
3333
begin {
34+
Write-Debug "SetModuleContent WorkingDirectory $WorkingDirectory"
3435
Push-Location $WorkingDirectory -StackName SetModuleContent
3536
$ContentStarted = $false # There has been no content yet
3637

Tests/Integration/Source1.Tests.ps1

Lines changed: 93 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,133 @@
11
#requires -Module ModuleBuilder
22

3-
Describe "Build-Module With Source1" {
4-
Context "When we call Build-Module" {
5-
$Output = Build-Module $PSScriptRoot\Source1\build.psd1 -Passthru
6-
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")
3+
Describe "When we call Build-Module" -Tag Integration {
4+
$Output = Build-Module $PSScriptRoot\Source1\build.psd1 -Passthru
5+
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")
76

8-
It "Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
9-
$Module | Should -Not -FileContentMatch '^Source$'
10-
}
7+
It "Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
8+
$Module | Should -Not -FileContentMatch '^Source$'
9+
}
1110

12-
$Metadata = Import-Metadata $Output.Path
11+
$Metadata = Import-Metadata $Output.Path
1312

14-
It "Should update FunctionsToExport in the manifest" {
15-
$Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source")
16-
}
13+
It "Should update FunctionsToExport in the manifest" {
14+
$Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source")
15+
}
1716

18-
It "Should update AliasesToExport in the manifest" {
19-
$Metadata.AliasesToExport -match "GS" | Should -Not -BeNullOrEmpty
20-
}
17+
It "Should update AliasesToExport in the manifest" {
18+
$Metadata.AliasesToExport -match "GS" | Should -Not -BeNullOrEmpty
19+
}
2120

22-
It "Should de-dupe and move using statements to the top of the file" {
23-
Select-String -Pattern "^using" -Path $Module | ForEach-Object LineNumber | Should -Be 1
24-
}
21+
It "Should de-dupe and move using statements to the top of the file" {
22+
Select-String -Pattern "^using" -Path $Module | ForEach-Object LineNumber | Should -Be 1
23+
}
2524

26-
It "Will comment out the original using statements in their original positions" {
27-
(Select-String -Pattern "^#\s*using" -Path $Module).Count | Should -Be 3
28-
}
25+
It "Will comment out the original using statements in their original positions" {
26+
(Select-String -Pattern "^#\s*using" -Path $Module).Count | Should -Be 3
2927
}
28+
}
3029

31-
Context "Regression test for #55: I can pass SourceDirectories" {
32-
$Output = Build-Module $PSScriptRoot\Source1\build.psd1 -SourceDirectories "Private" -Passthru
33-
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")
30+
Describe "Regression test for #55: I can pass SourceDirectories" -Tag Integration, Regression {
31+
$Output = Build-Module $PSScriptRoot\Source1\build.psd1 -SourceDirectories "Private" -Passthru
32+
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")
3433

35-
It "Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
36-
$Module | Should -Not -FileContentMatch '^Source$'
37-
}
34+
It "Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
35+
$Module | Should -Not -FileContentMatch '^Source$'
36+
}
3837

39-
$Metadata = Import-Metadata $Output.Path
38+
$Metadata = Import-Metadata $Output.Path
4039

41-
It "Should not have any FunctionsToExport if SourceDirectories don't match the PublicFilter" {
42-
$Metadata.FunctionsToExport | Should -Be @()
43-
}
40+
It "Should not have any FunctionsToExport if SourceDirectories don't match the PublicFilter" {
41+
$Metadata.FunctionsToExport | Should -Be @()
42+
}
4443

45-
It "Should de-dupe and move using statements to the top of the file" {
46-
Select-String -Pattern "^using" -Path $Module | ForEach-Object LineNumber | Should -Be 1
47-
}
44+
It "Should de-dupe and move using statements to the top of the file" {
45+
Select-String -Pattern "^using" -Path $Module | ForEach-Object LineNumber | Should -Be 1
46+
}
4847

49-
It "Will comment out the original using statement in the original positions" {
50-
(Select-String -Pattern "^#\s*using" -Path $Module).Count | Should -Be 2
51-
}
48+
It "Will comment out the original using statement in the original positions" {
49+
(Select-String -Pattern "^#\s*using" -Path $Module).Count | Should -Be 2
5250
}
51+
}
5352

54-
Context "Regression test for #55: I can pass SourceDirectories and PublicFilter" {
55-
$Output = Build-Module $PSScriptRoot\Source1\build.psd1 -SourceDirectories "Private" -PublicFilter "P*\*" -Passthru
56-
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")
53+
Describe "Regression test for #55: I can pass SourceDirectories and PublicFilter" -Tag Integration, Regression {
54+
$Output = Build-Module $PSScriptRoot\Source1\build.psd1 -SourceDirectories "Private" -PublicFilter "P*\*" -Passthru
55+
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")
5756

58-
It "Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
59-
$Module | Should -Not -FileContentMatch '^Source$'
60-
}
57+
It "Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
58+
$Module | Should -Not -FileContentMatch '^Source$'
59+
}
6160

62-
$Metadata = Import-Metadata $Output.Path
61+
$Metadata = Import-Metadata $Output.Path
6362

64-
It "Should not have any FunctionsToExport if SourceDirectories don't match the PublicFilter" {
65-
$Metadata.FunctionsToExport | Should -Be @("GetFinale", "GetPreview")
66-
}
63+
It "Should not have any FunctionsToExport if SourceDirectories don't match the PublicFilter" {
64+
$Metadata.FunctionsToExport | Should -Be @("GetFinale", "GetPreview")
65+
}
6766

68-
It "Should update AliasesToExport in the manifest" {
69-
$Metadata.AliasesToExport | Should -Be @("GF", "GP")
70-
}
67+
It "Should update AliasesToExport in the manifest" {
68+
$Metadata.AliasesToExport | Should -Be @("GF", "GP")
69+
}
7170

72-
It "Should de-dupe and move using statements to the top of the file" {
73-
Select-String -Pattern "^using" -Path $Module | ForEach-Object LineNumber | Should -Be 1
74-
}
71+
It "Should de-dupe and move using statements to the top of the file" {
72+
Select-String -Pattern "^using" -Path $Module | ForEach-Object LineNumber | Should -Be 1
73+
}
7574

76-
It "Will comment out the original using statement in the original positions" {
77-
(Select-String -Pattern "^#\s*using" -Path $Module).Count | Should -Be 2
78-
}
75+
It "Will comment out the original using statement in the original positions" {
76+
(Select-String -Pattern "^#\s*using" -Path $Module).Count | Should -Be 2
7977
}
78+
}
8079

81-
Context "Regression test for #84: Multiple Aliases per command will Export" {
82-
$Output = Build-Module $PSScriptRoot\Source1\build.psd1 -Passthru
80+
Describe "Regression test for #84: Multiple Aliases per command will Export" -Tag Integration, Regression {
81+
$Output = Build-Module $PSScriptRoot\Source1\build.psd1 -Passthru
8382

84-
$Metadata = Import-Metadata $Output.Path
83+
$Metadata = Import-Metadata $Output.Path
8584

86-
It "Should update AliasesToExport in the manifest" {
87-
$Metadata.AliasesToExport | Should -Be @("GS","GSou", "SS", "SSou")
88-
}
85+
It "Should update AliasesToExport in the manifest" {
86+
$Metadata.AliasesToExport | Should -Be @("GS","GSou", "SS", "SSou")
8987
}
88+
}
9089

91-
Context "Supports building without a build.psd1" {
92-
Copy-Item $PSScriptRoot\Source1 $PSScriptRoot\Copy1 -Recurse
93-
Remove-Item $PSScriptRoot\Copy1\build.psd1
94-
Rename-Item $PSScriptRoot\Copy1\Source1.psd1 Copy1.psd1
95-
96-
$Build = @{ }
90+
Describe "Supports building without a build.psd1" -Tag Integration {
91+
Copy-Item $PSScriptRoot\Source1 $PSScriptRoot\Copy1 -Recurse
92+
Remove-Item $PSScriptRoot\Copy1\build.psd1
93+
Rename-Item $PSScriptRoot\Copy1\Source1.psd1 Copy1.psd1
9794

98-
It "No longer fails if there's no build.psd1" {
99-
$BuildParameters = @{
100-
SourcePath = "$PSScriptRoot\Copy1\Copy1.psd1"
101-
OutputDirectory = "..\Result1"
102-
VersionedOutputDirectory = $true
103-
}
95+
$Build = @{ }
10496

105-
$Build.Output = Build-Module @BuildParameters -Passthru
97+
It "No longer fails if there's no build.psd1" {
98+
$BuildParameters = @{
99+
SourcePath = "$PSScriptRoot\Copy1\Copy1.psd1"
100+
OutputDirectory = "..\Result1"
101+
VersionedOutputDirectory = $true
106102
}
107103

108-
Remove-Item -Recurse $PSScriptRoot\Copy1
104+
$Build.Output = Build-Module @BuildParameters -Passthru
105+
}
109106

107+
Remove-Item -Recurse $PSScriptRoot\Copy1
110108

111-
It "Creates the same module as with a build.psd1" {
112-
$Build.Metadata = Import-Metadata $Build.Output.Path
113-
}
114109

115-
It "Should update AliasesToExport in the manifest" {
116-
$Build.Metadata.AliasesToExport | Should -Be @("GS", "GSou", "SS", "SSou")
117-
}
110+
It "Creates the same module as with a build.psd1" {
111+
$Build.Metadata = Import-Metadata $Build.Output.Path
112+
}
118113

119-
It "Should update FunctionsToExport in the manifest" {
120-
$Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source")
121-
}
114+
It "Should update AliasesToExport in the manifest" {
115+
$Build.Metadata.AliasesToExport | Should -Be @("GS", "GSou", "SS", "SSou")
116+
}
122117

118+
It "Should update FunctionsToExport in the manifest" {
119+
$Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source")
120+
}
121+
}
122+
123+
Describe "Regression test for #88 not copying prefix files" -Tag Integration, Regression {
124+
$Output = Build-Module $PSScriptRoot\build.psd1 -Passthru
125+
126+
$Metadata = Import-Metadata $Output.Path
127+
128+
It "Should update AliasesToExport in the manifest" {
129+
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")
130+
$ModuleInfo = Get-Content $Module
131+
$ModuleInfo[0] | Should -be "using module Configuration"
123132
}
124133
}

Tests/Integration/build.psd1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
Path = "Source1\Source1.psd1"
33
OutputDirectory = "..\Result1"
44
VersionedOutputDirectory = $true
5+
6+
# This file is not in Source1 it's here next to this build
7+
Prefix = "..\using.ps1"
58
}

Tests/Integration/using.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
using module Configuration

0 commit comments

Comments
 (0)