| 1 |
# Test of -test flag. |
| 2 |
|
| 3 |
deadcode -test -filter=example.com example.com/p |
| 4 |
|
| 5 |
want "Dead" |
| 6 |
!want "Live1" |
| 7 |
!want "Live2" |
| 8 |
|
| 9 |
want "ExampleDead" |
| 10 |
!want "ExampleLive" |
| 11 |
|
| 12 |
-- go.mod -- |
| 13 |
module example.com |
| 14 |
go 1.18 |
| 15 |
|
| 16 |
-- p/p.go -- |
| 17 |
package p |
| 18 |
|
| 19 |
func Live1() {} |
| 20 |
func Live2() {} |
| 21 |
func Dead() {} |
| 22 |
|
| 23 |
-- p/p_test.go -- |
| 24 |
package p_test |
| 25 |
|
| 26 |
import "example.com/p" |
| 27 |
|
| 28 |
import "testing" |
| 29 |
|
| 30 |
func Test(t *testing.T) { |
| 31 |
p.Live1() |
| 32 |
} |
| 33 |
|
| 34 |
func ExampleLive() { |
| 35 |
p.Live2() |
| 36 |
// Output: |
| 37 |
} |
| 38 |
|
| 39 |
// A test Example function without an "Output:" comment is never executed. |
| 40 |
func ExampleDead() { |
| 41 |
p.Dead() |
| 42 |
} |