Skip to content

Conversation

brackendawson
Copy link
Collaborator

Summary

If you passed a non-collection to IsIncreasing or any of its compatriots then the assertion would return false without failing the test.

Changes

  • Make isOrdered() return Fail() rather than false in validation so that the test will fail.
  • Test the above.

Motivation

The following invalid usage would previously pass:

var nonList int
assert.IsIncreasing(t, nonList)

Related issues

Closes #1419

@dolmen dolmen added bug Changes Requested pkg-assert Change related to package testify/assert labels Jul 21, 2023
)

// isOrdered checks that collection contains orderable elements.
func isOrdered(t TestingT, object interface{}, allowedComparesResults []CompareType, failMessage string, msgAndArgs ...interface{}) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

isOrdered is now an Helper. It must have the helper block before calling Fail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The call to Helper must be inside IsDecreasing() et al, not inside isOrdered(), this is not a regression as the functions are not currently helpers. We should have a separate issue to add Helper() calls to exported functions which need them.

Copy link
Collaborator

@dolmen dolmen Oct 16, 2023

Choose a reason for hiding this comment

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

The call to Helper must be inside IsDecreasing() et al, not inside isOrdered()

isOrdered now calls assert.Fail so errors will be reported there. But that not what we want. It is now an Helper while it wasn't the case before.

this is not a regression as the functions are not currently helpers.

But you are changing the behaviour.

We should have a separate issue to add Helper() calls to exported functions which need them.

On this matter #1423 is waiting for your approval.

So I'm asking again to fix this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I will fix the Helper method calls in this PR.

@dolmen dolmen changed the title IsIncreasing et al can return false w/out failing assert: IsIncreasing et al can return false w/out failing Aug 8, 2023
brackendawson and others added 3 commits February 24, 2024 14:55
If you passed a non-collection to IsIncreasing or any of its compatriots then the assertion would return false without failing the test.
Because maps are collections but not ordered.

Co-authored-by: Olivier Mengué <[email protected]>
@brackendawson
Copy link
Collaborator Author

I've moved the branch for this PR to my personal fork and opened #1787

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

Labels

bug pkg-assert Change related to package testify/assert

Projects

None yet

Development

Successfully merging this pull request may close these issues.

assert.IsIncreasing can return false without failing the test

2 participants