Skip to content

Conversation

@djweber
Copy link

@djweber djweber commented Oct 9, 2017

Currently, if a user does not clone with the --recursive flag or run git submodule update --init, Start-PSPester will fail to run due to the Pester module missing. While the error hints at the Pester module not being found, there is no suggested way of fixing the issue presented to the user. This change causes a warning to appear at the beginning of the execution of Start-PSPester if the Pester module cannot be found.

build.psm1 Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an error instead? We would not be able to run tests without Pester.

Copy link
Author

@djweber djweber Oct 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adityapatwardhan I could change this to use Write-Error, but now I'm wondering if we should use throw instead -- after all, there is no point in continuing at all if Pester can't be found. This would terminate the script with a single error instead of several (more vague) errors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually if we follow the pattern from: https://github.com/DdWr/PowerShell/blob/3fdd9f1b639df805f895c56cf574f2039ec15a76/build.psm1#L415

We should do Write-Warning and then return.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adityapatwardhan Changes made.

@djweber djweber changed the title Add warning to Start-PSPester if Pester module not found Add terminating error to Start-PSPester if Pester module not found Oct 9, 2017
@djweber djweber changed the title Add terminating error to Start-PSPester if Pester module not found Terminate Start-PSPester if Pester module not found Oct 9, 2017
build.psm1 Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor comment about the message -- how about this:

Write-Warning @"
Pester module not found.
Make sure that the proper git submodules are installed by running:
    git submodule update --init
"@

It looks like this:
image

@daxian-dbw daxian-dbw self-assigned this Oct 10, 2017
build.psm1 Outdated
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daxian-dbw I made the module check a little stricter here than simply checking for the path.

Currently, if a user does not clone with the --recursive flag or run
git submodule update --init, Start-PSPester will fail to run due to
the Pester module missing. While the error hints at the Pester module not
being found, there is no suggested way of fixing the issue presented to
the user. This change makes a helpful warning to appear at the beginning
of the execution of Start-PSPester if the Pester module cannot be found.
[switch]$IncludeFailingTest
)

if (-not (Get-Module -ListAvailable -Name $Pester -ErrorAction SilentlyContinue))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually prefer the Test-Path instead. With -ListAvailable the Pester version that comes installed with Windows 10 will be found. There are difference in those versions which might cause false errors in running tests.

Copy link
Author

@djweber djweber Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adityapatwardhan Since the full path to the project's Pester module is being passed in here, I believe this would not be an issue:

PS /Users/david/Code/PowerShell> Get-Module -ListAvailable /Users/david/Code/PowerShell/src/powershell-unix/bin/Linux/netcoreapp2.0/osx.10.12-x64/publish/Modules/Pester  | Format-Table
Path -Groupby Name

   Name: Pester

Path
----
/Users/david/Code/PowerShell/src/powershell-unix/bin/Linux/netcoreapp2.0/osx.10.12-x64/publish/Modules/Pester/Pester.psd1

However, if we only passed in Pester, I could see that being a cause for concern:

PS /Users/david/Code/PowerShell> Get-Module -ListAvailable Pester | Format-Table Path -Groupby Name
   
   Name: Pester

Path
----
/usr/local/microsoft/powershell/6.0.0-beta.8/Modules/Pester/4.0.8/Pester.psd1
/usr/local/microsoft/powershell/6.0.0-beta.8/Modules/Pester/Pester.psd1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Misread it being Pester instead of $Pester.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@daxian-dbw daxian-dbw merged commit 42e8deb into PowerShell:master Oct 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants