package main import ( "bytes" "os" "path/filepath" "regexp" "testing" "git.golem15.com/golem15/summercms/internal/docsite" "git.golem15.com/golem15/summercms/modules/bonfire" ) const repoRoot = "../.." // TestDocsTree fails with every problem line in the real docs tree. func TestDocsTree(t *testing.T) { problems, err := docsite.Check(docsite.Options{Root: repoRoot}) if err != nil { t.Fatal(err) } for _, p := range problems { t.Error(p.String()) } } // buildRealTree runs docs:build on the real tree into a temp dir and returns // the output dir and the command output. func buildRealTree(t *testing.T) (string, string) { t.Helper() out := filepath.Join(t.TempDir(), "site") var buf bytes.Buffer root, err := bonfire.NewRoot("summer", toolCommands(), &buf) if err != nil { t.Fatal(err) } root.SetArgs([]string{"docs:build", "--root", repoRoot, "--out", out}) if err := root.Execute(); err != nil { t.Fatalf("docs:build: %v\n%s", err, buf.String()) } return out, buf.String() } func TestDocsBuildRealTree(t *testing.T) { out, stdout := buildRealTree(t) if !regexp.MustCompile(`docs:build: wrote \d+ pages to `).MatchString(stdout) { t.Fatalf("output = %q, want a wrote-pages line", stdout) } for _, name := range []string{ "index.html", "index.md", "setup/installation.html", "setup/installation.md", "llms.txt", "llms-full.txt", "search-index.json", "assets/site.css", docsite.MarkerFile, } { if _, err := os.Stat(filepath.Join(out, name)); err != nil { t.Errorf("missing %s: %v", name, err) } } }