(t *testing.T)
| 1649 | } |
| 1650 | |
| 1651 | func TestGoRun(t *testing.T) { |
| 1652 | t.Parallel() |
| 1653 | root, err := os.MkdirTemp("", "stack") |
| 1654 | if err != nil { |
| 1655 | t.Fatal(err) |
| 1656 | } |
| 1657 | defer func() { |
| 1658 | if err = os.RemoveAll(root); err != nil { |
| 1659 | t.Error(err) |
| 1660 | } |
| 1661 | }() |
| 1662 | |
| 1663 | p := filepath.Join(root, "main.go") |
| 1664 | content := "package main\nfunc main() { panic(42) }\n" |
| 1665 | if err = os.WriteFile(p, []byte(content), 0600); err != nil { |
| 1666 | t.Fatal(err) |
| 1667 | } |
| 1668 | c := exec.Command("go", "run", p) |
| 1669 | out, err := c.CombinedOutput() |
| 1670 | if err == nil { |
| 1671 | t.Fatal("expected failure") |
| 1672 | } |
| 1673 | prefix := bytes.Buffer{} |
| 1674 | s, suffix, err := ScanSnapshot(bytes.NewReader(out), &prefix, defaultOpts()) |
| 1675 | compareErr(t, nil, err) |
| 1676 | compareString(t, "panic: 42\n\n", prefix.String()) |
| 1677 | compareString(t, "exit status 2\n", string(suffix)) |
| 1678 | if s == nil { |
| 1679 | t.Fatal("expected snapshot") |
| 1680 | } |
| 1681 | if runtime.GOOS == "windows" { |
| 1682 | // On Windows, we must make the path to be POSIX style. |
| 1683 | p = strings.Replace(p, pathSeparator, "/", -1) |
| 1684 | } |
| 1685 | |
| 1686 | want := []*Goroutine{ |
| 1687 | { |
| 1688 | Signature: Signature{ |
| 1689 | State: "running", |
| 1690 | Stack: Stack{ |
| 1691 | Calls: []Call{ |
| 1692 | { |
| 1693 | Func: Func{ |
| 1694 | Complete: "main.main", |
| 1695 | ImportPath: "main", |
| 1696 | DirName: "main", |
| 1697 | Name: "main", |
| 1698 | IsExported: true, |
| 1699 | IsPkgMain: true, |
| 1700 | }, |
| 1701 | RemoteSrcPath: p, |
| 1702 | Line: 2, |
| 1703 | SrcName: "main.go", |
| 1704 | DirSrc: path.Base(path.Dir(p)) + "/main.go", |
| 1705 | ImportPath: "main", |
| 1706 | Location: LocationUnknown, |
| 1707 | }, |
| 1708 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…