Tests/Acceptance/Project.Tests.ps1
$moduleroot = $Env:BHModulePath $moduleName = $Env:BHProjectName Describe "PSScriptAnalyzer rule-sets" -Tag Build { $Rules = Get-ScriptAnalyzerRule $scripts = Get-ChildItem $moduleRoot -Include *.ps1, *.psm1, *.psd1 -Recurse | Where-Object fullname -notmatch 'classes' foreach ( $Script in $scripts ) { Context "Script '$($script.FullName)'" { foreach ( $rule in $rules ) { It "Rule [$rule]" { (Invoke-ScriptAnalyzer -Path $script.FullName -IncludeRule $rule.RuleName ).Count | Should Be 0 } } } } } Describe "General project validation: $moduleName" { Context "Verifying all the files are proper PowerShell files"{ $scripts = Get-ChildItem $moduleroot -Include *.ps1, *.psm1, *.psd1 -Recurse # TestCases are splatted to the script so we need hashtables $testCase = $scripts | Foreach-Object {@{file = $_}} It "Script <file> should be valid powershell" -TestCases $testCase { param($file) $file.fullname | Should Exist $contents = Get-Content -Path $file.fullname -ErrorAction Stop $errors = $null $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) $errors.Count | Should Be 0 } } Context "Does the module load cleanly" { It "Module '$moduleName' can import cleanly" { {Import-Module (Join-Path $moduleRoot "$moduleName.psm1") -force } | Should Not Throw } } } |