diff --git a/publish/buildNugetPackage.ps1 b/publish/buildNugetPackage.ps1 deleted file mode 100644 index fcd3c0c2e..000000000 --- a/publish/buildNugetPackage.ps1 +++ /dev/null @@ -1,24 +0,0 @@ -$VerbosePreference = 'Continue' -$ErrorActionPreference = 'Stop' - -try { - $baseDir = $PSScriptRoot - $buildDir = "$baseDir\build\nuget" - $nugetExe = "$baseDir\vendor\tools\nuget.exe" - $targetBase = "tools" - - Write-Verbose "Running in $baseDir" - Write-Verbose "Building to $buildDir" - - $version = git.exe describe --abbrev=0 --tags - Write-Verbose "Version $version" - - Write-Verbose "Creating $buildDir" - mkdir $buildDir - Write-Verbose "Building package" - &$nugetExe pack "$baseDir\Pester.nuspec" -OutputDirectory $buildDir -NoPackageAnalysis -version $version -Properties targetBase=$targetBase -} -catch { - Write-Error -ErrorRecord $_ - exit 1 -} diff --git a/publish/getNugetExe.ps1 b/publish/getNugetExe.ps1 deleted file mode 100644 index ff343d694..000000000 --- a/publish/getNugetExe.ps1 +++ /dev/null @@ -1,43 +0,0 @@ -$VerbosePreference = 'Continue' -$ErrorActionPreference = 'Stop' - -try { - # had problems running nuget.exe on the build server - # so I try to run it first and if that does not work - # I download a version from the web and try that - - $nugetPath = "$psScriptRoot\vendor\tools\nuget.exe" - Write-Host Nuget path $nugetPath - - $nugetFound = Test-Path $nugetPath - if ($nugetFound) { - Write-Host Found local nuget.exe running it - $nugetRunnable = $false - try { - &$nugetPath | select -First 1 - $nugetRunnable = $true - } - catch { - Write-Host Could not run local nuget.exe. Failed with ("$_") - Remove-Item $nugetPath -Force -Confirm:$false -Verbose - } - } - else { - Write-Host Local nuget.exe not found - } - - if (-not $nugetFound -or -not $nugetRunnable) { - $vendorDirectory = $nugetPath | Split-Path - if (-not(Test-Path $VendorDirectory)) { - mkdir $vendorDirectory - } - - Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/v4.4.1/nuget.exe" -OutFile $nugetPath -Verbose - "Downloaded $(&$nugetPath | select -First 1)" - } - -} -catch { - Write-Error -ErrorRecord $_ - exit 1 -} diff --git a/publish/testRelease.ps1 b/publish/testRelease.ps1 deleted file mode 100644 index a32f87771..000000000 --- a/publish/testRelease.ps1 +++ /dev/null @@ -1,48 +0,0 @@ -param( - [switch] $LocalBuild -) - -$ErrorActionPreference = 'Stop' - -$psd1 = Join-Path $PSScriptRoot Pester.psd1 - -Get-Module Pester | Remove-Module -Import-Module $psd1 -ErrorAction Stop - -$xml = Join-Path $PSScriptRoot Test.Version.xml -$configuration = [PesterConfiguration]@{ - Run = @{ Path = $PSScriptRoot; PassThru = $true } - Filter = @{ Tag = 'VersionChecks', 'StyleRules' } - TestResult = @{ Enabled = $true; OutputPath = $xml; OutputFormat = 'NUnitXml' } -} - -$result = Invoke-Pester -Configuration $configuration -ErrorAction Stop - -if ($LocalBuild) { - # when I build release locally I don't want to - # think about removing the xml all the time - Remove-Item $xml -} - -if ($result.TotalCount -lt 1) { - $m = "No tests were run." - - if ($LocalBuild) { - $m - exit 9999 - } - else { - throw $m - } -} - -if ($result.FailedCount -gt 0) { - $m = "$($result.FailedCount) tests did not pass." - if ($LocalBuild) { - $m - exit $result.FailedCount - } - else { - throw $m - } -} diff --git a/publish/vendor/packages.config b/publish/vendor/packages.config deleted file mode 100644 index e80881d0a..000000000 --- a/publish/vendor/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/publish/vendor/tools/nuget.exe b/publish/vendor/tools/nuget.exe deleted file mode 100644 index a34c36752..000000000 Binary files a/publish/vendor/tools/nuget.exe and /dev/null differ diff --git a/test.ps1 b/test.ps1 index b047bdce7..e26a596f8 100644 --- a/test.ps1 +++ b/test.ps1 @@ -28,9 +28,6 @@ Forces inlining the module into a single file. This is how real build is done, but makes local debugging difficult. When -CI is used, inlining is forced. - - .NOTES - Tests are excluded with Tags VersionChecks, StyleRules, Help. #> param ( # force P to fail when I leave `dt` in the tests @@ -185,8 +182,6 @@ else { $configuration.Run.ExcludePath = '*/demo/*', '*/examples/*', '*/testProjects/*' $configuration.Run.PassThru = $true -$configuration.Filter.ExcludeTag = 'VersionChecks', 'StyleRules' - if ($CI) { $configuration.Run.Exit = $true diff --git a/tst/Pester.Tests.ps1 b/tst/Pester.Tests.ps1 index a01ff5aa9..3d0e4af41 100644 --- a/tst/Pester.Tests.ps1 +++ b/tst/Pester.Tests.ps1 @@ -1,134 +1,72 @@ Set-StrictMode -Version Latest -BeforeAll { - $manifestPath = (Join-Path $PSScriptRoot 'Pester.psd1') - $changeLogPath = (Join-Path $PSScriptRoot 'CHANGELOG.md') -} -# DO NOT CHANGE THIS TAG NAME; IT AFFECTS THE CI BUILD. -Describe -Tags 'VersionChecks' "Pester manifest and changelog" { +Describe 'Pester manifest' { BeforeAll { - $script:manifest = $null - $script:tagVersion = $null - $script:tagVersionShort = $null - $script:changelogVersion = $null - $script:changelogVersionShort = $null - $script:tagPrerelease = $null + $manifestPath = Join-Path (Get-Module Pester).ModuleBase 'Pester.psd1' + $manifest = Test-ModuleManifest -Path $manifestPath -WarningAction SilentlyContinue } - It "has a valid manifest" { - { - $script:manifest = Test-ModuleManifest -Path $manifestPath -ErrorAction Stop -WarningAction SilentlyContinue - } | Should -Not -Throw + It 'is a valid manifest' { + { Test-ModuleManifest -Path $manifestPath -ErrorAction Stop -WarningAction SilentlyContinue } | Should -Not -Throw } - It "has a valid name in the manifest" { - $script:manifest.Name | Should -Be Pester + It 'has the expected name' { + $manifest.Name | Should -Be 'Pester' } - It "has a valid guid in the manifest" { - $script:manifest.Guid | Should -Be 'a699dea5-2c73-4616-a270-1f7abb777e71' + It 'has the expected guid' { + $manifest.Guid | Should -Be 'a699dea5-2c73-4616-a270-1f7abb777e71' } +} - if ((Get-Command -Name git -ErrorAction SilentlyContinue) -and (Get-Item ".git" -ErrorAction Ignore)) { - if ([bool]((git remote -v 2>&1) -match "github.com/Pester/")) { - It "is tagged with a valid version" { - $thisCommit = git log --decorate --oneline HEAD~1..HEAD - - if ($thisCommit -match 'tag:\s*(.*?)[,)]') { - $script:tagVersion = $matches[1] - $script:tagVersionShort, $script:tagPrerelease = $script:tagVersion -split "-", 2 - } - - $script:tagVersion | Should -Not -BeNullOrEmpty - $script:tagVersionShort -as [Version] | Should -Not -BeNullOrEmpty - } - - It "has valid release notes in the manifest" { - $script:manifest.PrivateData.PSData.ReleaseNotes | Should -Be "https://github.com/pester/Pester/releases/tag/$script:tagVersion" - } - - It "tag and changelog versions are the same" { - - foreach ($line in (Get-Content $changeLogPath)) { - if ($line -match "^\s*##\s+(?.*?)\s") { - $script:changelogVersion = $matches.Version - $script:changelogVersionShort = $script:changelogVersion -replace "-.*$", '' - break - } - } - - $script:changelogVersion | Should -Be $script:tagVersion - $script:changelogVersionShort | Should -Be $script:tagVersionShort - } - - It "tag and changelog versions are the same" { - $script:changelogVersion | Should -Be $script:tagVersion - } - - It "all short versions are the same" { - $script:changelogVersionShort -as [Version] | Should -Be ( $script:manifest.Version -as [Version] ) - $script:manifest.Version -as [Version] | Should -Be ( $script:tagVersionShort -as [Version] ) - } +Describe 'Clean treatment of the $error variable' { + BeforeAll { + $error.Clear() + } + Context 'A Context' { + It 'Performs a successful test' { + $true | Should -Be $true } } - It "has valid pre-release suffix in manifest (empty for stable version)" { - # might be empty or null, as well as the tagPrerelase. we need empty string to eq $null but not to eq any other value - $prereleaseFromManifest = $script:manifest.PrivateData.PSData.Prerelease | where { $_ } - $prereleaseFromManifest | Should -Be $script:tagPrerelease + It 'Did not add anything to the $error variable' { + $error.Count | Should -Be 0 } } -if ($PSVersionTable.PSVersion.Major -ge 3) { - Describe 'Clean treatment of the $error variable' { +InPesterModuleScope { + Describe 'SafeCommands table' { BeforeAll { - $error.Clear() - } - Context 'A Context' { - It 'Performs a successful test' { - $true | Should -Be $true - } - } - - It 'Did not add anything to the $error variable' { - $error.Count | Should -Be 0 - } - } - - InPesterModuleScope { - Describe 'SafeCommands table' { - BeforeAll { - $path = $ExecutionContext.SessionState.Module.ModuleBase - $filesToCheck = Get-ChildItem -Path $path -Recurse -Include *.ps1, *.psm1 -Exclude *.Tests.ps1 - $callsToSafeCommands = @( - foreach ($file in $filesToCheck) { - $tokens = $parseErrors = $null - $ast = [System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref] $tokens, [ref] $parseErrors) - $filter = { - $args[0] -is [System.Management.Automation.Language.CommandAst] -and - $args[0].InvocationOperator -eq [System.Management.Automation.Language.TokenKind]::Ampersand -and - $args[0].CommandElements[0] -is [System.Management.Automation.Language.IndexExpressionAst] -and - $args[0].CommandElements[0].Target -is [System.Management.Automation.Language.VariableExpressionAst] -and - $args[0].CommandElements[0].Target.VariablePath.UserPath -match '^(?:script:)?SafeCommands$' - } - - $ast.FindAll($filter, $true) + $path = $ExecutionContext.SessionState.Module.ModuleBase + $filesToCheck = Get-ChildItem -Path $path -Recurse -Include *.ps1, *.psm1 -Exclude *.Tests.ps1 + $callsToSafeCommands = @( + foreach ($file in $filesToCheck) { + $tokens = $parseErrors = $null + $ast = [System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref] $tokens, [ref] $parseErrors) + $filter = { + $args[0] -is [System.Management.Automation.Language.CommandAst] -and + $args[0].InvocationOperator -eq [System.Management.Automation.Language.TokenKind]::Ampersand -and + $args[0].CommandElements[0] -is [System.Management.Automation.Language.IndexExpressionAst] -and + $args[0].CommandElements[0].Target -is [System.Management.Automation.Language.VariableExpressionAst] -and + $args[0].CommandElements[0].Target.VariablePath.UserPath -match '^(?:script:)?SafeCommands$' } - ) - $uniqueSafeCommands = $callsToSafeCommands | ForEach-Object { $_.CommandElements[0].Index.Value } | Select-Object -Unique + $ast.FindAll($filter, $true) + } + ) - $missingSafeCommands = $uniqueSafeCommands | Where { -not $script:SafeCommands.ContainsKey($_) } + $uniqueSafeCommands = $callsToSafeCommands | ForEach-Object { $_.CommandElements[0].Index.Value } | Select-Object -Unique - # These commands are conditionally added to the safeCommands table due to Nano / Core versus PSv2 compatibility; one will always - # be missing, and can be ignored. - # Also add the two possible commands uname and id which would be found on non-Windows platforms - $missingSafeCommands = $missingSafeCommands | Where { @('Get-WmiObject', 'Get-CimInstance', 'uname', 'id') -notcontains $_ } - } + $missingSafeCommands = $uniqueSafeCommands | Where { -not $script:SafeCommands.ContainsKey($_) } - It 'The SafeCommands table contains all commands that are called from the module' { - $missingSafeCommands | Should -Be $null - } + # These commands are conditionally added to the safeCommands table due to Nano / Core compatibility; one will always + # be missing, and can be ignored. + # Also add the two possible commands uname and id which would be found on non-Windows platforms + $missingSafeCommands = $missingSafeCommands | Where { @('Get-WmiObject', 'Get-CimInstance', 'uname', 'id') -notcontains $_ } + } + + It 'The SafeCommands table contains all commands that are called from the module' { + $missingSafeCommands | Should -Be $null } } } @@ -136,79 +74,14 @@ if ($PSVersionTable.PSVersion.Major -ge 3) { Describe 'Public API' { It 'all non-deprecated, non-internal public commands use CmdletBinding' { $r = Get-Command -Module Pester | - ? { $_.CommandType -ne 'Alias' } | # Get-Command outputs aliases in PowerShell 2 + ? { $_.CommandType -ne 'Alias' } | ? { -not $_.CmdletBinding } | % { $_.Name } $r | Should -beNullOrEmpty } } -Describe 'Style rules' -Tag StyleRules { - BeforeAll { - $pesterRoot = (Get-Module Pester).ModuleBase - - $files = @( - Get-ChildItem $pesterRoot\* -Include *.ps1, *.psm1, *.psd1 - Get-ChildItem (Join-Path $pesterRoot 'en-US') -Include *.ps1, *.psm1, *.psd1, *.txt -Recurse - Get-ChildItem (Join-Path $pesterRoot 'Functions') -Include *.ps1, *.psm1, *.psd1 -Recurse - Get-ChildItem (Join-Path $pesterRoot 'Dependencies') -Include *.ps1, *.psm1, *.psd1 -Recurse - ) - } - - It 'Pester source files contain no trailing whitespace' { - $badLines = @( - foreach ($file in $files) { - $lines = [System.IO.File]::ReadAllLines($file.FullName) - $lineCount = $lines.Count - - for ($i = 0; $i -lt $lineCount; $i++) { - if ($lines[$i] -match '\s+$') { - 'File: {0}, Line: {1}' -f $file.FullName, ($i + 1) - } - } - } - ) - - if ($badLines.Count -gt 0) { - throw "The following $($badLines.Count) lines contain trailing whitespace: $([System.Environment]::NewLine)$([System.Environment]::NewLine)$($badLines -join "$([System.Environment]::NewLine)")" - } - } - It 'Spaces are used for indentation in all code files, not tabs' { - $badLines = @( - foreach ($file in $files) { - $lines = [System.IO.File]::ReadAllLines($file.FullName) - $lineCount = $lines.Count - - for ($i = 0; $i -lt $lineCount; $i++) { - if ($lines[$i] -match '^[ ]*\t|^\t|^\t[ ]*') { - 'File: {0}, Line: {1}' -f $file.FullName, ($i + 1) - } - } - } - ) - - if ($badLines.Count -gt 0) { - throw "The following $($badLines.Count) lines start with a tab character: $([System.Environment]::NewLine)$([System.Environment]::NewLine)$($badLines -join "$([System.Environment]::NewLine)")" - } - } - - It 'Pester Source Files all end with a newline' { - $badFiles = @( - foreach ($file in $files) { - $string = [System.IO.File]::ReadAllText($file.FullName) - if ($string.Length -gt 0 -and $string[-1] -ne "`n") { - $file.FullName - } - } - ) - - if ($badFiles.Count -gt 0) { - throw "The following files do not end with a newline: $([System.Environment]::NewLine)$([System.Environment]::NewLine)$($badFiles -join "$([System.Environment]::NewLine)")" - } - } -} - -Describe 'Module packaging' -Tag StyleRules { +Describe 'Module packaging' { # Issue #2826: PSResourceGet decides a package is a script by looking for a # '.ps1' file in the package root (i.e. Pester.ps1). When that file is # present it prints a spurious installation-path warning on Install-PSResource Pester.