Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Other/Full-ModuleTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ if ($PrivateFunctions.count -gt 0) {
$contents = Get-Content -Path $PrivateFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}

foreach ($rule in $rules) {

It “passes the PSScriptAnalyzer Rule $rule“ {

(Invoke-ScriptAnalyzer -Path $PrivateFunction.FullName -IncludeRule $rule.RuleName ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PrivateFunction.FullName -IncludeRule $rule.RuleName ).Count | Should -Be 0

}
}
Expand Down Expand Up @@ -65,13 +65,13 @@ if ($PublicFunctions.count -gt 0) {
$contents = Get-Content -Path $PublicFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}
foreach ($rule in $rules) {

It “passes the PSScriptAnalyzer Rule $rule“ {

(Invoke-ScriptAnalyzer -Path $PublicFunction.FullName -IncludeRule $rule.RuleName ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PublicFunction.FullName -IncludeRule $rule.RuleName ).Count | Should -Be 0

}
}
Expand Down
8 changes: 4 additions & 4 deletions Other/Min-ModuleTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if ($PrivateFunctions.count -gt 0) {
$contents = Get-Content -Path $PrivateFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}


Expand All @@ -53,7 +53,7 @@ if ($PublicFunctions.count -gt 0) {
$contents = Get-Content -Path $PublicFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}

}
Expand All @@ -74,15 +74,15 @@ Describe 'ScriptAnalyzer Rule Testing' {
Context 'Public Functions' {

It 'Passes the Script Analyzer ' {
(Invoke-ScriptAnalyzer -Path $PublicFunctionPath -Recurse ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PublicFunctionPath -Recurse ).Count | Should -Be 0

}
}

Context 'Private Functions' {

It 'Passes the Script Analyzer ' {
(Invoke-ScriptAnalyzer -Path $PrivateFunctionPath ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PrivateFunctionPath ).Count | Should -Be 0

}
}
Expand Down
8 changes: 4 additions & 4 deletions Other/Norm-ModuleTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if ($PrivateFunctions.count -gt 0) {
$contents = Get-Content -Path $PrivateFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}


Expand Down Expand Up @@ -60,7 +60,7 @@ if ($PublicFunctions.count -gt 0) {
$contents = Get-Content -Path $PublicFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}

}
Expand All @@ -81,15 +81,15 @@ Describe 'ScriptAnalyzer Rule Testing' {
Context 'Public Functions' {

It 'Passes the Script Analyzer ' {
(Invoke-ScriptAnalyzer -Path $PublicFunctionPath -Recurse ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PublicFunctionPath -Recurse ).Count | Should -Be 0

}
}

Context 'Private Functions' {

It 'Passes the Script Analyzer ' {
(Invoke-ScriptAnalyzer -Path $PrivateFunctionPath ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PrivateFunctionPath ).Count | Should -Be 0

}
}
Expand Down
8 changes: 4 additions & 4 deletions PesterHelpers.Full.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ if ($PrivateFunctions.count -gt 0) {
$contents = Get-Content -Path $PrivateFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}

foreach ($rule in $rules) {

It “passes the PSScriptAnalyzer Rule $rule“ {

(Invoke-ScriptAnalyzer -Path $PrivateFunction.FullName -IncludeRule $rule.RuleName ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PrivateFunction.FullName -IncludeRule $rule.RuleName ).Count | Should -Be 0

}
}
Expand Down Expand Up @@ -65,13 +65,13 @@ if ($PublicFunctions.count -gt 0) {
$contents = Get-Content -Path $PublicFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}
foreach ($rule in $rules) {

It “passes the PSScriptAnalyzer Rule $rule“ {

(Invoke-ScriptAnalyzer -Path $PublicFunction.FullName -IncludeRule $rule.RuleName ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PublicFunction.FullName -IncludeRule $rule.RuleName ).Count | Should -Be 0

}
}
Expand Down
8 changes: 4 additions & 4 deletions PesterHelpers.Min.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if ($PrivateFunctions.count -gt 0) {
$contents = Get-Content -Path $PrivateFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}


Expand All @@ -53,7 +53,7 @@ if ($PublicFunctions.count -gt 0) {
$contents = Get-Content -Path $PublicFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}

}
Expand All @@ -74,15 +74,15 @@ Describe 'ScriptAnalyzer Rule Testing' {
Context 'Public Functions' {

It 'Passes the Script Analyzer ' {
(Invoke-ScriptAnalyzer -Path $PublicFunctionPath -Recurse ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PublicFunctionPath -Recurse ).Count | Should -Be 0

}
}

Context 'Private Functions' {

It 'Passes the Script Analyzer ' {
(Invoke-ScriptAnalyzer -Path $PrivateFunctionPath ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PrivateFunctionPath ).Count | Should -Be 0

}
}
Expand Down
8 changes: 4 additions & 4 deletions PesterHelpers.Norm.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if ($PrivateFunctions.count -gt 0) {
$contents = Get-Content -Path $PrivateFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}


Expand Down Expand Up @@ -60,7 +60,7 @@ if ($PublicFunctions.count -gt 0) {
$contents = Get-Content -Path $PublicFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
$errors.Count | Should -Be 0
}

}
Expand All @@ -81,15 +81,15 @@ Describe 'ScriptAnalyzer Rule Testing' {
Context 'Public Functions' {

It 'Passes the Script Analyzer ' {
(Invoke-ScriptAnalyzer -Path $PublicFunctionPath -Recurse ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PublicFunctionPath -Recurse ).Count | Should -Be 0

}
}

Context 'Private Functions' {

It 'Passes the Script Analyzer ' {
(Invoke-ScriptAnalyzer -Path $PrivateFunctionPath ).Count | Should Be 0
(Invoke-ScriptAnalyzer -Path $PrivateFunctionPath ).Count | Should -Be 0

}
}
Expand Down
14 changes: 7 additions & 7 deletions Private/Tests/Get-CommonParameter.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@

It "Function $($function.Name) Has show-help comment block" {

$function.Definition.Contains('<#') | should be 'True'
$function.Definition.Contains('#>') | should be 'True'
$function.Definition.Contains('<#') | Should -Be 'True'
$function.Definition.Contains('#>') | Should -Be 'True'
}

It "Function $($function.Name) Has show-help comment block has a.SYNOPSIS" {

$function.Definition.Contains('.SYNOPSIS') -or $function.Definition.Contains('.Synopsis') | should be 'True'
$function.Definition.Contains('.SYNOPSIS') -or $function.Definition.Contains('.Synopsis') | Should -Be 'True'

}

It "Function $($function.Name) Has show-help comment block has an example" {

$function.Definition.Contains('.EXAMPLE') | should be 'True'
$function.Definition.Contains('.EXAMPLE') | Should -Be 'True'
}

It "Function $($function.Name) Is an advanced function" {

$function.CmdletBinding | should be 'True'
$function.Definition.Contains('param') -or $function.Definition.Contains('Param') | should be 'True'
$function.CmdletBinding | Should -Be 'True'
$function.Definition.Contains('param') -or $function.Definition.Contains('Param') | Should -Be 'True'
}

}

}
Expand Down
10 changes: 5 additions & 5 deletions Public/Export/Export-AllModuleFunction.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
[Alias()]
Param
(

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromPipeline=$true,
Expand All @@ -36,12 +36,12 @@
$OutPath
)
$ModuleData = Get-Module $Module -Verbose:$VerbosePreference

If ($null -eq $ModuleData) {throw 'Please Import Module into session'}
else {
Write-Verbose "$ModuleData"
Write-Verbose "$ModuleData"
$PublicFunctions = (Get-command -Module $module).Where{$_.CommandType -ne 'Cmdlet'}

Foreach ($PublicFunction in $PublicFunctions){
Write-Verbose "Found $($PublicFunction.Name) being Exported"
}
Expand All @@ -55,7 +55,7 @@
}

$PublicFunctions | ForEach-Object { Export-Function -Function $_.Name -ResolvedFunction $_ -OutPath $OutPath -Verbose:$VerbosePreference }

$PrivateFunctions | ForEach-Object { Export-Function -Function $_.Name -ResolvedFunction $_ -OutPath $OutPath -PrivateFunction -Verbose:$VerbosePreference }
}
}
32 changes: 15 additions & 17 deletions Public/Export/Export-Function.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@
<#
.Synopsis
Exports a function from a module into a user given path

.Description
As synopsis

.PARAMETER Function
This Parameter takes a String input and is used in Both Parameter Sets

.PARAMETER ResolvedFunction
This should be passed the Function that you want to work with as an object making use of the following
$ResolvedFunction = Get-Command "Command"

.PARAMETER OutPath
This is the location that you want to output all the module files to. It is recommended not to use the same location as where the module is installed.
Also always check the files output what you expect them to.

.PARAMETER PrivateFunction
This is a switch that is used to correctly export Private Functions and is used internally in Export-AllModuleFunction

.EXAMPLE
Export-Function -Function Get-TwitterTweet -OutPath C:\TextFile\

This will export the function into the C:\TextFile\Get\Get-TwitterTweet.ps1 file and also create a basic test file C:\TextFile\Get\Get-TwitterTweet.Tests.ps1

.EXAMPLE
Get-Command -Module SPCSPS | Where-Object {$_.CommandType -eq 'Function'} | ForEach-Object { Export-Function -Function $_.Name -OutPath C:\TextFile\SPCSPS\ }
This will get all the Functions in the SPCSPS module (if it is loaded into memory or in a $env:PSModulePath as required by ModuleAutoLoading) and will export all the Functions into the C:\TextFile\SPCSPS\ folder under the respective Function Verbs. It will also create a basic Tests.ps1 file just like the prior example
Get-Command -Module SPCSPS | Where-Object {$_.CommandType -eq 'Function'} | ForEach-Object { Export-Function -Function $_.Name -OutPath C:\TextFile\SPCSPS\ }

This will get all the Functions in the SPCSPS module (if it is loaded into memory or in a $env:PSModulePath as required by ModuleAutoLoading) and will export all the Functions into the C:\TextFile\SPCSPS\ folder under the respective Function Verbs. It will also create a basic Tests.ps1 file just like the prior example
#>
[cmdletbinding(DefaultParameterSetName='Basic')]

Expand Down Expand Up @@ -59,10 +59,10 @@ Param(
)

$sb = New-Object -TypeName System.Text.StringBuilder

If (!($ResolvedFunction)) { $ResolvedFunction = Get-Command $function}
$code = $ResolvedFunction | Select-Object -ExpandProperty Definition

If (!($PrivateFunction)) {
$PublicOutPath = "$OutPath\Public\"
$ps1 = "$PublicOutPath$($ResolvedFunction.Verb)\$($ResolvedFunction.Name).ps1"
Expand All @@ -72,7 +72,7 @@ $sb = New-Object -TypeName System.Text.StringBuilder
}

$sb.AppendLine("function $function {") | Out-Null

foreach ($line in $code -split '\r?\n') {
$sb.AppendLine('{0}' -f $line) | Out-Null
}
Expand All @@ -84,16 +84,14 @@ $sb = New-Object -TypeName System.Text.StringBuilder

Set-Content -Path $ps1 -Value $($sb.ToString()) -Encoding UTF8
Write-Verbose -Message "Added the content of function $Function into the file"

If(!($PrivateFunction)) {
New-FunctionPesterTest -Function $Function -ResolvedFunction $ResolvedFunction -OutPath $PublicOutPath -Verbose:$VerbosePreference
Write-Verbose -Message "Created a Pester Test file for $Function Under the Basic ParamaterSet"
Write-Verbose -Message "Created a Pester Test file for $Function Under the Basic ParamaterSet"
}
ElseIf ($PrivateFunction) {
New-FunctionPesterTest -Function $Function -ResolvedFunction $ResolvedFunction -PrivateFunction -OutPath $OutPath -Verbose:$VerbosePreference
Write-Verbose -Message "Created a Pester Test file for $Function Under the Passthru ParamaterSet"
Write-Verbose -Message "Created a Pester Test file for $Function Under the Passthru ParamaterSet"
}


}

Loading