diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json deleted file mode 100644 index eb9e7f1..0000000 --- a/.MetaTestOptIn.json +++ /dev/null @@ -1,15 +0,0 @@ -[ - "Common Tests - Validate Module Files", - "Common Tests - Validate Markdown Files", - "Common Tests - Validate Example Files", - "Common Tests - Spellcheck Markdown Files", - "Common Tests - Relative Path Length", - "Common Tests - Validate Markdown Links", - "Common Tests - Validate Script Files", - "Common Tests - File Formatting", - "Common Tests - .psm1 File Parsing", - "Common Tests - New Error-Level Script Analyzer Rules", - "Common Tests - Custom Script Analyzer Rules", - "Common Tests - Flagged Script Analyzer Rules", - "Common Tests - Required Script Analyzer Rules" -] diff --git a/CHANGELOG.md b/CHANGELOG.md index bfd8c41..bd52504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added a new test type, `All`, to the `Initialize-TestEnvironment` function that initializes the DSC LCM and imports the module for testing ([issue #48](https://github.com/dsccommunity/DscResource.Test/issues/48)). +- Added check on changelog when invoking by project path. ## [0.9.0] - 2019-12-27 diff --git a/build.yaml b/build.yaml index dbbdf00..b8923de 100644 --- a/build.yaml +++ b/build.yaml @@ -41,7 +41,7 @@ BuildWorkflow: DscTest: | { Import-Module -force DscResource.Test - Invoke-DscResourceTest + Invoke-DscResourceTest -ExcludeTag 'Common Tests - Validate Localization' } t: - build diff --git a/source/Tests/QA/Changelog.common.Tests.ps1 b/source/Tests/QA/Changelog.common.Tests.ps1 new file mode 100644 index 0000000..088fcc1 --- /dev/null +++ b/source/Tests/QA/Changelog.common.Tests.ps1 @@ -0,0 +1,61 @@ +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('DscResource.AnalyzerRules\Measure-ParameterBlockParameterAttribute', '', Scope='Function', Target='*')] +param ( + $ModuleName, + $ModuleBase, + $ModuleManifest, + $ProjectPath, + $SourcePath, + $SourceManifest, + $Tag, + $ExcludeTag, + $ExcludeModuleFile, + $ExcludeSourceFile +) + +if (!$ProjectPath) +{ + # Invoke-DscResourceTest is only looking at a built module, skipping this test file. + Write-Verbose "No Project path set: $ProjectPath. Skipping changelog checks." + return +} +else +{ + Write-Verbose "Pushing location $ProjectPath on Stack ProjectTest" + Push-Location -StackName ProjectTest -Path $ProjectPath +} + +try +{ + Describe 'Changelog Management' -Tag 'Changelog' { + + It 'Changelog has been updated' -skip:( + !([bool](Get-Command git -EA SilentlyContinue) -and + [bool](&(Get-Process -id $PID).Path -NoProfile -Command 'git rev-parse --is-inside-work-tree 2>$null')) + ) { + # Get the list of changed files compared with master + $HeadCommit = &git rev-parse HEAD + $MasterCommit = &git rev-parse origin/master + $filesChanged = &git diff $MasterCommit...$HeadCommit --name-only + + if ($HeadCommit -ne $MasterCommit) + { + # if we're not testing same commit (i.e. master..master) + $filesChanged.Where{ + (Split-Path $_ -Leaf) -match '^changelog.md' + } | Should -Not -BeNullOrEmpty + } + } + + It 'Changelog format compliant with keepachangelog format' -skip:( + ![bool](Get-Command git -EA SilentlyContinue) -or + !(Import-Module -Name ChangelogManagement -ErrorAction SilentlyContinue -PassThru) + ) { + { Get-ChangelogData (Join-Path $ProjectPath 'CHANGELOG.md') -ErrorAction Stop } | Should -Not -Throw + } + } +} +finally +{ + Write-Debug "Poping location on Stack ProjectTest" + Pop-Location -StackName ProjectTest +} diff --git a/source/Tests/QA/PSSAResource.common.Tests.ps1 b/source/Tests/QA/PSSAResource.common.Tests.ps1 index 3dbd5cf..0538cee 100644 --- a/source/Tests/QA/PSSAResource.common.Tests.ps1 +++ b/source/Tests/QA/PSSAResource.common.Tests.ps1 @@ -67,11 +67,11 @@ $DscResourceAnalyzerRulesModule = Import-Module DscResource.AnalyzerRules -PassT Describe 'Common Tests - PS Script Analyzer on Resource Files' -Tag DscPSSA,'Common Tests - PS Script Analyzer on Resource Files' { - $dscResourcesPsm1Files = Get-ChildItem -Path $ModuleBase -Include *.psm1 -Recurse | WhereModuleFileNotExcluded + $dscResourcesPsm1Files = @(Get-ChildItem -Path $ModuleBase -Include *.psm1 -Recurse | WhereModuleFileNotExcluded) if ($SourcePath) { - $dscResourcesPsm1Files += Get-ChildItem -Path $SourcePath -Include *.psm1 -Recurse | WhereSourceFileNotExcluded + $dscResourcesPsm1Files += @(Get-ChildItem -Path $SourcePath -Include *.psm1 -Recurse | WhereSourceFileNotExcluded) } foreach ($dscResourcesPsm1File in $dscResourcesPsm1Files) diff --git a/source/Tests/QA/Restore-TestEnvironment.ps1 b/source/Tests/QA/Restore-TestEnvironment.ps1 deleted file mode 100644 index 0d9a854..0000000 --- a/source/Tests/QA/Restore-TestEnvironment.ps1 +++ /dev/null @@ -1,54 +0,0 @@ -<# - .SYNOPSIS - Restores the environment after running unit or integration tests - on a DSC resource. - - This restores the following changes made by calling - Initialize-TestEnvironment: - 1. Restores the $env:PSModulePath if it was changed. - 2. Restores the PowerShell execution policy. - 3. Resets the DSC LCM if running Integration tests. - - .PARAMETER TestEnvironment - The hashtable created by the Initialize-TestEnvironment. - - .EXAMPLE - Restore-TestEnvironment -TestEnvironment $TestEnvironment -#> -function Restore-TestEnvironment -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [Hashtable] - $TestEnvironment - ) - - Write-Verbose -Message "Cleaning up Test Environment after $($TestEnvironment.TestType) testing of $($TestEnvironment.DSCResourceName) in module $($TestEnvironment.DSCModuleName)." - - if ($TestEnvironment.TestType -ieq 'Integration') - { - # Clear the DSC LCM & Configurations - Clear-DscLcmConfiguration - } - - # Restore PSModulePath - if ($TestEnvironment.OldPSModulePath -ne $env:PSModulePath) - { - Set-PSModulePath -Path $TestEnvironment.OldPSModulePath - - if ($TestEnvironment.TestType -eq 'Integration') - { - # Restore the machine PSModulePath for integration tests. - Set-PSModulePath -Path $TestEnvironment.OldPSModulePath -Machine - } - } - - # Restore the Execution Policy - if ($TestEnvironment.OldExecutionPolicy -ne (Get-ExecutionPolicy)) - { - Set-ExecutionPolicy -ExecutionPolicy $TestEnvironment.OldExecutionPolicy -Scope 'Process' -Force - } -}