Merge pull request #835 from scrthq:hotfix/issue_832

fixes #832
This commit is contained in:
Doug Finke
2020-07-11 17:49:54 -04:00
committed by GitHub
4 changed files with 52 additions and 11 deletions

View File

@@ -13,7 +13,10 @@ param
# AppVeyor and Azure - Upload module as AppVeyor Artifact.
[Switch]$Artifact,
# Azure - Runs PsScriptAnalyzer against one or more folders and pivots the results to form a report.
[Switch]$Analyzer
[Switch]$Analyzer,
# Installs the module and invokes only the ModuleImport test.
# Used for validating that the module imports still when external dependencies are missing, e.g. mono-libgdiplus on macOS.
[Switch]$TestImportOnly
)
$ErrorActionPreference = 'Stop'
if ($Initialize) {
@@ -21,7 +24,7 @@ if ($Initialize) {
$ModuleVersion = (. ([Scriptblock]::Create((Get-Content -Path $Psd1 | Out-String)))).ModuleVersion
Update-AppveyorBuild -Version "$ModuleVersion ($env:APPVEYOR_BUILD_NUMBER) $env:APPVEYOR_REPO_BRANCH"
}
if ($Test) {
if ($Test -or $TestImportOnly) {
function Get-EnvironmentInfo {
if ([environment]::OSVersion.Platform -like "win*") {
# Get Windows Version
@@ -97,7 +100,23 @@ if (-not $VersionFilePath) {
'[Progress] Installing Module.'
. .\CI\Install.ps1
'[Progress] Invoking Pester.'
Invoke-Pester -OutputFile ('TestResultsPS{0}.xml' -f $PSVersionTable.PSVersion)
$pesterParams = @{
OutputFile = ('TestResultsPS{0}.xml' -f $PSVersionTable.PSVersion)
PassThru = $true
}
if ($TestImportOnly) {
$pesterParams['Tag'] = 'TestImportOnly'
}
else {
$pesterParams['ExcludeTag'] = 'TestImportOnly'
}
$testResults = Invoke-Pester @pesterParams
'Pester invocation complete!'
if ($testResults.FailedCount -gt 0) {
"Test failures:"
$testResults.TestResult | Where-Object {-not $_.Passed} | Format-List
Write-Error "$($testResults.FailedCount) Pester tests failed. Build cannot continue!"
}
}
if ($Finalize) {
'[Progress] Finalizing.'
@@ -206,4 +225,4 @@ if ($Analyzer) {
else {
"[Info] Invoke-ScriptAnalyzer didn't return any problems."
}
}
}

View File

@@ -7,8 +7,8 @@ if (-not $Strings) {
try { [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") }
catch { Write-Warning -Message $Strings.SystemDrawingAvailable }
foreach ($directory in @('Private', 'Public','Charting','InferData','Pivot')) {
Get-ChildItem -Path "$PSScriptRoot\$directory\*.ps1" | ForEach-Object {. $_.FullName}
foreach ($directory in @('Private', 'Public', 'Charting', 'InferData', 'Pivot')) {
Get-ChildItem -Path "$PSScriptRoot\$directory\*.ps1" | ForEach-Object { . $_.FullName }
}
if ($PSVersionTable.PSVersion.Major -ge 5) {
@@ -53,8 +53,8 @@ brew install mono-libgdiplus
"@
Write-Warning -Message $msg
}
finally {
$ExcelPackage | Close-ExcelPackage -NoSave
}
}
}
finally {
$ExcelPackage | Close-ExcelPackage -NoSave
}
}

View File

@@ -0,0 +1,6 @@
Param()
Describe "Module" -Tag "TestImportOnly" {
It "Should import without error" {
{ Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force -ErrorAction Stop } | Should -Not -Throw
}
}

View File

@@ -92,4 +92,20 @@ jobs:
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: '**/TestResults*.xml'
failTaskOnFailedTests: true
failTaskOnFailedTests: true
- job: macOSNoDeps
pool:
vmImage: 'macOS-latest'
steps:
- powershell: 'Install-Module -Name Pester -Force -MaximumVersion 4.99.99'
displayName: 'Update Pester'
- powershell: './CI/CI.ps1 -TestImportOnly'
displayName: 'Install and Test Import Only'
- task: PublishTestResults@2
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: '**/TestResults*.xml'
failTaskOnFailedTests: true