Skip to content

assert: ensure message is always displayed & fix under bazel#276

Merged
dnephin merged 6 commits intogotestyourself:mainfrom
cstrahan:bazel-fix
Oct 12, 2023
Merged

assert: ensure message is always displayed & fix under bazel#276
dnephin merged 6 commits intogotestyourself:mainfrom
cstrahan:bazel-fix

Conversation

@cstrahan
Copy link
Contributor

@cstrahan cstrahan commented Oct 2, 2023

Note that I still need to run the tests, but I wanted to get this PR open ASAP.

This PR fixes #274.

Now, when running under bazel test we'll see the following sort of error message when the target test source file can't be found:

--- FAIL: TestAssertShouldWorkUnderBazel (0.00s)
    your_test.go:40: the test source file does not exist: /private/var/tmp/_bazel_charles/99cf13450b07a7c7594bbbe785fbd4ef/sandbox/darwin-sandbox/20/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/some_package/your_package_test_/your_package_test.runfiles/__main__/some_package/your_test.go
        it appears that you are running this test under Bazel (target: //some_package:your_package_test);
        check that your test source files are added as test data in your go_test targets.
        example:
            go_test(
                name = "your_package_test",
                     srcs = ["your_test.go"],
                     deps = ["@tools_gotest_v3//assert"],
                     data = glob(["*_test.go"] # <====== test source files added as test data here!
            )
    your_test.go:40: assertion failed: but assert failed to find the expression to print: a should equal b
FAIL

If the user adds the test source file to their test data in the respective go_test target, they'll now see something like:

--- FAIL: TestAssertShouldWorkUnderBazel (0.00s)
    your_test.go:40: assertion failed: a is not b: a should equal b
FAIL

@CLAassistant
Copy link

CLAassistant commented Oct 2, 2023

CLA assistant check
All committers have signed the CLA.

@cstrahan
Copy link
Contributor Author

cstrahan commented Oct 2, 2023

All tests run via go test ./... pass, with the exception of these two (which I believe are due to an issue with the tests when run under macOS, as they were failing before my changes):

--- FAIL: TestChangeWorkingDir (0.00s)
    --- FAIL: TestChangeWorkingDir/changed_to_dir (0.00s)
        env_test.go:138: assertion failed: /private/var/folders/vc/8x3823591cz2_gpk94zpjfv00000gq/T/TestChangeWorkingDir-1487778779 (string) != /var/folders/vc/8x3823591cz2_gpk94zpjfv00000gq/T/TestChangeWorkingDir-1487778779 (string)
--- FAIL: TestChangeWorkingDir_IntegrationWithCleanup (0.00s)
    --- FAIL: TestChangeWorkingDir_IntegrationWithCleanup/cleanup_in_subtest (0.00s)
        env_test.go:157: assertion failed: /private/var/folders/vc/8x3823591cz2_gpk94zpjfv00000gq/T/TestChangeWorkingDir_IntegrationWithCleanup-2603325723 (string) != /var/folders/vc/8x3823591cz2_gpk94zpjfv00000gq/T/TestChangeWorkingDir_IntegrationWithCleanup-2603325723 (string)

I'll see if I can fix the lint issue.

@cstrahan
Copy link
Contributor Author

cstrahan commented Oct 2, 2023

Hmm. The ci/circleci: test-golang-1.20 check is failing:

∅  .
✓  assert (689ms)
∅  icmd/internal/stub
∅  internal/assert
∅  internal/cleanup
∅  internal/difflib
∅  internal/maint
∅  x
✓  internal/format (71ms)
✓  assert/opt (72ms)
✓  skip (75ms)
✓  env (75ms)
✓  assert/cmp (75ms)
✓  golden (75ms)
✓  internal/source (76ms)
✓  fs (170ms)
✖  poll (271ms)
✓  icmd (1.411s)
✓  x/subtest (4ms)
✓  assert/cmd/gty-migrate-from-testify (20.483s)

=== Skipped
=== SKIP: env TestPatchAllWindows (0.00s)
    env_test.go:70: runtime.GOOS != "windows"

=== Failed
=== FAIL: poll TestWaitOn_WithCompare (0.09s)
    poll_test.go:86: assertion failed: string "timeout hit after 10ms: first check never completed" does not contain "assertion failed: 3 (int) != 4 (int)"

DONE 289 tests, 1 skipped, 1 failure in 54.413s

Exited with code exit status 1

but that test passes with [email protected] on my machine (running macOS). Maybe a flaky test? Might bump CI with an empty commit.

@cstrahan
Copy link
Contributor Author

cstrahan commented Oct 2, 2023

Yay! The tests pass. But I just realized that my editor was hiding the fact that tabs and spaces got mixed together in that big error message string. Just pushed a commit to fix that up.

And move logic to a function so that variables can be closer to where they are used
Copy link
Member

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! I made a couple small changes, but overall this looks great.

Primarily I moved the variables to a bazel.go file, and extracted some of the logic to a new function. This way the variables and the code can be located a bit closer together.

I also extracted the multi-line error message to a raw string to make it a bit easier to read in code. The raw string removes the need to escape the double quotes.

If these changes look alright to you I think this is ready to be merged.

name = "your_package_test",
srcs = ["your_test.go"],
deps = ["@tools_gotest_v3//assert"],
data = glob(["*_test.go"])
Copy link
Member

Choose a reason for hiding this comment

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

On this line I added the trailing ) which I believe was missing, and removed the "test source files added as test data here!" comment. Does that seem ok? I guess the glob should capture all the test files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Yes, I think this is great 👍

@cstrahan
Copy link
Contributor Author

@dnephin Those changes look great! Don't see anything else I'd change. Thanks!

@dnephin dnephin merged commit 1fa4ef3 into gotestyourself:main Oct 12, 2023
Crown0815 pushed a commit to Crown0815/forgejo-runner-windows that referenced this pull request May 21, 2025
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [gotest.tools/v3](https://github.com/gotestyourself/gotest.tools) | require | patch | `v3.5.1` -> `v3.5.2` |

---

### Release Notes

<details>
<summary>gotestyourself/gotest.tools (gotest.tools/v3)</summary>

### [`v3.5.2`](https://github.com/gotestyourself/gotest.tools/releases/tag/v3.5.2)

[Compare Source](gotestyourself/gotest.tools@v3.5.1...v3.5.2)

#### What's Changed

-   assert: ensure message is always displayed & fix under bazel by [@&#8203;cstrahan](https://github.com/cstrahan) in gotestyourself/gotest.tools#276
-   go.mod: golang.org/x/tools v0.13.0 for go1.22+ compatibility by [@&#8203;thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#282
-   poll: Continue(): use format.Message for formatting by [@&#8203;thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#279
-   fix TestFromDirSymlink on Windows due to missing drive-letter by [@&#8203;thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#283
-   Fix various linting issues and minor bugs by [@&#8203;thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#280
-   fix badges in readme, gofmt, and minor linting fix by [@&#8203;thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#284
-   circleci: add go1.21, go1.22, go1.23, and update golangci-lint to v1.60.3 by [@&#8203;thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#285
-   assert, assert/cmp: un-deprecate assert.ErrorType for now by [@&#8203;thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#286

#### New Contributors

-   [@&#8203;cstrahan](https://github.com/cstrahan) made their first contribution in gotestyourself/gotest.tools#276

**Full Changelog**: gotestyourself/gotest.tools@v3.5.1...v3.5.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC), Automerge - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC).

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

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

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

---

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

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMTIuMCIsInVwZGF0ZWRJblZlciI6IjM5LjI1Mi4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/524
Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
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.

source.CallExprArgs fails to open target source file when run under bazel

3 participants