Skip to content

Commit

Permalink
Reproduce build failure for TestMain in black box test
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Feb 20, 2024
1 parent 4856288 commit ef83d56
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,16 @@ func Test_gobcoMain__TestMain(t *testing.T) {
_ = stderr
}

func Test_gobcoMain__TestMainTest(t *testing.T) {
s := NewSuite(t)
defer s.TearDownTest()

stdout, stderr := s.RunMain(1, "gobco", "-verbose", "testdata/testmaintest")

s.CheckContains(stdout, "[build failed]")
s.CheckContains(stderr, ": undefined: gobcoCounts")
}

func Test_gobcoMain__oddeven(t *testing.T) {
s := NewSuite(t)
defer s.TearDownTest()
Expand Down
5 changes: 5 additions & 0 deletions testdata/testmaintest/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package add

func Add(x, y int) int {
return x + y
}
21 changes: 21 additions & 0 deletions testdata/testmaintest/add_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package add_test

import (
add "github.com/rillig/gobco/testdata/testmaintest"
"os"
"testing"
)

// The TestMain function is defined in a black box test, thus the suffix
// '_test' in the package name.

func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func TestAdd(t *testing.T) {
have, want := add.Add(1, 2), 3
if have != want {
t.Errorf("want %d, have %d", want, have)
}
}

0 comments on commit ef83d56

Please sign in to comment.