(t *testing.T)
| 590 | } |
| 591 | |
| 592 | func TestMainWatchCloneAndDiffModes(t *testing.T) { |
| 593 | t.Run("watch flag dispatches to watch mode", func(t *testing.T) { |
| 594 | fake := &fakeWatchProcess{fileCount: 3, events: []watch.Event{{Path: "main.go", Op: "WRITE"}}} |
| 595 | withMainRuntimeStubs( |
| 596 | t, |
| 597 | func(root string, verbose bool) (watchProcess, error) { return fake, nil }, |
| 598 | func(c chan<- os.Signal, sig ...os.Signal) { c <- os.Interrupt }, |
| 599 | nil, |
| 600 | nil, |
| 601 | nil, |
| 602 | nil, |
| 603 | nil, |
| 604 | ) |
| 605 | |
| 606 | stdout := runMainWithArgs(t, []string{"codemap", "--watch", t.TempDir()}) |
| 607 | if !strings.Contains(stdout, "codemap watch - Live code graph daemon") || !strings.Contains(stdout, "Events logged: 1") { |
| 608 | t.Fatalf("expected watch mode output, got:\n%s", stdout) |
| 609 | } |
| 610 | }) |
| 611 | |
| 612 | t.Run("github url path clones and renders json project", func(t *testing.T) { |
| 613 | withMainRuntimeStubs( |
| 614 | t, |
| 615 | nil, |
| 616 | nil, |
| 617 | func(name string, args ...string) *exec.Cmd { |
| 618 | dest := args[len(args)-1] |
| 619 | return exec.Command("sh", "-c", `mkdir -p "$1"; printf 'package main\n' > "$1/main.go"`, "sh", dest) |
| 620 | }, |
| 621 | nil, |
| 622 | nil, |
| 623 | nil, |
| 624 | func(*os.File) bool { return false }, |
| 625 | ) |
| 626 | |
| 627 | stdout := runMainWithArgs(t, []string{"codemap", "--json", "github.com/acme/codemap"}) |
| 628 | var project scanner.Project |
| 629 | if err := json.Unmarshal([]byte(stdout), &project); err != nil { |
| 630 | t.Fatalf("expected cloned project JSON output, got error %v with body:\n%s", err, stdout) |
| 631 | } |
| 632 | if project.Name != "acme/codemap" { |
| 633 | t.Fatalf("project name = %q, want acme/codemap", project.Name) |
| 634 | } |
| 635 | if project.RemoteURL != "github.com/acme/codemap" { |
| 636 | t.Fatalf("project remote URL = %q, want github.com/acme/codemap", project.RemoteURL) |
| 637 | } |
| 638 | if len(project.Files) != 1 || project.Files[0].Path != "main.go" { |
| 639 | t.Fatalf("expected cloned project files to include main.go, got %+v", project.Files) |
| 640 | } |
| 641 | }) |
| 642 | |
| 643 | t.Run("diff json includes changed file annotations", func(t *testing.T) { |
| 644 | if _, err := exec.LookPath("git"); err != nil { |
| 645 | t.Skip("git not available") |
| 646 | } |
| 647 | |
| 648 | root := makeMainGitRepo(t, "main") |
| 649 | if err := os.WriteFile(filepath.Join(root, "main.go"), []byte("package main\n\nfunc changed() {}\n"), 0o644); err != nil { |
nothing calls this directly
no test coverage detected