Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locally running ./build.ps1 -Tests does not function as docs specify #1652

Open
clcaldwell opened this issue Mar 23, 2021 · 1 comment
Open
Assignees

Comments

@clcaldwell
Copy link
Contributor

clcaldwell commented Mar 23, 2021

Steps to reproduce

git clone https://github.com/PowerShell/PSScriptAnalyzer.git
cd PSScriptAnalyzer
./Build.ps1. -Test
Import-module ./build.psm1
Get-TestResults # Or Get-TestFailures

Expected behavior

This should, as per the documentation, load the results file and output it to the console.

Actual behavior

Throws these errors:

Resolve-Path : Cannot find path 'C:\Users\Coby\source\repos\PSScriptAnalyzer\TestResults.xml' because it does not
exist.
At C:\Users\Coby\source\repos\PSScriptAnalyzer\build.psm1:410 char:17
+     $logPath = (Resolve-Path $logfile).Path
+                 ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\Coby\s...TestResults.xml:String) [Resolve-Path], ItemNotFoundE
   xception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand

Get-Content : Cannot bind argument to parameter 'Path' because it is null.
At C:\Users\Coby\source\repos\PSScriptAnalyzer\build.psm1:411 char:34
+     $results = [xml](Get-Content $logPath)
+                                  ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-Content], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetContentC
   ommand

You cannot call a method on a null-valued expression.
At C:\Users\Coby\source\repos\PSScriptAnalyzer\build.psm1:412 char:5
+     $results.SelectNodes(".//test-case")
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Environment data

Fails in all environments.

@ghost ghost added the Needs: Triage 🔍 label Mar 23, 2021
@clcaldwell
Copy link
Contributor Author

The root cause is pretty simple - the output path is defined here:

$testResultsFile = "'$(Join-Path ${projectRoot} -childPath TestResults.xml)'"

But is not passed to Pester here:

$scriptBlock = [scriptblock]::Create("Import-Module PSScriptAnalyzer; Invoke-Pester -Path $testScripts")

Looking at this, #1444 , it seems we've decided to target Pester 5.X . I'll make a PR updating this Pester invocation to include the output file in the 5.x style, and update the readme to specify a minimum Pester 5.x version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants