|
8 | 8 | "bytes"
|
9 | 9 | "debug/elf"
|
10 | 10 | "debug/macho"
|
| 11 | + "flag" |
11 | 12 | "fmt"
|
12 | 13 | "go/format"
|
13 | 14 | "internal/race"
|
@@ -112,6 +113,12 @@ func TestMain(m *testing.M) {
|
112 | 113 | }
|
113 | 114 | os.Unsetenv("GOROOT_FINAL")
|
114 | 115 |
|
| 116 | + flag.Parse() |
| 117 | + if *proxyAddr != "" { |
| 118 | + StartProxy() |
| 119 | + select {} |
| 120 | + } |
| 121 | + |
115 | 122 | if canRun {
|
116 | 123 | args := []string{"build", "-tags", "testgo", "-o", "testgo" + exeSuffix, "../../.."}
|
117 | 124 | if race.Enabled {
|
@@ -417,7 +424,8 @@ func (tg *testgoData) doRun(args []string) error {
|
417 | 424 | func (tg *testgoData) run(args ...string) {
|
418 | 425 | tg.t.Helper()
|
419 | 426 | if status := tg.doRun(args); status != nil {
|
420 |
| - tg.t.Logf("go %v failed unexpectedly: %v", args, status) |
| 427 | + wd, _ := os.Getwd() |
| 428 | + tg.t.Logf("go %v failed unexpectedly in %s: %v", args, wd, status) |
421 | 429 | tg.t.FailNow()
|
422 | 430 | }
|
423 | 431 | }
|
@@ -760,16 +768,28 @@ func (tg *testgoData) wantNotStale(pkg, reason, msg string) {
|
760 | 768 | }
|
761 | 769 | }
|
762 | 770 |
|
| 771 | +// If -testwork is specified, the test prints the name of the temp directory |
| 772 | +// and does not remove it when done, so that a programmer can |
| 773 | +// poke at the test file tree afterward. |
| 774 | +var testWork = flag.Bool("testwork", false, "") |
| 775 | + |
763 | 776 | // cleanup cleans up a test that runs testgo.
|
764 | 777 | func (tg *testgoData) cleanup() {
|
765 | 778 | tg.t.Helper()
|
766 | 779 | if tg.wd != "" {
|
| 780 | + wd, _ := os.Getwd() |
| 781 | + tg.t.Logf("ended in %s", wd) |
| 782 | + |
767 | 783 | if err := os.Chdir(tg.wd); err != nil {
|
768 | 784 | // We are unlikely to be able to continue.
|
769 | 785 | fmt.Fprintln(os.Stderr, "could not restore working directory, crashing:", err)
|
770 | 786 | os.Exit(2)
|
771 | 787 | }
|
772 | 788 | }
|
| 789 | + if *testWork { |
| 790 | + tg.t.Logf("TESTWORK=%s\n", tg.path(".")) |
| 791 | + return |
| 792 | + } |
773 | 793 | for _, path := range tg.temps {
|
774 | 794 | tg.check(removeAll(path))
|
775 | 795 | }
|
|
0 commit comments