Skip to content

Commit 748d622

Browse files
Merge pull request #52 from PowershellFrameworkCollective/development
2.2.5.30
2 parents 4381378 + 84aebee commit 748d622

21 files changed

+252
-100
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ PSModuleDevelopment/PSModuleDevelopment.psproj.bak
2222
PSModuleDevelopment/PSModuleDevelopment.psprojs
2323
PSModuleDevelopment/PSModuleDevelopment.psproj
2424
sh.exe.stackdump
25+
26+
# ignore the TestResults
27+
TestResults/*

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
RootModule = 'PSModuleDevelopment.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '2.2.5.28'
7+
ModuleVersion = '2.2.5.30'
88

99
# ID used to uniquely identify this module
1010
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'

PSModuleDevelopment/PSModuleDevelopment.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$script:PSModuleRoot = $PSScriptRoot
2-
$script:PSModuleVersion = "2.2.5.28"
2+
$script:PSModuleVersion = "2.2.5.30"
33

44
$script:doDotSource = $false
55
if (Get-PSFConfigValue -FullName PSModuleDevelopment.Import.DoDotSource) { $script:doDotSource = $true }
@@ -29,8 +29,8 @@ function Import-PSMDFile
2929
$Path
3030
)
3131

32-
if ($script:doDotSource) { . $Path }
33-
else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($Path))), $null, $null) }
32+
if ($script:doDotSource) { . (Resolve-Path $Path) }
33+
else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($(Resolve-Path $Path)))), $null, $null) }
3434
}
3535
#endregion Helper function
3636

@@ -53,4 +53,4 @@ foreach ($function in (Get-ChildItem "$PSModuleRoot\functions" -Recurse -File -F
5353
#endregion Load functions
5454

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

PSModuleDevelopment/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## 2.2.5.30 (September 12th, 2018)
3+
- Upd: Template integrated NUnit Test Reporting
4+
- Upd: Template support for compiled module files
5+
26
## 2.2.5.28 (September 08th, 2018)
37
- Fix: Template CommandTest would throw an exception due to missing quotes on a string index
48

PSModuleDevelopment/tests/pester.ps1

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,82 @@
11
param (
2-
[ValidateSet('None', 'Default', 'Passed', 'Failed', 'Pending', 'Skipped', 'Inconclusive', 'Describe', 'Context', 'Summary', 'Header', 'Fails', 'All')]
3-
[string]
4-
$Show = "None",
5-
6-
[ValidateSet('Everything', 'Functions', 'General')]
7-
[string]
8-
$Run = "Everything",
9-
10-
[string]
11-
$Filter = "*.Tests.ps1"
2+
[ValidateSet('None', 'Default', 'Passed', 'Failed', 'Pending', 'Skipped', 'Inconclusive', 'Describe', 'Context', 'Summary', 'Header', 'Fails', 'All')]
3+
[string]
4+
$Show = "None",
5+
6+
[ValidateSet('Everything', 'Functions', 'General')]
7+
[string]
8+
$Run = "Everything",
9+
10+
[string]
11+
$Filter = "*.Tests.ps1"
1212
)
1313

14-
Write-Host "Starting Tests" -ForegroundColor Green
14+
Write-PSFMessage -Level Host -Message "Starting Tests"
1515

16-
Write-Host "Importing Module" -ForegroundColor Cyan
16+
Write-PSFMessage -Level Host -Message "Importing Module"
1717

1818
Remove-Module PSModuleDevelopment -ErrorAction Ignore
1919
Import-Module "$PSScriptRoot\..\PSModuleDevelopment.psd1"
2020
Import-Module "$PSScriptRoot\..\PSModuleDevelopment.psm1" -Force
2121

22+
Write-PSFMessage -Level Host -Message "Creating test result folder"
23+
$null = New-Item -Path "$PSScriptRoot\..\.." -Name TestResults -ItemType Directory -Force
24+
2225
$totalFailed = 0
2326
$totalRun = 0
2427

2528
$testresults = @()
2629

27-
if ($Run -match "Everything|General")
28-
{
29-
Write-PSFMessage -Level Important -Message "Modules imported, proceeding with general tests"
30-
foreach ($file in (Get-ChildItem "$PSScriptRoot\general" -Filter $Filter))
31-
{
32-
Write-PSFMessage -Level Significant -Message " Executing <c='em'>$($file.Name)</c>"
33-
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
34-
foreach ($result in $results)
35-
{
36-
$totalRun += $result.TotalCount
37-
$totalFailed += $result.FailedCount
38-
$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
39-
$name = $_.Name
40-
$testresults += [pscustomobject]@{
41-
Describe = $_.Describe
42-
Context = $_.Context
43-
Name = "It $name"
44-
Result = $_.Result
45-
Message = $_.FailureMessage
46-
}
47-
}
48-
}
49-
}
30+
if ($Run -match "Everything|General") {
31+
Write-PSFMessage -Level Important -Message "Modules imported, proceeding with general tests"
32+
foreach ($file in (Get-ChildItem "$PSScriptRoot\general" -Filter $Filter)) {
33+
Write-PSFMessage -Level Significant -Message " Executing <c='em'>$($file.Name)</c>"
34+
$TestOuputFile = Join-Path "$PSScriptRoot\..\..\TestResults" "TEST-$($file.BaseName).xml"
35+
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru -OutputFile $TestOuputFile -OutputFormat NUnitXml
36+
foreach ($result in $results) {
37+
$totalRun += $result.TotalCount
38+
$totalFailed += $result.FailedCount
39+
$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
40+
$name = $_.Name
41+
$testresults += [pscustomobject]@{
42+
Describe = $_.Describe
43+
Context = $_.Context
44+
Name = "It $name"
45+
Result = $_.Result
46+
Message = $_.FailureMessage
47+
}
48+
}
49+
}
50+
}
5051
}
5152

52-
if ($Run -match "Everything|Functions")
53-
{
54-
Write-PSFMessage -Level Important -Message "Proceeding with individual tests"
55-
foreach ($file in (Get-ChildItem "$PSScriptRoot\functions" -Recurse -File -Filter $Filter))
56-
{
57-
Write-PSFMessage -Level Significant -Message " Executing $($file.Name)"
58-
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
59-
foreach ($result in $results)
60-
{
61-
$totalRun += $result.TotalCount
62-
$totalFailed += $result.FailedCount
63-
$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
64-
$name = $_.Name
65-
$testresults += [pscustomobject]@{
66-
Describe = $_.Describe
67-
Context = $_.Context
68-
Name = "It $name"
69-
Result = $_.Result
70-
Message = $_.FailureMessage
71-
}
72-
}
73-
}
74-
}
53+
if ($Run -match "Everything|Functions") {
54+
Write-PSFMessage -Level Important -Message "Proceeding with individual tests"
55+
foreach ($file in (Get-ChildItem "$PSScriptRoot\functions" -Recurse -File -Filter $Filter)) {
56+
Write-PSFMessage -Level Significant -Message " Executing $($file.Name)"
57+
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
58+
foreach ($result in $results) {
59+
$totalRun += $result.TotalCount
60+
$totalFailed += $result.FailedCount
61+
$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
62+
$name = $_.Name
63+
$testresults += [pscustomobject]@{
64+
Describe = $_.Describe
65+
Context = $_.Context
66+
Name = "It $name"
67+
Result = $_.Result
68+
Message = $_.FailureMessage
69+
}
70+
}
71+
}
72+
}
7573
}
7674

7775
$testresults | Sort-Object Describe, Context, Name, Result, Message | Format-List
7876

7977
if ($totalFailed -eq 0) { Write-PSFMessage -Level Critical -Message "All <c='em'>$totalRun</c> tests executed without a single failure!" }
8078
else { Write-PSFMessage -Level Critical -Message "<c='em'>$totalFailed tests</c> out of <c='sub'>$totalRun</c> tests failed!" }
8179

82-
if ($totalFailed -gt 0)
83-
{
84-
throw "$totalFailed / $totalRun tests failed!"
85-
}
80+
if ($totalFailed -gt 0) {
81+
throw "$totalFailed / $totalRun tests failed!"
82+
}

PSModuleDevelopment/xml/PSModuleDevelopment.Types.ps1xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Types>
33
<!-- PSModuleDevelopment.Template.ParameterScript -->
44
<Type>

build/vsts-prerequisites.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
Write-Host "Installing Pester" -ForegroundColor Cyan
22
Install-Module Pester -Force -SkipPublisherCheck
3+
Write-Host "Installing PSScriptAnalyzer" -ForegroundColor Cyan
4+
Install-Module PSScriptAnalyzer -Force -SkipPublisherCheck
35
Write-Host "Installing PSFramework" -ForegroundColor Cyan
46
Install-Module PSFramework -Force -SkipPublisherCheck

templates/PSFModule/PSMDTemplate.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,13 @@
1919
psframework = {
2020
(Get-Module PSFramework).Version.ToString()
2121
}
22+
testfolder = {
23+
24+
}
25+
testresults = {
26+
@'
27+
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
28+
'@
29+
}
2230
}
2331
}

templates/PSFModule/internal/configurations/configuration.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ feel totally free to split them into multiple files.
99
<#
1010
# Example Configuration
1111
Set-PSFConfig -Module 'þnameþ' -Name 'Example.Setting' -Value 10 -Initialize -Validation 'integer' -Handler { } -Description "Example configuration setting. Your module can then use the setting using 'Get-PSFConfigValue'"
12-
#>
12+
#>
13+
14+
Set-PSFConfig -Module 'þnameþ' -Name 'Import.DoDotSource' -Value $false -Initialize -Validation 'bool' -Description "Whether the module files should be dotsourced on import. By default, the files of this module are read as string value and invoked, which is faster but worse on debugging."
15+
Set-PSFConfig -Module 'þnameþ' -Name 'Import.IndividualFiles' -Value $false -Initialize -Validation 'bool' -Description "Whether the module files should be imported individually. During the module build, all module code is compiled into few files, which are imported instead by default. Loading the compiled versions is faster, using the individual files is easier for debugging and testing out adjustments."

templates/PSFModule/readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# PSFModule guidance
2+
3+
This is a finished module layout optimized for implementing the PSFramework.
4+
5+
If you don't care to deal with the details, this is what you need to do to get started seeing results:
6+
7+
- Add the functions you want to publish to `/functions/`
8+
- Update the `FunctionsToExport` node in the module manifest (þnameþ.psd1). All functions you want to publish should be in a list.
9+
- Add internal helper functions the user should not see to `/internal/functions/`
10+
11+
## Path Warning
12+
13+
> If you want your module to be compatible with Linux and MacOS, keep in mind that those OS are case sensitive for paths and files.
14+
15+
`Import-ModuleFile` is preconfigured to resolve the path of the files specified, so it will reliably convert weird path notations the system can't handle.
16+
Content imported through that command thus need not mind the path separator.
17+
If you want to make sure your code too will survive OS-specific path notations, get used to using `Resolve-path` or the more powerful `Resolve-PSFPath`.

0 commit comments

Comments
 (0)