-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add -trimpath flag #128
Add -trimpath flag #128
Conversation
@@ -0,0 +1,47 @@ | |||
package utils |
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.
There's a few common functions that are fairly important, so I'd like to isolate them into a utils
package and add proper 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.
A few minor suggestions
@@ -22,6 +22,8 @@ type SummaryTableOptions struct { | |||
// tparse | |||
// /seed-up-down-to-zero | |||
Trim bool | |||
|
|||
TrimPath 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.
Maybe a comment here, there is one for other variable
for _, pkg := range packages { | ||
names = append(names, pkg.Summary.Package) | ||
} | ||
packagePrefix := utils.FindLongestCommonPrefix(names) | ||
|
||
for _, pkg := range packages { | ||
elapsed := strconv.FormatFloat(pkg.Summary.Elapsed, 'f', 2, 64) + "s" |
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 would have used
elapsed := strconv.FormatFloat(pkg.Summary.Elapsed, 'f', 2, 64) + "s" | |
elapsed := pkg.Summary.Elapsed.Truncate(10 * time.Millisecond).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.
Elapsed is a float64, using strconv.FormatFloat
seems most appropriate. If it were time.Time
then truncate would probably make more sense.
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.
Oh indeed, I missed that.
first, last := paths[0], paths[len(paths)-1] | ||
if first == last { | ||
return first | ||
} |
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.
What happens if the path is something like
foo/bar/foo
Or something like that, my point is if the first last are equal.
I could happen when the project has a replace
in the go.mod file to rewrite long project URLs to something shorter
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.
It depends on what the other paths are. I added a test case just in case, but this is what I'd expect:
{
paths: []string{
"foo/bar/foo",
"foo/foo/foo",
},
want: "foo/",
},
This flag allows the caller to trim the package name which gets displayed in both the package table and tests table.
There's a special case for
-trimpath=auto
to find the longest common path and use that as the prefix to trim. Almost always this is what a user would want (I think).Fix #125
Filed a separate issue for the packages that are not being omitted (no tests), #126
Examples: