Skip to content

assert ​

Asserts that every record in the stream must pass the given expression.

Synopsis ​

bash
recs assert [options] <expression> [files...]

Description ​

Asserts that every record in the stream must pass the given expression. The expression is evaluated on each record with r set to the current Record object and line set to the current line number (starting at 1). If the expression does not evaluate to true, processing is immediately aborted and an error message is printed.

Options ​

FlagDescription
--diagnostic / -d <text>Include this diagnostic string in any failed assertion errors.
--verbose / -vVerbose output for failed assertions; dumps the current record.
--expr / -e <code>Inline code snippet (alternative to positional argument).
--snippet-file / -E <path>Read snippet code from a file instead of the command line.
--lang / -l <lang>Snippet language: js (default), python/py, perl/pl.

Examples ​

Require each record to have a date field ​

bash
recs assert 'r.date'

Assert all values are positive with a diagnostic ​

bash
recs assert -d 'values must be positive' 'r.value > 0'

See Also ​

Released under the MIT License.