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

Generate better comments for require package #1610

Conversation

Neokil
Copy link
Contributor

@Neokil Neokil commented Jun 13, 2024

Summary

The comments for the require package were just copied over from the assert package when generating the functions. This could lead to confusion because

  1. The code-examples were showing examples using the assert package instead of the require package
  2. The function-documentation was not mentioning that the functions were calling t.FailNow() which is some critical information when using this package.

Changes

  1. Added a "replace" function to the template
  2. require.go.tmpl now replaces the package name accordingly
  3. require.go.tmpl now adds another line to the function-docs explaining the difference to the assert-function

Motivation

When new developers are coming in they most likely did not go through the github-documentation for every package used in the application. But what they do is read the function-docs when they go through code to understand what it is doing.
In case of test-cases using both require and assert it gets confusing because the function docs for the require package are referencing the assert package and don't really document the actual function.

The comments for the require package were just copied over
from the assert package when generating the functions.
This could lead to confusion because
1. The code-examples were showing examples using the
assert package instead of the require package
2. The function-documentation was not mentioning that
the functions were calling `t.FailNow()` which is some
critical information when using this package.
require/require.go.tmpl Outdated Show resolved Hide resolved
@dolmen dolmen added pkg-require Change related to package testify/require internal/codegen Change related to internal code generation documentation labels Jun 13, 2024
@dolmen
Copy link
Collaborator

dolmen commented Jun 13, 2024

I've just merged #1607, so please rebase and run codegen.

@hendrywiranto
Copy link
Contributor

this will close #1609 too

@Neokil Neokil requested a review from dolmen June 17, 2024 07:16
@Neokil
Copy link
Contributor Author

Neokil commented Jun 25, 2024

somehow I cannot add reviewers the to the PR, but maybe @boyan-soubachov, @dolmen, @MovieStoreGuy, @arjunmahishi or @brackendawson can one of you have a look?

@Neokil
Copy link
Contributor Author

Neokil commented Jul 31, 2024

any change to get someone to review/merge this?

Copy link
Collaborator

@brackendawson brackendawson left a comment

Choose a reason for hiding this comment

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

The change to swap assert. with require. is good. 👍 It should be safe as if any assert examples ever use msgAndArgs because the syntax will be compatible with require. I considered if inline examples should use the package name at all, in the standard library they do, despite links to functions not doing.

Adding a note about t.FailNow to every requirement is too much. The doc for require already says they stop test execution, we should just change this sentence to mention that it uses t.FailNow. The README.md also mentions t.FailNow, but these two docs should probably match one-another.

@brackendawson
Copy link
Collaborator

brackendawson commented Oct 9, 2024

this will close #1609 too

I'm afraid it wont, requre.Error has no return value. That docstring needs to be made into something that will work for both packages.

@Neokil
Copy link
Contributor Author

Neokil commented Oct 15, 2024

@brackendawson just removed the additional comment as you requested.

I have to say that IMO a hint like this would be really helpful after all to all people that are new to the package. When you encounter it in an existing project you will only see the function-comments in your IDE with no hint to the t.FailNow(). It is only when you are actually looking into the Github of the library that you will find that information. If you land on the pkg.go.dev page because you want to see the documentation for the function to see why it terminated your test you need to know that you have to scroll up to the top or else you will not find that info.

@brackendawson
Copy link
Collaborator

I have to say that IMO a hint like this would be really helpful after all to all people that are new to the package. When you encounter it in an existing project you will only see the function-comments in your IDE with no hint to the t.FailNow(). It is only when you are actually looking into the Github of the library that you will find that information. If you land on the pkg.go.dev page because you want to see the documentation for the function to see why it terminated your test you need to know that you have to scroll up to the top or else you will not find that info.

I hear you. And it's not that I disagree with any of that. But there are a lot of other notes that we could add to each function's docstring and there is a point where we're better not making them larger. For me the concept of t.Error vs t.Fatal doesn't feel so surprising, even if you might not be familiar with our nomenclature of assert and require. Just my opinion.

Going to allow some time for other maintainers to review before I merge.

@brackendawson brackendawson merged commit 75a239b into stretchr:master Oct 23, 2024
8 checks passed
apricote pushed a commit to hetznercloud/fleeting-plugin-hetzner that referenced this pull request Nov 25, 2024
…nercloud/fleeting-plugin-hetzner!175)

This MR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/stretchr/testify](https://github.com/stretchr/testify) | require | minor | `v1.9.0` -> `v1.10.0` |

---

### Release Notes

<details>
<summary>stretchr/testify (github.com/stretchr/testify)</summary>

### [`v1.10.0`](https://github.com/stretchr/testify/releases/tag/v1.10.0)

[Compare Source](stretchr/testify@v1.9.0...v1.10.0)

#### What's Changed

##### Functional Changes

-   Add PanicAssertionFunc by [@&#8203;fahimbagar](https://github.com/fahimbagar) in stretchr/testify#1337
-   assert: deprecate CompareType by [@&#8203;dolmen](https://github.com/dolmen) in stretchr/testify#1566
-   assert: make YAML dependency pluggable via build tags by [@&#8203;dolmen](https://github.com/dolmen) in stretchr/testify#1579
-   assert: new assertion NotElementsMatch by [@&#8203;hendrywiranto](https://github.com/hendrywiranto) in stretchr/testify#1600
-   mock: in order mock calls by [@&#8203;ReyOrtiz](https://github.com/ReyOrtiz) in stretchr/testify#1637
-   Add assertion for NotErrorAs by [@&#8203;palsivertsen](https://github.com/palsivertsen) in stretchr/testify#1129
-   Record Return Arguments of a Call by [@&#8203;jayd3e](https://github.com/jayd3e) in stretchr/testify#1636
-   assert.EqualExportedValues: accepts everything by [@&#8203;redachl](https://github.com/redachl) in stretchr/testify#1586

##### Fixes

-   assert: make tHelper a type alias by [@&#8203;dolmen](https://github.com/dolmen) in stretchr/testify#1562
-   Do not get argument again unnecessarily in Arguments.Error() by [@&#8203;TomWright](https://github.com/TomWright) in stretchr/testify#820
-   Fix time.Time compare by [@&#8203;myxo](https://github.com/myxo) in stretchr/testify#1582
-   assert.Regexp: handle \[]byte array properly by [@&#8203;kevinburkesegment](https://github.com/kevinburkesegment) in stretchr/testify#1587
-   assert: collect.FailNow() should not panic by [@&#8203;marshall-lee](https://github.com/marshall-lee) in stretchr/testify#1481
-   mock: simplify implementation of FunctionalOptions by [@&#8203;dolmen](https://github.com/dolmen) in stretchr/testify#1571
-   mock: caller information for unexpected method call by [@&#8203;spirin](https://github.com/spirin) in stretchr/testify#1644
-   suite: fix test failures by [@&#8203;stevenh](https://github.com/stevenh) in stretchr/testify#1421
-   Fix issue [#&#8203;1662](stretchr/testify#1662) (comparing infs should fail) by [@&#8203;ybrustin](https://github.com/ybrustin) in stretchr/testify#1663
-   NotSame should fail if args are not pointers [#&#8203;1661](stretchr/testify#1661) by [@&#8203;sikehish](https://github.com/sikehish) in stretchr/testify#1664
-   Increase timeouts in Test_Mock_Called_blocks to reduce flakiness in CI by [@&#8203;sikehish](https://github.com/sikehish) in stretchr/testify#1667
-   fix: compare functional option names for indirect calls by [@&#8203;arjun-1](https://github.com/arjun-1) in stretchr/testify#1626

##### Documantation, Build & CI

-   .gitignore: ignore "go test -c" binaries by [@&#8203;dolmen](https://github.com/dolmen) in stretchr/testify#1565
-   mock: improve doc by [@&#8203;dolmen](https://github.com/dolmen) in stretchr/testify#1570
-   mock: fix FunctionalOptions docs by [@&#8203;snirye](https://github.com/snirye) in stretchr/testify#1433
-   README: link out to the excellent testifylint by [@&#8203;brackendawson](https://github.com/brackendawson) in stretchr/testify#1568
-   assert: fix typo in comment by [@&#8203;JohnEndson](https://github.com/JohnEndson) in stretchr/testify#1580
-   Correct the EventuallyWithT and EventuallyWithTf example by [@&#8203;JonCrowther](https://github.com/JonCrowther) in stretchr/testify#1588
-   CI: bump softprops/action-gh-release from 1 to 2 by [@&#8203;dependabot](https://github.com/dependabot) in stretchr/testify#1575
-   mock: document more alternatives to deprecated AnythingOfTypeArgument by [@&#8203;dolmen](https://github.com/dolmen) in stretchr/testify#1569
-   assert: Correctly document EqualValues behavior by [@&#8203;brackendawson](https://github.com/brackendawson) in stretchr/testify#1593
-   fix: grammar in godoc by [@&#8203;miparnisari](https://github.com/miparnisari) in stretchr/testify#1607
-   .github/workflows: Run tests for Go 1.22 by [@&#8203;HaraldNordgren](https://github.com/HaraldNordgren) in stretchr/testify#1629
-   Document suite's lack of support for t.Parallel by [@&#8203;brackendawson](https://github.com/brackendawson) in stretchr/testify#1645
-   assert: fix typos in comments by [@&#8203;alexandear](https://github.com/alexandear) in stretchr/testify#1650
-   mock: fix doc comment for NotBefore by [@&#8203;alexandear](https://github.com/alexandear) in stretchr/testify#1651
-   Generate better comments for require package by [@&#8203;Neokil](https://github.com/Neokil) in stretchr/testify#1610
-   README: replace Testify V2 notice with [@&#8203;dolmen](https://github.com/dolmen)'s V2 manifesto by [@&#8203;hendrywiranto](https://github.com/hendrywiranto) in stretchr/testify#1518

#### New Contributors

-   [@&#8203;fahimbagar](https://github.com/fahimbagar) made their first contribution in stretchr/testify#1337
-   [@&#8203;TomWright](https://github.com/TomWright) made their first contribution in stretchr/testify#820
-   [@&#8203;snirye](https://github.com/snirye) made their first contribution in stretchr/testify#1433
-   [@&#8203;myxo](https://github.com/myxo) made their first contribution in stretchr/testify#1582
-   [@&#8203;JohnEndson](https://github.com/JohnEndson) made their first contribution in stretchr/testify#1580
-   [@&#8203;JonCrowther](https://github.com/JonCrowther) made their first contribution in stretchr/testify#1588
-   [@&#8203;miparnisari](https://github.com/miparnisari) made their first contribution in stretchr/testify#1607
-   [@&#8203;marshall-lee](https://github.com/marshall-lee) made their first contribution in stretchr/testify#1481
-   [@&#8203;spirin](https://github.com/spirin) made their first contribution in stretchr/testify#1644
-   [@&#8203;ReyOrtiz](https://github.com/ReyOrtiz) made their first contribution in stretchr/testify#1637
-   [@&#8203;stevenh](https://github.com/stevenh) made their first contribution in stretchr/testify#1421
-   [@&#8203;jayd3e](https://github.com/jayd3e) made their first contribution in stretchr/testify#1636
-   [@&#8203;Neokil](https://github.com/Neokil) made their first contribution in stretchr/testify#1610
-   [@&#8203;redachl](https://github.com/redachl) made their first contribution in stretchr/testify#1586
-   [@&#8203;ybrustin](https://github.com/ybrustin) made their first contribution in stretchr/testify#1663
-   [@&#8203;sikehish](https://github.com/sikehish) made their first contribution in stretchr/testify#1664
-   [@&#8203;arjun-1](https://github.com/arjun-1) made their first contribution in stretchr/testify#1626

**Full Changelog**: stretchr/testify@v1.9.0...v1.10.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yOC4wIiwidXBkYXRlZEluVmVyIjoiMzkuMjguMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation internal/codegen Change related to internal code generation pkg-require Change related to package testify/require
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants