TestGomoduleComplex is an integration test that creates a non-trivial tree of go modules using the "replace" statement.
(t *testing.T)
| 1452 | // TestGomoduleComplex is an integration test that creates a non-trivial tree |
| 1453 | // of go modules using the "replace" statement. |
| 1454 | func TestGomoduleComplex(t *testing.T) { |
| 1455 | // This test cannot run in parallel. |
| 1456 | if internaltest.GetGoMinorVersion() < 11 { |
| 1457 | t.Skip("requires go module support") |
| 1458 | } |
| 1459 | old := os.Getenv("GOPATH") |
| 1460 | defer os.Setenv("GOPATH", old) |
| 1461 | root, err := os.MkdirTemp("", "stack") |
| 1462 | if err != nil { |
| 1463 | t.Fatal(err) |
| 1464 | } |
| 1465 | defer func() { |
| 1466 | if err = os.RemoveAll(root); err != nil { |
| 1467 | t.Error(err) |
| 1468 | } |
| 1469 | }() |
| 1470 | |
| 1471 | os.Setenv("GOPATH", filepath.Join(root, "go")) |
| 1472 | os.Setenv("GO111MODULE", "on") |
| 1473 | tree := map[string]string{ |
| 1474 | "pkg1/go.mod": "module example.com/pkg1\n" + |
| 1475 | "require (\n" + |
| 1476 | "\texample.com/pkg2 v0.0.1\n" + |
| 1477 | "\texample.com/pkg3 v0.0.1\n" + |
| 1478 | ")\n" + |
| 1479 | "replace example.com/pkg2 => ../pkg2\n" + |
| 1480 | // This is kind of a hack to force testing with a package inside GOPATH, |
| 1481 | // since this won't normally work by default. |
| 1482 | "replace example.com/pkg3 => ../go/src/example.com/pkg3\n", |
| 1483 | "pkg1/cmd/main.go": "package main\n" + |
| 1484 | "import \"example.com/pkg1/internal\"\n" + |
| 1485 | "func main() {\n" + |
| 1486 | "\tinternal.CallCallDie()\n" + |
| 1487 | "}\n", |
| 1488 | "pkg1/internal/int.go": "package internal\n" + |
| 1489 | "import \"example.com/pkg2\"\n" + |
| 1490 | "func CallCallDie() {\n" + |
| 1491 | "\tpkg2.CallDie()\n" + |
| 1492 | "}\n", |
| 1493 | |
| 1494 | "pkg2/go.mod": "module example.com/pkg2\n" + |
| 1495 | "require (\n" + |
| 1496 | "\texample.com/pkg3 v0.0.1\n" + |
| 1497 | ")\n" + |
| 1498 | // This is kind of a hack to force testing with a package inside GOPATH, |
| 1499 | // since this won't normally work by default. |
| 1500 | "replace example.com/pkg3 => ../go/src/example.com/pkg3\n", |
| 1501 | "pkg2/src2.go": "package pkg2\n" + |
| 1502 | "import \"example.com/pkg3\"\n" + |
| 1503 | "func CallDie() { pkg3.Die() }\n", |
| 1504 | |
| 1505 | "go/src/example.com/pkg3/go.mod": "module example.com/pkg3\n", |
| 1506 | "go/src/example.com/pkg3/src3.go": "package pkg3\n" + |
| 1507 | "func Die() { panic(42) }\n", |
| 1508 | } |
| 1509 | createTree(t, root, tree) |
| 1510 | |
| 1511 | exe := filepath.Join(root, "yo") |
nothing calls this directly
no test coverage detected
searching dependent graphs…