11# requires -Module ModuleBuilder
22
33Describe " Build-Module With Source1" {
4- Write-Host " Current Modules: `n $ ( Get-Module | Out-String ) " - ForegroundColor DarkGreen - BackgroundColor Yellow
54 Context " When we call Build-Module" {
65 $Output = Build-Module $PSScriptRoot \Source1\build.psd1 - Passthru
76 $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
@@ -13,7 +12,7 @@ Describe "Build-Module With Source1" {
1312 $Metadata = Import-Metadata $Output.Path
1413
1514 It " Should update FunctionsToExport in the manifest" {
16- $Metadata.FunctionsToExport | Should - Be @ (" Get-Finale " , " Get- Source" )
15+ $Metadata.FunctionsToExport | Should - Be @ (" Get-Source" )
1716 }
1817
1918 It " Should update AliasesToExport in the manifest" {
@@ -25,6 +24,56 @@ Describe "Build-Module With Source1" {
2524 }
2625
2726 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+ }
29+ }
30+
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" )
34+
35+ It " Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
36+ $Module | Should -Not - FileContentMatch ' ^Source$'
37+ }
38+
39+ $Metadata = Import-Metadata $Output.Path
40+
41+ It " Should not have any FunctionsToExport if SourceDirectories don't match the PublicFilter" {
42+ $Metadata.FunctionsToExport | Should - Be @ ()
43+ }
44+
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+ }
48+
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+ }
52+ }
53+
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" )
57+
58+ It " Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
59+ $Module | Should -Not - FileContentMatch ' ^Source$'
60+ }
61+
62+ $Metadata = Import-Metadata $Output.Path
63+
64+ It " Should not have any FunctionsToExport if SourceDirectories don't match the PublicFilter" {
65+ $Metadata.FunctionsToExport | Should - Be @ (" GetFinale" , " GetPreview" )
66+ }
67+
68+ It " Should update AliasesToExport in the manifest" {
69+ $Metadata.AliasesToExport | Should - Be @ (" GF" , " GP" )
70+ }
71+
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+ }
75+
76+ It " Will comment out the original using statement in the original positions" {
2877 (Select-String - Pattern " ^#\s*using" - Path $Module ).Count | Should - Be 2
2978 }
3079 }
0 commit comments