Skip to content

Changes to allow tests to be run outside of CI #882

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

Merged

Conversation

JamesWTruher
Copy link
Contributor

@JamesWTruher JamesWTruher commented Feb 10, 2018

PR Summary

Test and build changes to enable test execution outside of CI environment
Reduce verbosity of buildCore script
Simplify test execution to a single command with a single result file

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets. Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • User facing documentation needed
  • Change is not breaking
  • Make sure you've added a new test if existing tests do not effectively test the code changed
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

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

Great work but maybe the upgrade to Pester v4 should be a separate PR?

@@ -97,19 +97,16 @@ Describe "Test importing correct customized rules" {
$customizedRulePath.Count | Should Be 1
}

It "will show the custom rule when given a rule folder path with trailing backslash" {
It "will show the custom rule when given a rule folder path with trailing backslash" -skip:(!$IsWindows){
Copy link
Collaborator

@bergmeister bergmeister Feb 10, 2018

Choose a reason for hiding this comment

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

I guess you are planning to introduce a Travis build for Linux/Mac as well? I think it would be good if you open an issue with a brief description of the high level plan of PR's to come so that we can see the big picture.

Copy link
Contributor Author

@JamesWTruher JamesWTruher Feb 12, 2018

Choose a reason for hiding this comment

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

yup, that's the plan, I'll work on that issue
the start is here: #886

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks. Looks good to me.

}

It "will show the custom rules when given a glob" {
# needs fixing for Linux
$expectedNumRules = 4
if (Test-PSEditionCoreCLRLinux)
if ( ! $IsWindows )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very minor but here and in other changes the spacing inside the parenthesis is inconsistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure - will fix

$initialTestScript = Get-Content $directory\TestScriptWithFixableWarnings.ps1 -Raw
BeforeAll {
$scriptName = "TestScriptWithFixableWarnings.ps1"
$testSource = join-path $PSScriptRoot ${scriptName}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think ${scriptName} can be simplified to $scriptName

Copy link
Contributor Author

@JamesWTruher JamesWTruher Feb 12, 2018

Choose a reason for hiding this comment

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

the "${< name >}" is the formal identifier of the variable. I should have done it to the first variable too. You'll start to see more of these in my PRs. I should note that this is much different than "$($variable)" which is definitely unneeded

Copy link
Collaborator

Choose a reason for hiding this comment

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

I totally agree that braces make sense inside a string for string interpolation and is better than "$($variable)" but can you briefly explain please why one would use curly braces for variables outside of strings (the only use case that I found here is when the variable name itself contains special characters) or is this just a question of style?

Copy link
Contributor Author

@JamesWTruher JamesWTruher Feb 13, 2018

Choose a reason for hiding this comment

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

in the case above it's inconsistent (since it's not used with $PSScriptRoot so it's a bit confusing. My preference is to use braces all the time (sort of like full commands vs aliases), and it's mostly habit. When I'm in a hurry, I sometimes omit them.
Since most don't have them, I removed them here to avoid the confusion

@@ -63,7 +63,7 @@ Param
$RequiredVersion
)

# #Requires -Module @{ModuleName = 'Pester'; ModuleVersion = '3.4.0'}
# #Requires -Module @{ModuleName = 'Pester'; ModuleVersion = '4.1.1'}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a technical reason to upgrade to v4 as part of this PR? I think it might be better to do this as a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the test fixes are sort of entwined, by doing them all at once I won't need to change the tests again.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, I see. Then we also need to update the documented version number of Pester in the test section here of the developer guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

quite right - fixed

@@ -106,7 +106,7 @@ function SuppressPwdParam()
}

Context "Rule suppression within DSC Configuration definition" {
It "Suppresses rule" -skip:((Test-PSEditionCoreCLRLinux) -or ($PSVersionTable.PSVersion -lt [Version]'5.0.0')) {
It "Suppresses rule" -skip:((!$IsWindows) -or ($PSVersionTable.PSVersion -lt [Version]'5.0.0')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

$PSVersionTable.PSVersion.Major -lt 5 looks more elegant to me but this might be just a question of style and therefore opinionated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's fine - I have no preference

}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a change of the file's encoding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it doesn't look like it. it looks like there was previously no newline at the end of the file.

@@ -66,7 +66,7 @@ $x = @{ }
}

Context "When assignment statements are in DSC Configuration" {
It "Should find violations when assignment statements are not aligned" {
It "Should find violations when assignment statements are not aligned" -skip:($IsLinux -or $IsMacOS) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not simply !$isWindows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yah

@@ -29,7 +29,7 @@ Describe "UseIdenticalMandatoryParametersForDSC" {
}

# todo add a test to check one violation per function
It "Should find a violations" {
It "Should find a violations" -pending {
Copy link
Collaborator

@bergmeister bergmeister Feb 10, 2018

Choose a reason for hiding this comment

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

Why pending?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the test is marked as TODO, and the comment seems like it is a test in potentio rather than something useful since it would only be checking a file that is known to be good.

Mark some tests as pending that weren't actually doing anything
Skip DSC tests on Mac/Linux
Update to use Pester version 4.1.1
Change logic in appveyor to invoke pester only once
@JamesWTruher JamesWTruher changed the title WIP: Changes to allow tests to be run outside of CI Changes to allow tests to be run outside of CI Feb 15, 2018
@JamesWTruher
Copy link
Contributor Author

JamesWTruher commented Feb 15, 2018

@bergmeister I think this is ready now - what do you think?

@bergmeister
Copy link
Collaborator

@JamesWTruher Overall most changes look OK (although I cannot verify some technical details why some stuff does not work on Windows but I think it is OK to trust to you on that).
My 2 thoughts are:

  • Should we adapt all assertion operator to the new pester v4 syntax with dashes? Although the old syntax still works, mixing old and new style is discouraged and will bite us at some point if we don't change it now. I don't mind if you do it later in another PR but we should be aware of this problem.
  • Should we add more details to the rule documentation due to the different platform specific behaviour that the tests show?

@JamesWTruher
Copy link
Contributor Author

I'm actually not sure why there are differences between the platforms either, my changes were more mechanical (removing the broken check for linux, which didn't include mac, etc). I will continue to investigate that. As for the update to Pester 4 syntax, that's tracked in #890.
As for documentation, any rule which works differently between platforms should be understood and documented.

@JamesWTruher JamesWTruher merged commit de28e4f into PowerShell:development Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants