-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/errtrace: Fix toolexec with
go run main.go
When compiling files passed as command line arguments, go uses a special package name, "command-line-arguments". Similarly for tests, it uses "command-line-arguments.test". Rather than hardcoding these special package names, let's update the stdlib detection to: * Rule out any package with "." (as no stdlib packages contain periods) * Look for "-std" in the arguments passed to compile Update the toolexec tests to compile with files passed directly on the command line, and verify both "go run" and "go build".
- Loading branch information
Showing
5 changed files
with
118 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//go:build go1.21 | ||
|
||
package main | ||
|
||
import "slices" | ||
|
||
func slicesContains[T comparable](s []T, find T) bool { | ||
return slices.Contains[[]T](s, find) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//go:build !go1.21 | ||
|
||
package main | ||
|
||
func slicesContains[T comparable](s []T, find T) bool { | ||
for _, v := range s { | ||
if v == find { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestFoo(t *testing.T) { | ||
t.Errorf("fail") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters