diff options
Diffstat (limited to 'internal/cli/corpus_test.go')
| -rw-r--r-- | internal/cli/corpus_test.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/cli/corpus_test.go b/internal/cli/corpus_test.go new file mode 100644 index 0000000..0ed17bc --- /dev/null +++ b/internal/cli/corpus_test.go @@ -0,0 +1,41 @@ +package cli + +import ( + "bytes" + "strings" + "testing" + + "github.com/lukaszkasprzak/lectio/internal/bible" +) + +func TestRunCorpusCheckPathArg(t *testing.T) { + t.Cleanup(func() { bible.SetUserCorporaDir("") }) + + var buf bytes.Buffer + if code := runCorpusCheck("../bible/testdata/corpora/badbook.tsv", false, &buf, &buf); code != 1 { + t.Fatalf("badbook: exit %d, want 1 (out=%s)", code, buf.String()) + } + if !strings.Contains(buf.String(), "ERROR:") { + t.Errorf("expected an ERROR: line, got %s", buf.String()) + } + + buf.Reset() + if code := runCorpusCheck("../bible/testdata/corpora/good.tsv", false, &buf, &buf); code != 0 { + t.Fatalf("good: exit %d, want 0 (out=%s)", code, buf.String()) + } + if !strings.Contains(buf.String(), "ok:") { + t.Errorf("expected an ok: summary, got %s", buf.String()) + } +} + +func TestRunCorpusCheckJSON(t *testing.T) { + t.Cleanup(func() { bible.SetUserCorporaDir("") }) + + var buf bytes.Buffer + if code := runCorpusCheck("../bible/testdata/corpora/badbook.tsv", true, &buf, &buf); code != 1 { + t.Fatalf("badbook --json: exit %d, want 1 (out=%s)", code, buf.String()) + } + if !strings.Contains(buf.String(), `"Errors"`) { + t.Errorf("expected a JSON report, got %s", buf.String()) + } +} |
