summaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go39
1 files changed, 38 insertions, 1 deletions
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"}}<html><head><title>{{.Title}}</title></head><body>{{joinSections .Sections}}</body></html>{{end}}
{{define "weblog"}}<html><head><title>{{.Title}}</title></head><body>{{joinSections .Sections}}</body></html>{{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), "<title>One</title>") {
+ 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)}