Closed it-praktyk closed 7 years ago
@nohwnd, @dlwyatt
Should all tests for Pester itself (Functions*.Tests.ps1 files) start with a declaration Set-StrictMode -Version Latest
?
I've found that the Functions\Coverage.Tests.ps1 doesn't contain this.
yup. whole pester should be able to run in strict mode.
OK, I'll update style rules tests to check if the first line of Functions*.Tests.ps1 is Set-StrictMode -Version Latest
to avoid this kind of situation in the future.
BTW, I can't find any tests for the Set-TestInconclusive function.
Okay maybe not this way. Once the strict mode is set you don't have to re-set it for every file right? So this is likely just a remnant of past. No need to add more rules for this, imho the code on build server runs in strict mode anyway, so it would get caught there. If it is not we should set it up that way.
Hmmm, I caught errors provided above after when I set Set-StrictMode -Version Latest
just at the beginning of my local copy of the Pester.psm1. They were not caught by CI.
In that case I am wrong about how Strict mode works or something else is wring. I'll have a look when I have some spare time.
The list of tests files which don't start from Set-StrictMode
PS Pester> Get-ChildItem -Include *.Tests.ps1 -Recurse | foreach { [String]$FileFirstLine = "{0} - {1}" -f $_.Name, $(Get-Content $_ | Select-Object -First 1) ; If ( $FileFirstLine -notmatch 'StrictMode') { Write-Host $FileFirstLine } }
BreakAndContinue.Tests.ps1 - Describe 'Clean handling of break and continue' {
Environment.Tests.ps1 - InModuleScope -ModuleName Pester {
GlobalMock-A.Tests.ps1 - # This script exists to create and mock a global function, then exit. The actual behavior
GlobalMock-B.Tests.ps1 - # This test depends on some state set up in GlobalMock-A.Tests.ps1. The behavior we're verifying
New-MockObject.Tests.ps1 - describe 'New-MockObject' {
Output.Tests.ps1 - InModuleScope -ModuleName Pester -ScriptBlock {
SetupTeardown.Tests.ps1 - Describe 'Describe-Scoped Test Case setup' {
TestsRunningInCleanRunspace.Tests.ps1 - function Invoke-PesterInJob ($ScriptBlock, [switch] $GenerateNUnitReport)
Pester.Tests.ps1 - $here = Split-Path -Parent $MyInvocation.MyCommand.Path
Guys, I need help!
I stacked in troubleshooting of the current issue. The whole what I did is in the branch https://github.com/it-praktyk/pester/tree/Dev4-1_PSCore_compatibility.
Thank you in advance.
CC: @Jaykul
@nohwnd, I don't understand what the line does.
When I've added Set-StrictMode -Latest at the beginning of the Pester.psm1 $PSVersionTable.ClrVersion$PSVersionTable.ClrVersiont$PSVersionTable.ClrVersion$PSVersionTable.ClrVersion$PSVersionTable.ClrVersionhe error like below is thrown.
Could you look on this, please?
[-] Should validate test results against the nunit 2.5 schema 160ms
Expected: the expression not to throw an exception. Message was {Exception calling "Validate" with "1" argument(s): "The property 'Exception' cannot be found on this object. Verify that the property exists."}
from <FOLDER_PATH>\Pester\Functions\TestResults.Tes$PSVersionTable.ClrVersion$PSVersionTable.ClrVersion$PSVersionTable.ClrVersionts.ps1:148 char:19
+ { $xml.Validate({throw $args.Exception }) } | Should ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
148: { $xml.Validate({throw $args.Exception }) } | Should Not Throw
at Invoke-LegacyAssertion, <FOLDER_PATH>\Pester\Functions\Assertions\Should.ps1: line 190
at <ScriptBlock>, <FOLDER_PATH>\Pester\Functions\TestResults.Tests.ps1: line 148
[Update]
Previously I disabled the line because $PSVersionTable.ClrVersion
is not available on PSCore.
When I've rerun tests without set Set-StrictMode the error message was clear - the xsd schema violation.
3 days ago I've asked for help to resolve the issue #870. I was not clear what does it mean and what I really need.
I tried to resolve issues with not initialized variables in the Gherkin related code - some examples are above. Due to lack of time, I can't learn Gherkin notations and analyze this part of the code.
All your help will be appreciated. Thank you.
Most of the issues are resolved and proposed to merge as a part of the pull request #925.
Gherkin related are sent back to the @Jaykul's fork as a part of the pull request https://github.com/Jaykul/Pester/pull/1 - the code what caused them was not merged to Pester yet.
Some tests fail when Set-StrictMode fail when Set-StrictMode is set to Latest.
Most of the errors are related to Gherkin-style tests under PowerShell 2.0 - especially under execution by Travis-based continues integration.
To reproduce you can add Set-StrictMode at the beginning of Pester.psm1.
The variable '$StepFiles' cannot be retrieved because it has not been set.