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

Quote input string in BeNullOrEmpty error #2329

Merged
merged 1 commit into from Apr 3, 2023

Conversation

fflaten
Copy link
Collaborator

@fflaten fflaten commented Mar 28, 2023

PR Summary

Fix missing quotes when single string is passed to Should -BeNullOrEmpty.

/cc @johlju

PR Checklist

  • PR has meaningful title
  • Summary describes changes
  • PR is ready to be merged
    • If not, use the arrow next to Create Pull Request to mark it as a draft. PR can be marked Ready for review when it's ready.
  • Tests are added/update (if required)
  • Documentation is updated/added (if required)

@fflaten fflaten added the Bug label Mar 28, 2023
@fflaten fflaten changed the title Quote input string BeNullOrEmpty error Quote input string in BeNullOrEmpty error Mar 28, 2023
@@ -52,7 +53,8 @@ function Should-BeNullOrEmpty([object[]] $ActualValue, [switch] $Negate, [string
$failureMessage = NotShouldBeNullOrEmptyFailureMessage -Because $Because
}
else {
$failureMessage = ShouldBeNullOrEmptyFailureMessage -ActualValue $ActualValue -Because $Because
$valueToFormat = if ($singleValue) { $expandedValue } else { $ActualValue }
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to affect non empty hashtables too. Shall we add a unit tests to verify the exception message when the hast table is not empty? So it too returns the expected message? There is an existing test at line 22-24 but it does not verify the exception message.

Copy link
Collaborator Author

@fflaten fflaten Mar 29, 2023

Choose a reason for hiding this comment

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

We don't do any special formatting for hashtables. It only drops the outer array, which in a single-item case should be the array Pester wrapped pipeline-input in.

@{ hello = "world" } | Should -BeNullOrEmpty
# Pester 5.3.3
Expected $null or empty, but got @(System.Collections.Hashtable).

# After PR
Expected $null or empty, but got System.Collections.Hashtable

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good.

@nohwnd nohwnd merged commit dc120cd into pester:main Apr 3, 2023
14 checks passed
@fflaten fflaten deleted the benullorempty-format branch April 3, 2023 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants