| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
PbtCli.Render
Description
Human-readable rendering: suite tables, test trees, and live run output.
Synopsis
- encodeJsonPretty :: ToJSON a => a -> ByteString
- encodeJsonCompact :: ToJSON a => a -> ByteString
- renderSuiteNames :: Discovery -> Text
- renderSuitesTable :: Discovery -> Text
- renderSuitesTsv :: Discovery -> Text
- renderTestTree :: [TestInfo] -> Text
- renderTestList :: [TestInfo] -> Text
- renderEvent :: Event -> Maybe Text
- renderEventWith :: (Int -> Maybe Text) -> Event -> Maybe Text
- renderSuiteBanner :: Text -> Text
- testNameIndex :: [TestInfo] -> IntMap Text
- tagEventWithSuite :: Text -> Value -> Value
JSON
encodeJsonPretty :: ToJSON a => a -> ByteString Source #
Pretty JSON with discovery's keys in their documented order.
aeson orders an object's keys by its own key map, which is alphabetical — so
without this a suite would print discoverCommand before name. The order
below is the one list-test-suites.schema.json documents and the shell tool
emits, which is also the order that reads best: identity first, then
classification, then the commands. Keys not listed keep aeson's order and sort
after the listed ones.
encodeJsonCompact :: ToJSON a => a -> ByteString Source #
Single-line JSON, for piping into jq or another process.
Key order is aeson's here, not the documented one: a JSON object is unordered
by definition, every consumer parses it, and encodeJsonPretty is the variant
meant to be read.
Suites
renderSuiteNames :: Discovery -> Text Source #
One suite name per line — the default suites output.
Just the names, with no decoration, so the common uses compose:
pbt-cli suites | wc -l, or feeding the list straight back into
pbt-cli run. Compatibility is expressed by filtering
(--compatible-only) rather than by annotating, so the output stays a clean
list of arguments.
renderSuitesTable :: Discovery -> Text Source #
A table of every discovered suite, grouped by project file.
The COMPAT column is the answer to "which suites can I stream and discover
tests in", which is the question this command exists to answer, so it gets a
symbol rather than another word of prose.
renderSuitesTsv :: Discovery -> Text Source #
The legacy tab-separated format:
suite \t packageDir \t mainPath \t entryPoint \t hsSourceDirs.
Kept byte-compatible with list-test-suites.sh --tsv so existing editor
integrations and shell pipelines keep working: mainPath is relative to the
scanned root (not to the package) and the source dirs are ;-joined so the
column count is fixed even for a multi-dir stanza.
Tests
renderTestTree :: [TestInfo] -> Text Source #
The test tree as nested groups, with each test's id.
The id is what --test-id takes, so it is shown first and unpadded: the point
of running discovery is usually to pick ids to re-run.
renderTestList :: [TestInfo] -> Text Source #
One line per test: id<TAB>fullpathname. Convenient for shell loops.
Streaming
renderEvent :: Event -> Maybe Text Source #
renderEventWith with no name index: a test_done whose description is
empty renders without one.
renderEventWith :: (Int -> Maybe Text) -> Event -> Maybe Text Source #
A one-line human rendering of a streaming event, or Nothing for events
with nothing to say on a console.
test_started is dropped rather than printed: it is immediately followed by
the test_done line for the same test, and echoing both doubles the output
for no added information. test_trace and test_progress are likewise
suppressed — they are for tooling, and a trace payload is far too large for a
terminal line.
renderSuiteBanner :: Text -> Text Source #
A banner naming the suite whose events follow.
run --stream invokes cabal once per suite, so without this the events of six
suites would arrive as one undifferentiated list of PASS lines.
testNameIndex :: [TestInfo] -> IntMap Text Source #
Names for every test in a suite_started event, keyed by id.
Feed this to renderEventWith. Tasty providers differ in whether they set a
test_done description — the shimmed Convex.Tasty.HUnit ones do, plain
Test.Tasty.HUnit ones send "" — so without the tree a live run would print
a column of anonymous PASS lines.
tagEventWithSuite :: Text -> Value -> Value Source #
Add a suite field to an event, naming the suite that produced it.
run --json can cover many suites, and the event schema carries no suite
identity — a consumer would see several suite_started events with no way to
tell them apart. The streaming-events schema does not set
additionalProperties: false, so an added field is schema-valid, and a
consumer that ignores unknown fields is unaffected.
A non-object event (which the schema does not produce) is returned unchanged.