Podlite 3.0 released

Podlite 3.0

Podlite 3.0 is tagged. The specification now places tests beside the rules they check, and the same test syntax can check any Podlite document. The full changelog is under =head2 v3.0 in the released specification.

What's new in 3.0

A specification that checks itself

Prose can leave a rule ambiguous: the same sentence can sometimes be read in two ways. In 3.0 the specification places tests beside the rules they check, and each test states what a parser must find or must not find. The specification settles disagreements in one sentence: "If a test of this specification differs from the rule it checks, the rule governs."

The tests are written in Podlite and check the structure of the parsed document independently of its output format. In the specification the tests live in files under t/, and each test is brought in with =include next to the rule it checks. On podlite.org it appears as a label beside that rule and opens in place.

Test blocks

3.0 adds the =test block. A test holds one or more =assert blocks. Each assertion contains a selector that must find a block or, with :absent, must find none. A test may also hold =fixture blocks that supply documents for its assertions, and =resource blocks when the test is about how a path resolves. These blocks can sit in any Podlite document. The invoice example uses one fixture and one assertion:

=begin test :id<every-invoice-has-a-number> :caption('every invoice carries a number')
=begin fixture
=for Invoice :number<2026-041>
Office chairs, 4 pcs.
=end fixture
=for assert :absent
Invoice[ :!?number ]
=end test

The same test syntax for any document

Requirements for any document, or for a set of files a selector names, are written the same way. By default an assertion states that something is present, so a requirement for every block is written as the absence of its opposite. That every invoice carries a :number reads as "no invoice lacks one", the assertion in the test above.

The command-line tool runs the tests of a file. With --against, an assertion that names no source of its own checks the given document instead. Here the test is saved as invoice-checks.podlite and holds no fixture:

=begin test :id<every-invoice-has-a-number> :caption('every invoice carries a number')
=for assert :absent
Invoice[ :!?number ]
=end test
invoice-checks.podlite

The document to check, invoices.podlite, holds two invoices, and the second has no number:

=for Invoice :number<2026-041> :status<issued>
Office chairs, 4 pcs.

=for Invoice :status<draft>
Desk lamp.
invoices.podlite
$ podlite test invoice-checks.podlite --against invoices.podlite
failed  every-invoice-has-a-number (invoice-checks.podlite:1) against invoices.podlite
  assertion 1 at invoice-checks.podlite:2: :absent Invoice[ :!?number ]
    does not hold, against the supplied document invoices.podlite, 1 match
    found Invoice at invoices.podlite:4
1 test: 0 passed, 1 failed, 0 skipped

The report points to the invoice without a number at invoices.podlite:4. The tool exits with status 1, so a build can detect the failed check. That makes the tests usable in automated document checks, for example in continuous integration, and as a guard on the files changed by an editing tool.

Selectors with predicates

The invoice assertion uses Invoice[ :!?number ] to find invoices without a number, an example of the square-bracket predicates introduced in 3.0. A predicate tests the configuration in effect for a block, so a selection can depend on an attribute alone.

Other changes

Some rules change how existing documents read: a =picture takes its source only from :src, where an image source written on its first line now belongs, and CSV and TSV use the first row as column names by default. The changelog summarizes the rest.

Links

Funding ↗ pays for the time that goes into Podlite.