// SPDX-License-Identifier: GPL-3.0-or-later package extract import ( "os" "path/filepath" "strings" "testing" ) // TestRealDocuments reads documents made by the programs people use - // LibreOffice 25.2 (docx, odt, doc, pdf, ods, xlsx, xls) and pandoc (pptx, // epub) - from invented text, not ones built by hand in a test (triage // 34s). The zip formats always run; a format that needs an external tool // runs when that tool is installed and is skipped otherwise. func TestRealDocuments(t *testing.T) { e := newWithPath(os.Getenv("PATH")) found := map[string]bool{} for _, tool := range e.Tools() { found[tool.Name] = tool.Path != "" } for _, c := range []struct { file string tools []string // any one of them will do; none means Go reads it want string }{ {"doc.docx", nil, "acme ltd"}, {"doc.odt", nil, "acme ltd"}, {"sheet.ods", nil, "acme ltd"}, {"sheet.xlsx", nil, "acme ltd"}, {"slides.pptx", nil, "acme ltd"}, {"book.epub", nil, "acme ltd"}, {"doc.pdf", []string{"pdftotext"}, "acme ltd"}, {"doc.doc", []string{"antiword", "catdoc"}, "acme ltd"}, {"sheet.xls", []string{"xls2csv"}, "acme ltd"}, } { t.Run(c.file, func(t *testing.T) { if len(c.tools) > 0 { ok := false for _, tool := range c.tools { ok = ok || found[tool] } if !ok { t.Skipf("none of %v installed", c.tools) } } got, err := text(t, e, filepath.Join("testdata", "real", c.file), 0) if err != nil { t.Fatal(err) } if !strings.Contains(got, c.want) { t.Errorf("text of %s lacks %q:\n%q", c.file, c.want, got) } }) } }