Skip to content

Commit dade014

Browse files
authored
Add more tests to raise coverage (#383)
:shipit:
1 parent bc25ba5 commit dade014

File tree

72 files changed

+4796
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+4796
-105
lines changed

.build/tasks/ChocolateyPackage.build.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ task copy_paths_to_choco_staging {
130130
$packagesToCopyTo = [string[]]$copyItem.packageName
131131
}
132132

133-
if ($packageName.exclude)
133+
if ($copyItem.Exclude)
134134
{
135135
$CopyFoldersToChocoParams['exclude'] = $copyItem.exclude
136136
}
137137

138-
if ($packageName.Force)
138+
if ($copyItem.Force)
139139
{
140140
$CopyFoldersToChocoParams['Force'] = $copyItem.Force
141141
}

.build/tasks/JaCoCo.coverage.build.ps1

+2-3
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,13 @@ task Convert_Pester_Coverage {
253253

254254
$CodeCoverageThreshold = Get-CodeCoverageThreshold @GetCodeCoverageThresholdParameters
255255

256-
"`tCode Coverage Threshold = '$CodeCoverageThreshold'"
257-
258256
if (-not $CodeCoverageThreshold)
259257
{
260258
$CodeCoverageThreshold = 0
261259
}
262260

261+
"`tCode Coverage Threshold = '$CodeCoverageThreshold'"
262+
263263
$PesterOutputFolder = Get-SamplerAbsolutePath -Path $PesterOutputFolder -RelativeTo $OutputDirectory
264264
"`tPester Output Folder = '$PesterOutputFolder'"
265265

@@ -450,7 +450,6 @@ task Convert_Pester_Coverage {
450450
$originalXml.Load($CodeCoverageOutputFile)
451451

452452
$codeCoverageOutputBackupFile = $CodeCoverageOutputFile -replace '\.xml', '.xml.bak'
453-
$newCoverageFilePath = Join-Path -Path $PesterOutputFolder -ChildPath $codeCoverageOutputBackupFile
454453

455454
Write-Build -Color 'DarkGray' -Text "`tWriting a backup of original code coverage file to '$codeCoverageOutputBackupFile'."
456455

.build/tasks/Set-BuildEnvironment.BuildHelpers.build.ps1

-32
This file was deleted.

.build/tasks/release.module.build.ps1

+53-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,56 @@
1+
<#
2+
.SYNOPSIS
3+
Tasks for releasing modules.
4+
5+
.PARAMETER OutputDirectory
6+
The base directory of all output. Defaults to folder 'output' relative to
7+
the $BuildRoot.
8+
9+
.PARAMETER BuiltModuleSubdirectory
10+
The parent path of the module to be built.
11+
12+
.PARAMETER VersionedOutputDirectory
13+
If the module should be built using a version folder, e.g. ./MyModule/1.0.0.
14+
Defaults to $true.
15+
16+
.PARAMETER ChangelogPath
17+
The path to and the name of the changelog file. Defaults to 'CHANGELOG.md'.
18+
19+
.PARAMETER ReleaseNotesPath
20+
The path to and the name of the release notes file. Defaults to 'ReleaseNotes.md'.
21+
22+
.PARAMETER ProjectName
23+
The project name.
24+
25+
.PARAMETER ModuleVersion
26+
The module version that was built.
27+
28+
.PARAMETER GalleryApiToken
29+
The module version that was built.
30+
31+
.PARAMETER NuGetPublishSource
32+
The source to publish nuget packages. Defaults to https://www.powershellgallery.com.
33+
34+
.PARAMETER PSModuleFeed
35+
The name of the feed (repository) that is passed to command Publish-Module.
36+
Defaults to 'PSGallery'.
37+
38+
.PARAMETER SkipPublish
39+
If publishing should be skipped. Defaults to $false.
40+
41+
.PARAMETER PublishModuleWhatIf
42+
If the publish command will be run with '-WhatIf' to show what will happen
43+
during publishing. Defaults to $false.
44+
45+
.PARAMETER ChocolateyBuildOutput
46+
Sub-Folder (or absolute path) of the Chocolatey build output folder (relative
47+
to $OutputDirectory). Contain the path to one or more Chocolatey packages.
48+
This variable $ChocolateyBuildOutput also used to determine if the repository
49+
is building a Chocolatey package. Defaults to 'choco'.
50+
#>
51+
152
param
253
(
3-
# Base directory of all output (default to 'output')
454
[Parameter()]
555
[string]
656
$OutputDirectory = (property OutputDirectory (Join-Path $BuildRoot 'output')),
@@ -46,9 +96,6 @@ param
4696

4797
[Parameter()]
4898
[string]
49-
# Sub-Folder (or absolute path) of the Chocolatey build output folder (relative to $OutputDirectory)
50-
# Contain the path to one or more Chocolatey packages.
51-
# This variable here is used to determine if the repository is building a Chocolatey package.
5299
$ChocolateyBuildOutput = (property ChocolateyBuildOutput 'choco')
53100
)
54101

@@ -159,6 +206,7 @@ task Create_changelog_release_output {
159206
}
160207
}
161208

209+
# Synopsis: Publish Nuget package to a gallery.
162210
task publish_nupkg_to_gallery -if ($GalleryApiToken -and (Get-Command -Name 'nuget' -ErrorAction 'SilentlyContinue')) {
163211
# Get the vales for task variables, see https://github.com/gaelcolas/Sampler#task-variables.
164212
. Set-SamplerTaskVariable
@@ -272,6 +320,7 @@ task package_module_nupkg {
272320
$null = Unregister-PSRepository -Name output -ErrorAction SilentlyContinue
273321
}
274322

323+
# Synopsis: Publish a built PowerShell module to a gallery.
275324
task publish_module_to_gallery -if ($GalleryApiToken -and (Get-Command -Name 'Publish-Module' -ErrorAction 'SilentlyContinue')) {
276325
# Get the vales for task variables, see https://github.com/gaelcolas/Sampler#task-variables.
277326
. Set-SamplerTaskVariable

CHANGELOG.md

+29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Removed
11+
12+
- Removed the task `Set_Build_Environment_Variables` since it is not used,
13+
and build helpers are not in use anymore. Fixes [#376](https://github.com/gaelcolas/Sampler/issues/376)
14+
15+
### Added
16+
17+
- Added more unit tests to raise code coverage.
18+
- Deprecated Pester 4 HQRM tests was removed from code coverage. The new
19+
Pester 5 HQRM test are in module DscResource.Test and is tested there.
20+
21+
### Changed
22+
23+
- Some unnecessary code was removed from the script `Set-SamplerTaskVariable`
24+
since the functions `Get-SamplerBuiltModuleManifest`, `Get-SamplerBuiltModuleBase`,
25+
and `Get-SamplerModuleRootPath` already handle returning the absolute path.
26+
It also simplified mocking the functions for the unit tests.
27+
- Task `copy_paths_to_choco_staging`
28+
- Now handle property `Exclude` and `Force` correctly.
29+
30+
### Fixed
31+
32+
- `Get-MofSchemaName`
33+
- Correctly throws an error if the schema MOF cannot be parsed.
34+
- Task `Convert_Pester_Coverage`
35+
- Removed one unused line of code.
36+
- Moved one line of code so that code coverage threshold value
37+
will output correctly in some circumstances.
38+
1039
## [0.115.0] - 2022-06-09
1140

1241
### Added

Sampler/Public/Get-MofSchemaName.ps1

+5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ function Get-MofSchemaName
8181
$class = [Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache]::ImportClasses(
8282
$tempFilePath, $moduleInfo, $exceptionCollection
8383
)
84+
85+
if ($exceptionCollection.Count -gt 0)
86+
{
87+
throw $exceptionCollection
88+
}
8489
}
8590
catch
8691
{

Sampler/scripts/Set-SamplerTaskVariable.ps1

+1-13
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,11 @@ else
175175
}
176176

177177
$BuiltModuleManifest = Get-SamplerBuiltModuleManifest @GetBuiltModuleManifestParams
178-
if ($BuiltModuleManifest)
179-
{
180-
$BuiltModuleManifest = (Get-Item -Path $BuiltModuleManifest -ErrorAction 'SilentlyContinue').FullName
181-
}
182178

183179
"`tBuilt Module Manifest = '$BuiltModuleManifest'"
184180

185181
$BuiltModuleBase = Get-SamplerBuiltModuleBase @GetBuiltModuleManifestParams
186-
if ($BuiltModuleBase)
187-
{
188-
$BuiltModuleBase = (Get-Item -Path $BuiltModuleBase -ErrorAction 'SilentlyContinue').FullName
189-
}
182+
190183

191184
"`tBuilt Module Base = '$BuiltModuleBase'"
192185

@@ -206,11 +199,6 @@ else
206199
if ($BuiltModuleManifest)
207200
{
208201
$BuiltModuleRootScriptPath = Get-SamplerModuleRootPath -ModuleManifestPath $BuiltModuleManifest
209-
210-
if ($BuiltModuleRootScriptPath)
211-
{
212-
$BuiltModuleRootScriptPath = (Get-Item -Path $BuiltModuleRootScriptPath -ErrorAction 'SilentlyContinue').FullName
213-
}
214202
}
215203

216204
"`tBuilt Module Root Script = '$BuiltModuleRootScriptPath'"

build.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Pester:
5454
StackTraceVerbosity: Full
5555
CIFormat: Auto
5656
CodeCoverage:
57-
CoveragePercentTarget: 24 # Set to 0 to bypass
57+
CoveragePercentTarget: 70 # Set to 0 to bypass
5858
# Set to specific filename to override the default filename.
5959
#OutputPath: JaCoCo_coverage.xml
6060
OutputEncoding: ascii
@@ -67,6 +67,9 @@ Pester:
6767
- Templates
6868
- Modules/DscResource.Common
6969
- Assets
70+
# This is deprecated Pester 4 HQRM test, the HQRM test for Pester 5 has been
71+
# moved to module DscResource.Test.
72+
- tasks/DscResource.Test.build.ps1
7073

7174
####################################################
7275
# Code Coverage Configuration #

codecov.yml

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ coverage:
2727
fixes:
2828
- '^\d+\.\d+\.\d+\/tasks::.build/tasks' # move path "X.Y.Z/tasks" => ".build/tasks"
2929
- '^Sampler\/tasks::.build/tasks' # move path "Sampler/tasks" => ".build/tasks"
30+
31+
ignore:
32+
- '.build\tasks\DscResource.Test.build.ps1' # Deprecated HQRM tasks

tests/Integration/PlasterTemplates/Build/BuildPlasterTemplate.Integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/ChocolateyPipeline/ChocolateyPipelinePlasterTemplate.Integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/ClassFolderResource/AddClassFolderResource.integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/ClassResource/AddClassResource.integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/Classes/AddClasses.integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/Composite/AddCompositeResource.integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/Enum/AddEnum.integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/GCPackage/GCPackages.integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/GithubConfig/GithubConfigPlasterTemplate.Integration.tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/HelperSubmodules/HelperSubmodules.integration.tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/MofResource/AddMofResource.integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/PrivateFunction/AddPrivateFunction.integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/PublicCallPrivateFunctions/AddPublicCallPrivateFunctions.integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/PublicFunction/AddPublicFunction.integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

tests/Integration/PlasterTemplates/Sampler/CompleteModulePlasterTemplate.Integration.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BeforeAll {
44
# If the module is not found, run the build task 'noop'.
55
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
66
{
7-
# Redirect all streams to $null, except the error stream (stream 3)
7+
# Redirect all streams to $null, except the error stream (stream 2)
88
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
99
}
1010

0 commit comments

Comments
 (0)