Skip to content

Instantly share code, notes, and snippets.

Created December 17, 2014 08:29
Show Gist options
  • Save anonymous/47611a2f30761f74a36e to your computer and use it in GitHub Desktop.
Save anonymous/47611a2f30761f74a36e to your computer and use it in GitHub Desktop.

Markdown based testing of files

This is a markdown based language for specification of testcases for files in a filesystem. Ideally a set of files may be described and at the same time formal specifications about the files can be specified using test cases written in, e.g., shell scripts embedded as code-blocks.

Overview

This section actually specifies some tests.

ensure that ./README.md

  • exists
  • has more that 100 lines
  • is gzipped

The ensure statement specifies one or more test-cases for a file-pattern given as argument. The file pattern is here ./README.md (this file), but it may be any legal glob pattern and may hence specify test-cases for a number of files.

The actual testcases a given as a bullet-list. Github flavoured markdown adds support for "checkboxes" in bulletted lists (as shown above).

File exists

This section specifies and implements a test-case. It is polymorphic in the sense that it may apply to any given file: The uppercase File in the section heading is a variable that may be substituted for an actual file. Variables are specified by words starting with upper-case letters (like in Prolog). The first variable in a section title is substituted for a file.

For the given File, the test-case specified using the code-block below is executed. If the return code is zero (success) then the test-case succeeds and otherwise it fails.

[[ -f File ]]
plink --bfile ikawhikq --out kqwehkquwerh

In the code-block above File is a replaced with the given value for the File variable.

File has more than X lines

Other variables than the files name may be included in test-cases. In this section the variable X is also given. Note that variables are given as by words with a first uppercase letter.

wc README.md | awk '$1 <= X { exit 1}'

File is gzipped

This predicate

X grandparent Y iff - X parent Y - Y parent Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment