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

Fix the compare different type rule, to allow using WithTransform #111

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

nunnatsa
Copy link
Owner

@nunnatsa nunnatsa commented Oct 3, 2023

Description

The WithTransform matcher can be used to transform the actual value type. This PR fix a false positive when using this matcher to change the actual value type to match the matcher type.

For example:

Expect(uint(5)).Should(WithTransform(func(i uint) int { return int(i) }, Equal(5)))

In this case, the test should work because the transform function (the first parameter of the WithTransform matcher) casts the uint actual value to int, to match the Equal(5) matcher.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added test case and related test data
  • Update the functional test

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I ran golangci-lint

@nunnatsa

The `WithTransform` matcher can be used to transform the actual value
type. This PR fix a false positive when using this matcher to change the
actual value type to match the matcher type.

For example:
```go
Expect(uint(5)).Should(WithTransform(func(i uint) int { return int(i) }, Equal(5)))
```

In this case, the test should work because the transform function (the
first parameter of the `WithTransform` matcher) casts the `uint` actual
value to `int`, to match the `Equal(5)` matcher.
@nunnatsa nunnatsa merged commit 8a24a39 into main Oct 3, 2023
1 check passed
@nunnatsa nunnatsa deleted the fix-comp-type-rule branch October 3, 2023 09:10
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.

1 participant