From 2cf936847f9e04e28d41bc088aa954cf37138359 Mon Sep 17 00:00:00 2001 From: t Date: Sat, 11 Jul 2026 18:14:04 -0600 Subject: track all generated outputs in .gitignore --- main_test.go | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'main_test.go') diff --git a/main_test.go b/main_test.go index 91f432b..cbb102c 100644 --- a/main_test.go +++ b/main_test.go @@ -21,6 +21,10 @@ func writeTestFile(t *testing.T, root, name, contents string) { } } +func build(root string) error { + return buildWithFallback(root, "https://example.com", "page", false) +} + func testLayouts() string { return `{{define "page"}}{{.Title}}{{joinSections .Sections}}{{end}} {{define "weblog"}}{{.Title}}{{joinSections .Sections}}{{end}} @@ -148,7 +152,7 @@ func TestMarkdownTemplateFallsThroughPathThenFallback(t *testing.T) { writeTestFile(t, root, "notes/recipes/bread.md", "# Bread\n") writeTestFile(t, root, "notes/recipes/cocktails/stirred.md", "# Stirred\n") writeTestFile(t, root, "notes/recipes/cocktails/old_fashioned.md", "# Old Fashioned\n") - if err := buildWithFallback(root, "default"); err != nil { + if err := buildWithFallback(root, "https://example.com", "default", false); err != nil { t.Fatal(err) } for name, want := range map[string]string{ @@ -269,6 +273,39 @@ func TestManifestRejectsNonOutputPaths(t *testing.T) { } } +func TestGitignoreTracksOnlyCurrentGeneratedOutputs(t *testing.T) { + root := t.TempDir() + writeTestFile(t, root, ".gitignore", "*.log\n/pantograph/cache.html\n") + writeTestFile(t, root, "layouts.tmpl", testLayouts()) + writeTestFile(t, root, "one.md", "# One\n") + writeTestFile(t, root, "nested/two.md", "# Two\n") + if err := buildWithFallback(root, "https://example.com", "page", true); err != nil { + t.Fatal(err) + } + want := "*.log\n/pantograph/cache.html\n" + gitignoreStart + "\n/nested/two.html\n/one.html\n" + gitignoreEnd + "\n" + if raw, _ := os.ReadFile(filepath.Join(root, ".gitignore")); string(raw) != want { + t.Fatalf(".gitignore = %q, want %q", raw, want) + } + if err := os.Remove(filepath.Join(root, "nested/two.md")); err != nil { + t.Fatal(err) + } + if err := buildWithFallback(root, "https://example.com", "page", true); err != nil { + t.Fatal(err) + } + want = "*.log\n/pantograph/cache.html\n" + gitignoreStart + "\n/one.html\n" + gitignoreEnd + "\n" + if raw, _ := os.ReadFile(filepath.Join(root, ".gitignore")); string(raw) != want { + t.Fatalf("updated .gitignore = %q, want %q", raw, want) + } + writeTestFile(t, root, ".gitignore", gitignoreStart+"\n") + writeTestFile(t, root, "one.md", "# Changed\n") + if err := buildWithFallback(root, "https://example.com", "page", true); err == nil { + t.Fatal("build accepted an unterminated managed block") + } + if raw, _ := os.ReadFile(filepath.Join(root, "one.html")); !strings.Contains(string(raw), "One") { + t.Fatalf("failed .gitignore update changed output: %s", raw) + } +} + func TestSortingFilteringSlicing(t *testing.T) { a := &Page{Title: "A", Meta: map[string]any{"post_date": "2024-01-01", "kind": "x"}, ModTime: time.Unix(1, 0)} b := &Page{Title: "B", Meta: map[string]any{"post_date": "2025-01-01", "kind": "y"}, ModTime: time.Unix(2, 0)} -- cgit v1.3