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

feat: add Value3, V3, Value4, V4 #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dolmen
Copy link

@dolmen dolmen commented Jan 5, 2023

Add Value3, V3, Value4, V4 like Value, Value2.
Add test coverage for Value2.

error.go Outdated Show resolved Hide resolved
error.go Outdated Show resolved Hide resolved

fmt.Println("Panic message:", must.Panic(func() {
must.Value2(1, 2, errors.New("P"))
}).(error).Error())
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should write one good example for all Value# functions and write the rest as tests. What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

I think we should merge to have good coverage, and then work on doc improvements.

Doc and examples for Value3/V3/Value4/V4 are quite useless because redundant (if someone has read Value2/V2 that should be enough), but we could improve examples by using concrete functions from stdlib.

Copy link
Owner

Choose a reason for hiding this comment

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

The coding style (error type assertion) is fine as a test, but should not be in an example because it's not guaranteed by the API https://github.com/xiegeo/must#compatibility

Values used in panics are only for debugging. No guarantees are provided on how panics are constructed.

If you have a use case. It's possible to provide a function or change the docs to reflect it. My thinking on this is if you need panic to be created in a particular way, it's better to roll your own than use a dependency.

Copy link
Author

@dolmen dolmen Jan 31, 2023

Choose a reason for hiding this comment

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

The assertion is applied on the return value from must.Panic. In this case it is an error because must.Value2 panics with the errors.New("P") result.

I don't think that my example goes beyond the API contract. But could you reply to those questions:

  • Isn't it guaranteed that must.Value2 panics with the 3 argument?
  • Isn't it guaranteed that must.Panic returns the raw value caught by recover which, in this case, is an error because it comes from the 3 argument given to Value2?

Copy link
Author

@dolmen dolmen Jan 31, 2023

Choose a reason for hiding this comment

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

Well the response to the second question is in https://github.com/xiegeo/must#compatibility and was written in #14 (comment).

Copy link
Author

Choose a reason for hiding this comment

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

Would it be ok if I transform the Examples into just Tests?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, write as a test is ok.

@xiegeo xiegeo added this to the Version 1 milestone Jan 7, 2023
@xiegeo xiegeo added the enhancement New feature or request label Jan 7, 2023
Add Value3, V3, Value4, V4.
Add test coverage for Value2.
@dolmen dolmen force-pushed the feat/Value3,Value4 branch from e443440 to 1c30cb7 Compare January 11, 2023 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants