Skip to content

Commit

Permalink
Preparation to be able to run common tests against this module (Power…
Browse files Browse the repository at this point in the history
…Shell#174)

* Changes to DscResource.Tests
- Fixed so that code coverage can be scan for code even if there is no DSCResource folder.
- Added workaround for AppVeyor replaces punctuation in folder structure for DscResource.Tests.
- Remove the $repoName variable and replace it with $moduleName. It was duplicate.

* Fixed review comments at r1 for PR PowerShell#174
  • Loading branch information
johlju authored and kwirkykat committed Jul 29, 2017
1 parent 441e04c commit 104da5c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
31 changes: 22 additions & 9 deletions AppVeyor.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function Invoke-AppveyorTestScriptTask
if ($DisableConsistency.IsPresent)
{
$disableConsistencyMofPath = Join-Path -Path $env:temp -ChildPath 'DisableConsistency'
if ( -not (Test-Path -Path $disableConsistencyMofPath))
if (-not (Test-Path -Path $disableConsistencyMofPath))
{
$null = New-Item -Path $disableConsistencyMofPath -ItemType Directory -Force
}
Expand Down Expand Up @@ -220,12 +220,25 @@ function Invoke-AppveyorTestScriptTask
if ($CodeCoverage)
{
Write-Warning -Message 'Code coverage statistics are being calculated. This will slow the start of the tests while the code matrix is built. Please be patient.'
$pesterParameters += @{
CodeCoverage = @(
"$env:APPVEYOR_BUILD_FOLDER\*.psm1"
"$env:APPVEYOR_BUILD_FOLDER\DSCResources\*.psm1"
"$env:APPVEYOR_BUILD_FOLDER\DSCResources\**\*.psm1"
)

# Only add code path for DSCResources if they exist.
if (Test-Path -Path "$MainModulePath\DSCResources" )
{
$pesterParameters += @{
CodeCoverage = @(
"$env:APPVEYOR_BUILD_FOLDER\*.psm1"
"$env:APPVEYOR_BUILD_FOLDER\DSCResources\*.psm1"
"$env:APPVEYOR_BUILD_FOLDER\DSCResources\**\*.psm1"
)
}
}
else
{
$pesterParameters += @{
CodeCoverage = @(
"$env:APPVEYOR_BUILD_FOLDER\*.psm1"
)
}
}
}
$results = Invoke-Pester @pesterParameters
Expand Down Expand Up @@ -255,14 +268,14 @@ function Invoke-AppveyorTestScriptTask
}
}

foreach($result in $results.TestResult)
foreach ($result in $results.TestResult)
{
[string] $describeName = $result.Describe -replace '\\', '/'
[string] $contextName = $result.Context -replace '\\', '/'
$componentName = '{0}; Context: {1}' -f $describeName, $contextName
$appVeyorResult = $result.Result
# Convert any result not know by AppVeyor to an AppVeyor Result
switch($result.Result)
switch ($result.Result)
{
'Pending'
{
Expand Down
30 changes: 22 additions & 8 deletions Meta.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ $moduleRootFilePath = Split-Path -Path $PSScriptRoot -Parent
$moduleName = (Get-Item -Path $moduleRootFilePath).Name
$dscResourcesFolderFilePath = Join-Path -Path $moduleRootFilePath -ChildPath 'DscResources'

<#
This is a workaround to be able to test DscResource.Tests module.
Because the name has punctuation in the name, AppVeyor replaces
that with a dash when it creates the folder structure, so the folder
name becomes 'dscresource-tests'. This sets the module name to the
correct name.
If the name can be detected in a better way, for DscResource.Tests
and all other modules, then this could be removed.
#>
if ($moduleName -eq 'dscresource-tests')
{
$moduleName = 'DscResource.Tests'
}

# Identify the repository root path of the resource module
$repoRootPath = $moduleRootFilePath
$repoRootPathFound = $false
Expand All @@ -39,7 +53,7 @@ if (-not $repoRootPathFound)
'errors. Please ensure this repository has been cloned using Git.')
$repoRootPath = $moduleRootFilePath
}
$repoName = Split-Path -Path $repoRootPath -Leaf

$testOptInFilePath = Join-Path -Path $repoRootPath -ChildPath '.MetaTestOptIn.json'
# .MetaTestOptIn.json should be in the following format
# [
Expand All @@ -50,7 +64,7 @@ $testOptInFilePath = Join-Path -Path $repoRootPath -ChildPath '.MetaTestOptIn.js
# ]

$optIns = @()
if(Test-Path $testOptInFilePath)
if (Test-Path $testOptInFilePath)
{
$optIns = Get-Content -LiteralPath $testOptInFilePath | ConvertFrom-Json
}
Expand All @@ -66,7 +80,7 @@ Describe 'Common Tests - File Formatting' {
{
if (Test-FileInUnicode $textFile)
{
if($textFile.Extension -ieq '.mof')
if ($textFile.Extension -ieq '.mof')
{
Write-Warning -Message "File $($textFile.FullName) should be converted to ASCII. Use fixer function 'Get-UnicodeFilesList `$pwd | ConvertTo-ASCII'."
}
Expand Down Expand Up @@ -109,7 +123,7 @@ Describe 'Common Tests - File Formatting' {
{
$fileContent = Get-Content -Path $textFile.FullName -Raw

if([String]::IsNullOrWhiteSpace($fileContent))
if ([String]::IsNullOrWhiteSpace($fileContent))
{
Write-Warning -Message "File $($textFile.FullName) is empty. Please remove this file."
$containsEmptyFile = $true
Expand All @@ -126,7 +140,7 @@ Describe 'Common Tests - File Formatting' {
{
$fileContent = Get-Content -Path $textFile.FullName -Raw

if(-not [String]::IsNullOrWhiteSpace($fileContent) -and $fileContent[-1] -ne "`n")
if (-not [String]::IsNullOrWhiteSpace($fileContent) -and $fileContent[-1] -ne "`n")
{
if (-not $containsFileWithoutNewLine)
{
Expand Down Expand Up @@ -566,7 +580,7 @@ Describe 'Common Tests - Validate Example Files' -Tag 'Examples' {
if ($env:APPVEYOR -eq $true)
{
$psHomePSModulePathItem = Get-PSHomePSModulePathItem
$powershellModulePath = Join-Path -Path $psHomePSModulePathItem -ChildPath $repoName
$powershellModulePath = Join-Path -Path $psHomePSModulePathItem -ChildPath $moduleName

Write-Verbose -Message ('Copying module from ''{0}'' to ''{1}''' -f $moduleRootFilePath, $powershellModulePath) -Verbose

Expand Down Expand Up @@ -708,7 +722,7 @@ Describe 'Common Tests - Validate Example Files' -Tag 'Examples' {

# Restore the load of the module to ensure future tests have access to it
Import-Module -Name (Join-Path -Path $moduleRootFilePath `
-ChildPath "$repoName.psd1") `
-ChildPath "$moduleName.psd1") `
-Global
}
}
Expand Down Expand Up @@ -794,7 +808,7 @@ Describe 'Common Tests - Validate Markdown Files' -Tag 'Markdown' {
"run 'npm install -g gulp' in order to have this " + `
"text execute.")
}
if($optIn)
if ($optIn)
{
$mdErrors | Should Be 0
}
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ Invoke-AppveyorAfterTestTask `
* Fixed Byte Order Mark (BOM) in files; DscResource.AnalyzerRules.psd1,
DscResource.AnalyzerRules.psm1 and en-US/DscResource.AnalyzerRules.psd1
([issue #169](https://github.com/PowerShell/DscResource.Tests/issues/169)).
* Fixed so that code coverage can be scan for code even if there is no DSCResource
folder.
* Added workaround for AppVeyor replaces punctuation in folder structure for
DscResource.Tests.
* Remove the $repoName variable and replace it with $moduleName as it was a
duplicate.

### 0.2.0.0

Expand Down

0 comments on commit 104da5c

Please sign in to comment.