Skip to content

Commit c14dc14

Browse files
author
Friedrich Weinmann
committed
Implemented changes to make tests happy
1 parent b0bf0ff commit c14dc14

24 files changed

+121
-71
lines changed

PSModuleDevelopment/PSModuleDevelopment.psm1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
$script:PSModuleDevelopmentModuleRoot = $PSScriptRoot
2-
$script:PSModuleDevelopmentModuleVersion = '2.0.0.0'
1+
$script:PSModuleRoot = $PSScriptRoot
2+
$script:PSModuleVersion = "2.0.0.0"
33

44
$script:doDotSource = $false
55
if (Get-PSFConfigValue -Name PSModuleDevelopment.Import.DoDotSource) { $script:doDotSource = $true }
@@ -36,14 +36,14 @@ function Import-PSMDFile
3636

3737

3838
# Perform Actions before loading the rest of the content
39-
. Import-PSMDFile -Path "$PSModuleDevelopmentModuleRoot\internal\scripts\preload.ps1"
39+
. Import-PSMDFile -Path "$PSModuleRoot\internal\scripts\preload.ps1"
4040

4141
#region Load functions
42-
foreach ($function in (Get-ChildItem "$PSModuleDevelopmentModuleRoot\functions" -Recurse -File -Filter "*.ps1"))
42+
foreach ($function in (Get-ChildItem "$PSModuleRoot\functions" -Recurse -File -Filter "*.ps1"))
4343
{
4444
. Import-PSMDFile -Path $function.FullName
4545
}
4646
#endregion Load functions
4747

4848
# Perform Actions after loading the module contents
49-
. Import-PSMDFile -Path "$PSModuleDevelopmentModuleRoot\internal\scripts\postload.ps1"
49+
. Import-PSMDFile -Path "$PSModuleRoot\internal\scripts\postload.ps1"

PSModuleDevelopment/PSModuleDevelopment.psproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Folder>functions\performance</Folder>
1212
<Folder>functions\help</Folder>
1313
<Folder>snippets</Folder>
14-
<Folder>functions\wix</Folder>
14+
<Folder>internal\functions\wix</Folder>
1515
<Folder>internal</Folder>
1616
<Folder>internal\configurations</Folder>
1717
<Folder>functions\format</Folder>
@@ -22,6 +22,7 @@
2222
<Folder>tests</Folder>
2323
<Folder>tests\functions</Folder>
2424
<Folder>tests\general</Folder>
25+
<Folder>internal\functions</Folder>
2526
</Folders>
2627
<Files>
2728
<File Build="2">PSModuleDevelopment.psd1</File>
@@ -38,10 +39,10 @@
3839
<File Build="2" Shared="False" ReferenceFunction="Invoke-New-PssModuleProject_ps1">functions\utility\New-PssModuleProject.ps1</File>
3940
<File Build="2">en-us\about_psmoduledevelopment.help.txt</File>
4041
<File Build="2" Shared="False" ReferenceFunction="Invoke-Set-PSMDModulePath_ps1">functions\utility\Set-PSMDModulePath.ps1</File>
41-
<File Build="2" Shared="True" ReferenceFunction="Invoke-Get-PSMDWixConfig_ps1">functions\wix\Get-PSMDWixConfig.ps1</File>
42-
<File Build="2" Shared="True" ReferenceFunction="Invoke-Set-PSMDWixConfig_ps1">functions\wix\Set-PSMDWixConfig.ps1</File>
43-
<File Build="2" Shared="True" ReferenceFunction="Invoke-Invoke-PSMDWixBuild_ps1">functions\wix\Invoke-PSMDWixBuild.ps1</File>
44-
<File Build="2" Shared="False" ReferenceFunction="Invoke-Invoke-PSMDWixBuild2_ps1">functions\wix\Invoke-PSMDWixBuild2.ps1</File>
42+
<File Build="2" Shared="True" ReferenceFunction="Invoke-Get-PSMDWixConfig_ps1">internal\functions\wix\Get-PSMDWixConfig.ps1</File>
43+
<File Build="2" Shared="True" ReferenceFunction="Invoke-Set-PSMDWixConfig_ps1">internal\functions\wix\Set-PSMDWixConfig.ps1</File>
44+
<File Build="2" Shared="True" ReferenceFunction="Invoke-Invoke-PSMDWixBuild_ps1">internal\functions\wix\Invoke-PSMDWixBuild.ps1</File>
45+
<File Build="2" Shared="False" ReferenceFunction="Invoke-Invoke-PSMDWixBuild2_ps1">internal\functions\wix\Invoke-PSMDWixBuild2.ps1</File>
4546
<File Build="2" Shared="False" ReferenceFunction="Invoke-wix_ps1">internal\configurations\wix.ps1</File>
4647
<File Build="2" Shared="False" ReferenceFunction="Invoke-debug_ps1">internal\configurations\debug.ps1</File>
4748
<File Build="2" Shared="False" ReferenceFunction="Invoke-license_ps1">internal\scripts\license.ps1</File>

PSModuleDevelopment/en-us/about_psmoduledevelopment.help.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ LONG DESCRIPTION
132132
# The Need for Speed #
133133
#-------------------------------------------------------------------------#
134134

135-
Speed matters.
135+
Speed matters.
136136
In order to develop high performance code however, you need to have the
137137
tools to measure speed accurately. PowerShell has out of the box a tool
138138
that helps with that: 'Measure-Command'
@@ -206,7 +206,7 @@ LONG DESCRIPTION
206206
- New Alias: hex --> Get-HelpEx
207207
Because getting help should be simple.
208208

209-
1.2.0.0 (August 15th, 2016):
209+
1.2.0.0 (August 15th, 2016):
210210
- New function: Get-ExHelp
211211
Provides localized help to better test modules with localized help
212212
content.

PSModuleDevelopment/functions/assembly/Expand-PSMDTypeName.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
{
2626
foreach ($item in $InputObject)
2727
{
28-
if ($item -eq $null) { continue }
28+
if ($null -eq $item) { continue }
2929

3030
$type = $item.GetType()
3131
if ($type.FullName -eq "System.RuntimeType") { $type = $item }

PSModuleDevelopment/functions/assembly/Get-PSMDConstructor.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
{
4242
foreach ($item in $InputObject)
4343
{
44-
if ($item -eq $null) { continue }
44+
if ($null -eq $item) { continue }
4545
if ($item -is [System.Type]) { $type = $item }
4646
else { $type = $item.GetType() }
4747

PSModuleDevelopment/functions/format/New-PSMDFormatTableDefinition.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
3838
Creates a format xml that only includes the columns LastWriteTime, FullName
3939
#>
40+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
4041
[CmdletBinding()]
4142
Param (
4243
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]

PSModuleDevelopment/functions/moduledebug/Remove-PSMDModuleDebug.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
1010
.PARAMETER Name
1111
Name of modules whose debugging configuration should be removed.
12+
13+
.PARAMETER Confirm
14+
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.
15+
16+
.PARAMETER WhatIf
17+
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.
1218
1319
.EXAMPLE
1420
PS C:\> Remove-PSMDModuleDebug -Name "cPSNetwork"

PSModuleDevelopment/functions/moduledebug/Set-PSMDModuleDebug.ps1

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@
2828
.PARAMETER PostImportAction
2929
Any scriptblock that should run after importing the module.
3030
Only used when importing modules using the "Invoke-ModuleDebug" funtion, as his used for modules set to auto-import.
31+
32+
.PARAMETER Priority
33+
When importing modules in a debugging context, they are imported in the order of their priority.
34+
The lower the number, the sooner it is imported.
3135
3236
.PARAMETER AllAutoImport
3337
Changes all registered modules to automatically import on powershell launch.
3438
3539
.PARAMETER NoneAutoImport
3640
Changes all registered modules to not automatically import on powershell launch.
41+
42+
.PARAMETER Confirm
43+
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.
44+
45+
.PARAMETER WhatIf
46+
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.
3747
3848
.EXAMPLE
3949
PS C:\> Set-PSMDModuleDebug -Name 'cPSNetwork' -AutoImport
@@ -60,7 +70,8 @@
6070
Author: Friedrich Weinmann
6171
Created on: August 7th, 2016
6272
#>
63-
[CmdletBinding(DefaultParameterSetName = "Name")]
73+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
74+
[CmdletBinding(DefaultParameterSetName = "Name", SupportsShouldProcess = $true)]
6475
Param (
6576
[Parameter(Mandatory = $true, Position = 0, ParameterSetName = "Name")]
6677
[Alias('n')]
@@ -106,25 +117,31 @@
106117
if ($AllAutoImport)
107118
{
108119
$allModules = Import-Clixml $PSModuleDevelopment_ModuleConfigPath
109-
foreach ($module in $allModules)
120+
if ($PSCmdlet.ShouldProcess(($allModules.Name -join ", "), "Configuring modules to automatically import"))
110121
{
111-
$module.AutoImport = $true
122+
foreach ($module in $allModules)
123+
{
124+
$module.AutoImport = $true
125+
}
126+
Export-Clixml -InputObject $allModules -Path $PSModuleDevelopment_ModuleConfigPath
112127
}
113-
Export-Clixml -InputObject $allModules -Path $PSModuleDevelopment_ModuleConfigPath
114128
}
115129
#endregion AllAutoImport
116130

117-
#region AllAutoImport
131+
#region NoneAutoImport
118132
if ($NoneAutoImport)
119133
{
120134
$allModules = Import-Clixml $PSModuleDevelopment_ModuleConfigPath
121-
foreach ($module in $allModules)
135+
if ($PSCmdlet.ShouldProcess(($allModules.Name -join ", "), "Configuring modules to not automatically import"))
122136
{
123-
$module.AutoImport = $false
137+
foreach ($module in $allModules)
138+
{
139+
$module.AutoImport = $false
140+
}
141+
Export-Clixml -InputObject $allModules -Path $PSModuleDevelopment_ModuleConfigPath
124142
}
125-
Export-Clixml -InputObject $allModules -Path $PSModuleDevelopment_ModuleConfigPath
126143
}
127-
#endregion AllAutoImport
144+
#endregion NoneAutoImport
128145

129146
#region Name
130147
# Import all module-configurations
@@ -133,11 +150,11 @@
133150
# If a configuration already exists, change only those values that were specified
134151
if ($module = $allModules | Where-Object { $_.Name -eq $Name })
135152
{
136-
if ($PSBoundParameters.ContainsKey("AutoImport")) { $module.AutoImport = $AutoImport.ToBool() }
137-
if ($PSBoundParameters.ContainsKey("DebugMode")) { $module.DebugMode = $DebugMode.ToBool() }
138-
if ($PSBoundParameters.ContainsKey("PreImportAction")) { $module.PreImportAction = $PreImportAction }
139-
if ($PSBoundParameters.ContainsKey("PostImportAction")) { $module.PostImportAction = $PostImportAction }
140-
if ($PSBoundParameters.ContainsKey("Priority")) { $module.Priority = $Priority }
153+
if (Test-PSFParameterBinding -ParameterName "AutoImport") { $module.AutoImport = $AutoImport.ToBool() }
154+
if (Test-PSFParameterBinding -ParameterName "DebugMode") { $module.DebugMode = $DebugMode.ToBool() }
155+
if (Test-PSFParameterBinding -ParameterName "PreImportAction") { $module.PreImportAction = $PreImportAction }
156+
if (Test-PSFParameterBinding -ParameterName "PostImportAction") { $module.PostImportAction = $PostImportAction }
157+
if (Test-PSFParameterBinding -ParameterName "Priority") { $module.Priority = $Priority }
141158
}
142159
# If no configuration exists yet, create a new one with all parameters as specified
143160
else
@@ -154,7 +171,10 @@
154171

155172
# Add new module configuration to all (if any) other previous configurations and export it to config file
156173
$newModules = @(($allModules | Where-Object { $_.Name -ne $Name }), $module)
157-
Export-Clixml -InputObject $newModules -Path $PSModuleDevelopment_ModuleConfigPath
174+
if ($PSCmdlet.ShouldProcess($name, "Changing debug settings for module"))
175+
{
176+
Export-Clixml -InputObject $newModules -Path $PSModuleDevelopment_ModuleConfigPath
177+
}
158178
#endregion Name
159179
}
160180
Set-Alias -Name smd -Value Set-PSMDModuleDebug -Option AllScope -Scope Global

PSModuleDevelopment/functions/performance/Measure-PSMDCommandEx.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#>
5555
DynamicParam
5656
{
57-
# Create the dictionary
57+
# Create the dictionary
5858
$______RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
5959

6060
#region Prepare ScriptBlock Parameter

PSModuleDevelopment/functions/refactor/Rename-PSMDParameter.ps1

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
6060
Renames the parameter 'Foo' of the command 'Get-Test' to 'Bar' for all scripts stored in 'C:\Scripts\Modules\MyModule'
6161
#>
62+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
63+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSupportsShouldProcess", "")]
64+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "")]
65+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseOutputTypeCorrectly", "")]
6266
[CmdletBinding()]
6367
Param (
6468
[Parameter(Mandatory = $true)]
@@ -265,7 +269,7 @@
265269
foreach ($property in $Ast.PSObject.Properties)
266270
{
267271
if ($property.Name -eq "Parent") { continue }
268-
if ($property.Value -eq $null) { continue }
272+
if ($null -eq $property.Value) { continue }
269273

270274
if (Get-Member -InputObject $property.Value -Name GetEnumerator -MemberType Method)
271275
{
@@ -303,7 +307,7 @@
303307
if ($name -notlike "-*") { $name = "-$name" }
304308

305309
$length = $Ast.Extent.EndOffset - $Ast.Extent.StartOffset
306-
if ($Ast.Argument -ne $null) { $length = $Ast.Argument.Extent.StartOffset - $Ast.Extent.StartOffset - 1 }
310+
if ($null -ne $Ast.Argument) { $length = $Ast.Argument.Extent.StartOffset - $Ast.Extent.StartOffset - 1 }
307311

308312
Add-FileReplacement -Path $Ast.Extent.File -Start $Ast.Extent.StartOffset -Length $length -NewContent $name
309313
}
@@ -406,6 +410,7 @@
406410

407411
function Apply-FileReplacement
408412
{
413+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseApprovedVerbs", "")]
409414
[CmdletBinding()]
410415
Param (
411416
[bool]
@@ -466,22 +471,6 @@
466471
}
467472
}
468473

469-
<#
470-
$param = $com.Parameters.$Name
471-
if ($param -eq $null)
472-
{
473-
Stop-PSFFunction -Message "Parameter $param not found on command $Command" -EnableException $EnableException -Category ObjectNotFound -Tag "fail", "input"
474-
return
475-
}
476-
477-
$names = @()
478-
$names += $param.Name
479-
foreach ($alias in $param.Attributes.AliasNames)
480-
{
481-
if ($alias.Length -gt 0) { $names += $alias }
482-
}
483-
#>
484-
485474
$files = Get-ChildItem -Path $Path -Recurse | Where-Object Extension -Match "\.ps1|\.psm1"
486475

487476
$issues = @()

0 commit comments

Comments
 (0)