runt/lib.rs
1//! Runt is a blazing fast, concurrent, and parallel snapshot testing framework.
2//!
3//! Snapshot testing involves running a command and testing its output against
4//! an already known "golden" output file.
5//! A runt test suite is defined using a `runt.toml` file.
6//!
7//! ## Installation
8//!
9//! To install the `runt` binary, simply run:
10//! ```
11//! cargo install runt
12//! ```
13//!
14//! ## Testing Model
15//! Runt's organizes tests using test suites.
16//! At the minimum, a test suite needs to be specify the input file paths as
17//! well as a command that is run for each input file.
18//! For example, the following defines a test suite named "Cat tests" that
19//! runs the command `cat {}` on every file `.txt` file in the directory
20//! `cat-tests/`.
21//! The `{}` is replaced by the path of the input file.
22//! ```
23//! [[tests]]
24//! # Name for this test suite.
25//! name = "Cat tests"
26//! # Test paths can be globs or exact.
27//! paths = [ "cat-test/*.txt" ]
28//! # Command to run on each test file. {} is replaced with input name.
29//! cmd = "cat {}"
30//! # (Optional) Directory to store the generated .expect files.
31//! expect_dir = "cat-out/"
32//! # (Optional) Timeout for tests in seconds. Defaults to 1200 seconds.
33//! timeout = 120
34//! ```
35//!
36//! ## Running a Test Suite
37//! Runt's command line interface is used to run and interact with a Runt
38//! test suite.
39//!
40//! For example, we can run [Runt's own test suite][runt-suite].
41//! From the directory containing the `runt.toml` file, run `runt`.
42//! Runt will generate a summary by running all the test suites. It will also
43//! print out the paths of the missing and the failing test suites:
44//! ```text
45//! ? Cat tests:cat-test/a.txt
46//! ✗ Cat tests:cat-test/b.txt
47//! ✗ Timeout test:timeout-test/input.txt (timeout)
48//! ? Ls test:ls-test/input.txt
49//! 1 passing / 2 failing / 2 missing
50//! ```
51//!
52//! According to Runt, we have 2 failing and 2 missing tests.
53//!
54//! ## Filters
55//!
56//! A complete runt configuration might have hundreds of tests. Runt provides
57//! two kinds of filter operations to select a subset of the test configuration.
58//! - Pre-filters: The `--include` and `--exclude` flags can be used to select
59//! tests names that match (or don't match) a particular regex. The regexes
60//! are matched against the string `<suite-name>:<path>`.
61//! - Post-filters: The `--only` flag can be used to print out the names of
62//! tests with a specific exit condition (failing or missing). This is
63//! particularly useful in conjuction with the `--diff` and `--save` flags.
64//!
65//!
66//! For example, to view only the tests that failed, we can invoke:
67//! ```bash
68//! runt -o fail
69//! ```
70//! To which, `runt` will respond with:
71//! ```text
72//! ✗ Cat tests:cat-test/b.txt
73//! ✗ Timeout test:timeout-test/input.txt (timeout)
74//! 1 passing / 2 failing / 2 missing
75//! ```
76//! Note that Runt is still running all the tests. It simply suppressing the
77//! output from the missing tests.
78//!
79//! If we only want to run the tests from the test suite `Cat tests`, we can
80//! use the `-i` flag:
81//! ```bash
82//! runt -i 'Cat tests'
83//! ```
84//! To which, `runt` reports:
85//! ```test
86//! ✗ Cat tests:cat-test/b.txt
87//! ? Cat tests:cat-test/a.txt
88//! 0 passing / 1 failing / 1 missing
89//! ```
90//! Note that runt reports 0 passing tests because it is not running the test
91//! suite with the previously passing tests.
92//!
93//! ## Viewing diffs and Saving .expect Files
94//!
95//! Under the hood, `runt` uses `.expect` files to test the outputs of running
96//! a command.
97//! The `expect_dir` option specifies the directory which contains the `.expect`
98//! file (defaults to the directory containing the test path).
99//! For example, we can view the `.expect` files for the "Cat tests" suite
100//! under `cat-out`.
101//!
102//! Runt is also capable of showing diffs for failing and missing tests using
103//! the `-d` flag.
104//! For example, we can run:
105//! ```bash
106//! runt -i 'Cat tests' -d
107//! ```
108//! Runt generates diffs for both the missing test and the failing tests.
109//!
110//! In order to bless the diff as correct, we can use the `-s` flag to save
111//! the output.
112//! ```bash
113//! runt -i 'Cat tests' -d -s
114//! ```
115//!
116//! Both the `-d` and `-s` flags work with the filtering flags.
117//!
118//! ## Timeouts
119//!
120//! Test suites can require a default timeout for each individual test.
121//! When left unspecified, Runt will use 20 minutes as the default.
122//!
123//! [runt-suite]: https://github.com/rachitnigam/runt/tree/master/cli-test
124pub mod cli;
125pub mod errors;
126pub mod executor;
127pub mod picker;
128pub mod printer;