-
Notifications
You must be signed in to change notification settings - Fork 24
Conversation
@sio4 I would love to get your blessing before merging this one. Whenever you have the chance please take a look at it. |
Sorry for the late response. I was not able to take a look at this PR during the weekdays, but I will check it soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look at the PR and found some issues with it. I feel like this approach could be a good one with backward compatibility if we fixed some listed issues. However, I would like to discuss a more basic concept regarding command line options (which was one of my rough ideas for v2 when I worked on #181 and #167). I will leave a comment including that on #241.
// testValuedFlags are the flags on the go test command that | ||
// receive a value, we use this to determine if the last argument | ||
// is a flag or a package path | ||
testValuedFlags = strings.Join([]string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if having a static list of flags is a good way to maintain especially since we support multiple go versions which could have different sets of flags. For example, -covermode
and -coverpkg
are missing.
Also, this approach does not support -args
flag even though I am not sure how many developers use this flag with the apps built with Buffalo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I don't like this part. I added this to be able to understand when a flag received values, this is important to determine if the test command is being passed packages to test. p.e:
go test //
go test -run xxx // No packages
go test -run xxx -p 1 // No packages
go test ./... // packages specified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I know this is added to check if the user gave the module list to test or just gave flags (with values).
My idea on this is simple. I think we can just ignore adding an automatically found module list when the user gave additional flags for go test
. Previously when we need to walk through the given (or automatically collected) modules for -m
supporting before, with switching between -testify.m
and -run
, so the list of target modules was important. However, if we deprecate the behavior of -m
we had and just use the standard -run
, we don't need to care about it anymore and we can let the user complete the command line as the same as when the user runs go test
directly.
Briefly, I would like to make the command the same or similar to the go test
command line:
buffalo test -- -cover ./...
==go test -cover ./...
after preparing test db (just use the user-provided args as is)buffalo test
==go test
after preparing test db (just use the user-provided args as is, which is none)- or
buffalo test
==go test ./...
as a special exception (add./...
for when there is no args at all)
- or
So make buffalo test [...]
equivalent to go test [...]
except for the database preparing part, it could be easy to understand the behavior since all Buffalo users are Go developers, and it is more expectable.
} | ||
|
||
// Add extra args (-testify.m) to the command | ||
cargs = append(cargs, extraArgs(args)...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that the function clean()
(only) removes -m
and -testify.m
from the args and the function extraArgs()
appends -testify.m
at the end of the command line after the list of packages when one of -m
, -testify.m
, or -run
was specified. However, it will not work if the user provides -run TestMethod
since when a user wants to run a specific test case in a single Suite, the proper command line should be something like go test -run TestSuite -testify.m TestMethod
. (see another comment for the old code)
Also, -run
does not always mean to be -testify.m
. E.g. I have a package named utils
in my app which does not use testify (suite) based test cases which to be run with the standard -run TestUtilsFunc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The biggest issue I'm facing is maintaining a functionality that I don't see documented by our tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, we just mentioned the feature in short words, we just supported a simple use case only, and that is for the season of v0.10, which is the season around Go v1.7 or v1.8 maybe. I think we could adapt the testing to the modern version of Go and Buffalo.
https://gobuffalo.io/documentation/guides/testing/#execute-a-single-test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. One consideration to bring here is that the -m feature can be addressed with -run
, developers just have to enter a larger name for the tests. In general I would love to see Buffalo being closer to the stdlib for our upcomming versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I would like to make it easy for Go developers who already know how go
works.
p = strings.TrimPrefix(p, app.PackagePkg+string(filepath.Separator)) | ||
os.Chdir(p) | ||
|
||
if hasTestify(cmd.Args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We previously used this "for each package loop" approach as a workaround for the -testify.m
conditions:
- just with the
-testify.m TestMethod
only without-run TestSuite
, - per package switching of the flag between
-run
and-testify.m
with the (quick and dirty)hasTestify()
helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. IMO we should move to run tests closer to the standard library. At this point, just to support this -testify.m behavior we're disallowing users from passing arguments to the go test
command.
|
||
// DisableFlagParsing is set to true since we will need to allow undefined | ||
// flags to be passed to the go test command. | ||
DisableFlagParsing: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I would like to change this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cobra does not support changing this behavior. AFAIK if we enable this we will have to listen for each of the flags that the go build and test command accept, otherwise Cobra will err.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I explained more clearly (with my limited Yonglish skill) in the issue #241. In short, We can use "end-of-options" for this. Cobra supports the POSIX standard "end-of-options" flag which is the double dash --
, and using it could be acceptable for most Unix-like OS users naturally. By using this, we can both use Cobra's flag parsing for Buffalo-specific flags and pass others to go test
very easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's interesting. I did not try that but when I added test
flags that were not declared in our Cobra command got error. Will take a look at end-of-options
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the end-of-options is the POSIX standard and it will make us and users easy to separate buffalo-specific flags such as --force-migrations
and go test
flags including app-specific flags with the standard flag -args
. However, I am still open to a simpler way too:
POSIX style with simpler internal with Cobra (Cobra makes the args for the go test
)
$ buffalo test --force-migration -- -cover -race ./...
vs.
Go style without end-of-options but with slightly more work of cleaning buffalo-specific args from the original args
$ buffalo test --force-migration -cover -race ./...
Hi @paganotoni, I had time to check this PR and also some background histories and tests for the issue and I left some comments on the issue #241. Please check those comments, I tried to describe in detail what I think about the issue and the underlying consideration for the command line style. |
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment. Otherwise, this will be closed in 7 days. |
This PR was closed because it has been stalled for 45+7 days with no activity. |
What is being done in this PR?
This is related to #241.
What are the main choices made to get to this solution?
What was discovered while working on it? (Optional)
List the manual test cases you've covered before sending this PR: