-
Notifications
You must be signed in to change notification settings - Fork 79
testscript: merge coverage from all test binary executions #119
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,82 @@ | ||
unquote scripts/exec.txt | ||
|
||
# The module uses testscript itself. | ||
# Use the checked out module, based on where the test binary ran. | ||
go mod edit -replace=github.com/rogpeppe/go-internal=${GOINTERNAL_MODULE} | ||
go mod tidy | ||
|
||
# First, a 'go test' run without coverage. | ||
go test -vet=off | ||
stdout 'PASS' | ||
! stdout 'total coverage' | ||
|
||
# Then, a 'go test' run with -coverprofile. | ||
# Assuming testscript works well, this results in the basic coverage being 0%, | ||
# since the test binary does not directly run any non-test code. | ||
# The total coverage after merging profiles should end up being 100%, | ||
# as long as all three sub-profiles are accounted for. | ||
# Marking all printlns as covered requires all edge cases to work well. | ||
go test -vet=off -coverprofile=cover.out -v | ||
stdout 'PASS' | ||
stdout '^coverage: 0\.0%' | ||
stdout '^total coverage: 100\.0%' | ||
! stdout 'malformed coverage' # written by "go test" if cover.out is invalid | ||
exists cover.out | ||
|
||
-- go.mod -- | ||
module test | ||
|
||
go 1.15 | ||
-- foo.go -- | ||
package foo | ||
|
||
import "os" | ||
|
||
func foo1() int { | ||
switch os.Args[1] { | ||
case "1": | ||
println("first path") | ||
case "2": | ||
println("second path") | ||
default: | ||
println("third path") | ||
} | ||
return 1 | ||
} | ||
-- foo_test.go -- | ||
package foo | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/rogpeppe/go-internal/gotooltest" | ||
"github.com/rogpeppe/go-internal/testscript" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
os.Exit(testscript.RunMain(m, map[string] func() int{ | ||
"foo": foo1, | ||
})) | ||
} | ||
|
||
func TestFoo(t *testing.T) { | ||
p := testscript.Params{ | ||
Dir: "scripts", | ||
} | ||
if err := gotooltest.Setup(&p); err != nil { | ||
t.Fatal(err) | ||
} | ||
testscript.Run(t, p) | ||
} | ||
-- scripts/exec.txt -- | ||
># Note that foo always fails, to prevent "go build" from doing anything. | ||
> | ||
># Running the command directly; trigger the first path. | ||
>! foo 1 | ||
> | ||
># Running the command via exec; trigger the second path. | ||
>! exec foo 2 | ||
> | ||
># Running the command indirectly, via toolexec; trigger the third path. | ||
>! go build -a -toolexec=foo runtime |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.