package docs import ( "os" "path/filepath" "runtime" "strings" "testing" ) // TestDocs validates the repository's docs/ directory against the content // contract. This is a unit test rather than an endtoend case because the // contract is a property of the documentation source tree, not of anything // the sqlc CLI does: there is no command whose output could pin it down. func TestDocs(t *testing.T) { _, thisFile, _, ok := runtime.Caller(0) if !ok { t.Fatal("could not locate source file") } root := filepath.Join(filepath.Dir(thisFile), "..", "..", "docs") problems, err := Lint(root) if err != nil { t.Fatal(err) } for _, p := range problems { t.Errorf("%s", p) } } // TestLintViolations pins down what the linter rejects, using a synthetic // docs tree that violates each rule of the contract once. func TestLintViolations(t *testing.T) { root := t.TempDir() write := func(name, content string) { t.Helper() p := filepath.Join(root, filepath.FromSlash(name)) if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil { t.Fatal(err) } if err := os.WriteFile(p, []byte(content), 0o644); err != nil { t.Fatal(err) } } write("toc.yaml", ` index: index.md sections: - title: Guides pages: - sub/page.md - sub/page.md - ghost.md `) write("index.md", `# Index A [broken link](missing.md) and a [bad anchor](sub/page.md#nope) and a [bad self anchor](#nowhere) and an [absolute link](/sub/page.md) and an [escaping link](../outside.md).