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

feature: testify not working with import alias #261

Closed
2 tasks done
gjermundgaraba opened this issue Jan 12, 2025 · 6 comments
Closed
2 tasks done

feature: testify not working with import alias #261

gjermundgaraba opened this issue Jan 12, 2025 · 6 comments
Labels
enhancement New feature or request

Comments

@gjermundgaraba
Copy link

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.3

Operating system/version

MacOS 15.2

Output from :checkhealth neotest-golang

==============================================================================
neotest-golang: require("neotest-golang.health").check()

Requirements ~
- OK Binary 'go' found on PATH: /usr/local/go/bin/go
- OK Found go.mod file for /Users/gg/code/ibc-go/testing/chain_test.go in /Users/gg/code/ibc-go/go.mod
- OK Treesitter parser for go is installed
- OK neotest is available
- OK nvim-treesitter is available
- OK nio is available
- OK plenary is available

DAP (optional) ~
- OK Binary 'dlv' found on PATH: /Users/gg/go/bin/dlv
- WARNING dap is not available
- WARNING dapui is not available
- WARNING dap-go is not available

Gotestsum (optional) ~
- OK Binary 'gotestsum' found on PATH: /Users/gg/go/bin/gotestsum
- Found gotestsum to be installed, but not set as test runner.

Sanitization (optional) ~
- OK Sanitization is disabled

Describe the bug

If the testify suite import has been aliased, running tests don't work.
More specifically, they are "not found" (testing: warning: no tests to run):

WARN | 2025-01-12T22:45:58Z+0100 | .../nvim/lazy/neotest-golang/lua/neotest-golang/logging.lua:92 | Test(s) not associated (not found/executed)

Steps To Reproduce

  1. Alias the testify suite import testifysuite "github.com/stretchr/testify/suite"
  2. Try to run a test

Expected Behavior

Ideally, it would work with aliased imports.

Your Lua setup

No response

@gjermundgaraba gjermundgaraba added the bug Something isn't working label Jan 12, 2025
@gjermundgaraba
Copy link
Author

I would be more than happy to give this a shot, but I am not very familiar with the treesitter queries and if this can even be done with the current approach. If this is doable, it would be nice as a starting point, as I would love to expand the testify support (and this could be a good starting point).

@fredrikaverpil
Copy link
Owner

fredrikaverpil commented Jan 13, 2025

Hi @gjermundgaraba

I'm not sure if this can be done and maintain reliability. I believe it's in here that you need to somehow be able to detect the suite.Run or whatever.Run without matching it against "suite".

operand: (identifier) @suite_lib (#eq? @suite_lib "suite")

operand: (identifier) @suite_lib (#eq? @suite_lib "suite")

You can try removing (#eq? @suite_lib "suite") and see where that takes you. But I'm afraid then other potential operands will wrongly be detected as testify suites (examples: router.Run, gin.Engine.Run).

I just recently had a report that these operands were wrongly identified as vanilla go tests, and fixed in this PR: #244

@fredrikaverpil
Copy link
Owner

fredrikaverpil commented Jan 13, 2025

I should add that it's quite difficult to support testify well, as you might imagine 😅
For this reason, I don't really like testify and instead recommend looking into https://pkg.go.dev/gotest.tools/v3 (especially assert.DeepEqual) which works really well with https://pkg.go.dev/github.com/google/go-cmp/cmp/cmpopts and https://pkg.go.dev/google.golang.org/protobuf/testing/protocmp

Copy link
Contributor

github-actions bot commented Feb 3, 2025

This issue has been open for 20 days with no activity. Remove the stale label or add a comment or it will be closed in 10 days.

@github-actions github-actions bot added the Stale label Feb 3, 2025
@fredrikaverpil fredrikaverpil added enhancement New feature or request and removed bug Something isn't working labels Feb 7, 2025
@fredrikaverpil fredrikaverpil changed the title bug: testify not working with import alias feature: testify not working with import alias Feb 7, 2025
@fredrikaverpil
Copy link
Owner

fredrikaverpil commented Feb 7, 2025

Hey again @gjermundgaraba could you please give the testify-regexp branch a try?

I've hardcoded support in #291 for testifysuite "github.com/stretchr/testify/suite" but I'm planning on making it configurable. Would love to hear if this works for you first though. 😄

{
  "fredrikaverpil/neotest-golang" ,
  branch = "testify-regexp",
}

@fredrikaverpil
Copy link
Owner

I've implemented support for this. You will have to add optional config to enable your use case. See the docs for more info:

https://fredrikaverpil.github.io/neotest-golang/config/#testify_import_identifier

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

No branches or pull requests

2 participants