Skip to content

Commit 1165c6b

Browse files
committed
Fix the tests
1 parent 9c53092 commit 1165c6b

File tree

5 files changed

+216
-221
lines changed

5 files changed

+216
-221
lines changed

Source/Public/Invoke-ScriptGenerator.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ function Invoke-ScriptGenerator {
8080
}
8181

8282
# Find that generator...
83-
$GeneratorCmd = Get-Command -Name ${Generator} -ParameterType Ast -ErrorAction Ignore
84-
| Where-Object { $_.OutputType.Name -eq "TextReplacement" }
83+
$GeneratorCmd = Get-Command -Name ${Generator} <# -CommandType Function #> -ParameterType Ast -ErrorAction Ignore
84+
| Where-Object { $_.OutputType.Name -eq "TextReplacement" -or ($_.CommandType -eq "Alias" -and $_.Definition -like "PesterMock*" ) }
8585
| Select-Object -First 1
8686

8787
if (-not $GeneratorCmd) {

Tests/Public/Build-Module.Tests.ps1

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,31 @@ Describe "Build-Module" {
123123
Push-Location TestDrive:/ -StackName BuildModuleTest
124124
New-Item -ItemType Directory -Path TestDrive:/Output/MyModule/1.0.0/ -Force
125125

126-
Mock ConvertToAst {
127-
[PSCustomObject]@{
128-
PSTypeName = "PoshCode.ModuleBuilder.ParseResults"
129-
ParseErrors = $null
130-
Tokens = $null
131-
AST = { }.AST
126+
127+
InModuleScope ModuleBuilder {
128+
Mock ConvertToAst {
129+
[PSCustomObject]@{
130+
PSTypeName = "PoshCode.ModuleBuilder.ParseResults"
131+
ParseErrors = $null
132+
Tokens = $null
133+
AST = { }.AST
134+
}
132135
}
133-
}
134-
Mock GetCommandAlias { @{'Get-MyInfo' = @('GMI') } }
135-
Mock InitializeBuild {
136-
# These are actually all the values that we need
137-
[PSCustomObject]@{
138-
OutputDirectory = "TestDrive:/Output"
139-
Name = "MyModule"
140-
Version = [Version]"1.0.0"
141-
Target = "CleanBuild"
142-
ModuleBase = "TestDrive:/MyModule/"
143-
CopyDirectories = @()
144-
Encoding = "UTF8"
145-
PublicFilter = "Public/*.ps1"
136+
Mock Update-AliasesToExport
137+
Mock InitializeBuild {
138+
# These are actually all the values that we need
139+
[PSCustomObject]@{
140+
OutputDirectory = "TestDrive:/Output"
141+
Name = "MyModule"
142+
Version = [Version]"1.0.0"
143+
Target = "CleanBuild"
144+
ModuleBase = "TestDrive:/MyModule/"
145+
CopyDirectories = @()
146+
Encoding = "UTF8"
147+
PublicFilter = "Public/*.ps1"
148+
}
146149
}
147150
}
148-
149151
Mock Push-Location {}
150152

151153
# So it doesn't have to exist
@@ -181,7 +183,7 @@ Describe "Build-Module" {
181183
Assert-MockCalled ConvertToAst -Scope Context
182184
}
183185

184-
It "Should call Move-UsingStatement to move the using statements, just in case" {
186+
It "Should call Move-UsingStatement to move the using statements" {
185187
Assert-MockCalled Move-UsingStatement -Parameter {
186188
$AST.Extent.Text -eq "{ }"
187189
} -Scope Context
@@ -197,10 +199,10 @@ Describe "Build-Module" {
197199
} -Scope Context
198200
}
199201

200-
It "Should call Update-Metadata to set the AliasesToExport" {
201-
Assert-MockCalled Update-Metadata -Parameter {
202-
$PropertyName -eq "AliasesToExport"
203-
} -Scope Context
202+
It "Should call Update-AliasesToExport to update aliases" {
203+
Assert-MockCalled Update-AliasesToExport -Parameter {
204+
$AST.Extent.Text -eq "{ }"
205+
}
204206
}
205207
}
206208

Tests/Public/ConvertTo-SourceLineNumber.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Describe "ConvertTo-SourceLineNumber" {
6969
Function = 'Get-Source'
7070
# these are pipeline bound
7171
File = $Convert_LineNumber_ModulePath
72-
Line = 48 # 1 offset with the Using Statement introduced in MoveUsingStatements
72+
Line = 48 # 1 offset with the Using Statement introduced in MoveUsingStatement
7373
}
7474

7575
$SourceLocation = $PesterMiss | Convert-LineNumber -Passthru

Tests/Private/MoveUsingStatements.Tests.ps1 renamed to Tests/Public/Move-UsingStatement.Tests.ps1.old

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
#requires -Module ModuleBuilder
2-
Describe "MoveUsingStatements" {
2+
Describe "Move-UsingStatement" {
33
BeforeAll {
4-
$CommandInfo = InModuleScope ModuleBuilder { Get-Command MoveUsingStatements }
4+
$CommandInfo = InModuleScope ModuleBuilder { Get-Command Move-UsingStatement }
55
}
66

77
Context "Necessary Parameters" {
88

9-
It 'has a mandatory AST parameter' {
10-
$AST = $CommandInfo.Parameters['AST']
9+
It 'has a mandatory InputObject parameter' {
10+
$AST = $CommandInfo.Parameters['InputObject']
1111
$AST | Should -Not -BeNullOrEmpty
1212
$AST.ParameterType | Should -Be ([System.Management.Automation.Language.Ast])
1313
$AST.Attributes.Where{ $_ -is [Parameter] }.Mandatory | Should -Be $true
1414
}
15-
16-
It "has an optional string Encoding parameter" {
17-
$Encoding = $CommandInfo.Parameters['Encoding']
18-
$Encoding | Should -Not -BeNullOrEmpty
19-
$Encoding.ParameterType | Should -Be ([String])
20-
$Encoding.Attributes.Where{$_ -is [Parameter]}.Mandatory | Should -Be $False
21-
}
2215
}
2316

2417
Context "Moving Using Statements to the beginning of the file" {
@@ -111,7 +104,7 @@ Describe "MoveUsingStatements" {
111104
$ErrorFound.Count | Should -Be $ErrorBefore
112105

113106
# After
114-
&$MoveUsingStatementsCmd -RootModule $testModuleFile
107+
&$MoveUsingStatementCmd -RootModule $testModuleFile
115108

116109
$null = [System.Management.Automation.Language.Parser]::ParseFile(
117110
$testModuleFile,
@@ -144,7 +137,7 @@ Describe "MoveUsingStatements" {
144137
$PSM1File = "using namespace System.IO; function x {}"
145138
Set-Content $testModuleFile -value $PSM1File -Encoding UTF8
146139

147-
&$MoveUsingStatementsCmd -RootModule $testModuleFile -Debug
140+
&$MoveUsingStatementCmd -RootModule $testModuleFile -Debug
148141

149142
(Get-Content -Raw $testModuleFile).Trim() | Should -Be $PSM1File
150143

0 commit comments

Comments
 (0)