-
Notifications
You must be signed in to change notification settings - Fork 753
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
tools: migrate test generation features to gopls
#1594
Comments
@stamblerre I would like to work on this if no one's working. |
Sounds good! /cc @hyangah to confirm that this would be a good thing to work on |
Please correct me if I'm wrong, to generate tests vscode-go calls gotests lib internally as a child process. However, gotests doesn't return any error if test(s) don't get generated other than "No tests were generated for...". The Probably modifying gotests to return an error for existing tests would be a better idea? |
@n1lesh: Thanks for digging into the underlying cause! An alternative option may actually be to move the test generation logic into |
@stamblerre I can work on the |
gopls
The Gopls will handle the add unit tests request following steps below:
NOTE:
|
Cool! A few notes:
Let's just say "Add unit test for X". No need to prefix the code action with "Source:", since it is in the "Source Action" section.
s/grpc/rpc. Also, the command does not return a workspace edit. Rather it calls the Test function naming LGTM. It may be simpler to start with just "Add unit test for function". |
Excited to use this! A couple of suggestions:
|
Cool! Should probably be "Add a test for Bar", but we can discuss that on the CL. This will be great. |
Change https://go.dev/cl/621056 mentions this issue: |
Change https://go.dev/cl/621096 mentions this issue: |
Next CL: Following the existing implementation from For embedding type, we will choose the type name as fields name. E.g. Field
The end goal of the test looks below. (This is generate by the
|
Change https://go.dev/cl/621675 mentions this issue: |
To update this issue with some decisions:
|
All good, though in item 7 I suggest splitting the two cases as it leads to better error messages. (In Google readability reviews people sometimes say "but it's longer", but this is generated code so that's excuse won't fly. ;-) got, err := Foo(args)
if err != nil {
if !test.wantErr {
t.Errorf("Foo(%v) failed: %v", args, err)
}
return
}
if test.wantErr {
t.Fatalf("Foo(%v) succeeded unexpectedly", args)
}
... compare got and test.want ... |
Change https://go.dev/cl/621057 mentions this issue: |
Change https://go.dev/cl/622320 mentions this issue: |
This CL is some glue code which build the connection between the LSP "code action request" with second call which compute the actual DocumentChange. AddTest source code action will create a test file if not already exist and insert a random function at the end of the test file. For testing, an internal boolean option "addTestSourceCodeAction" is created and only effective if set explicitly in marker test. For golang/vscode-go#1594 Change-Id: Ie3d9279ea2858805254181608a0d5103afd3a4c6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/621056 Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Is your feature request related to a problem? Please describe.
I'm always frustrated when I click on "Generate test for function" and see "No tests were generated for ...".
Describe the solution you'd like
I would like to see a reason of why there was no tests were generated. For example - "test for ... already exist".
Additional context
It would be perfect to see a location of generated tests if there is already existing one. Or after successful generation.
The text was updated successfully, but these errors were encountered: