#testing

bin+lib lit

Integrated testing tool, inspired by LLVM’s ‘lit’ testing script

20 releases (4 stable)

1.0.3 Jan 29, 2021
1.0.2 May 17, 2020
0.4.0 Apr 23, 2020
0.3.4 Jun 1, 2019
0.1.0 Dec 30, 2016

#50 in Testing

Download history 37/week @ 2021-06-29 32/week @ 2021-07-06 28/week @ 2021-07-13 119/week @ 2021-07-20 62/week @ 2021-07-27 73/week @ 2021-08-03 55/week @ 2021-08-10 33/week @ 2021-08-17 59/week @ 2021-08-24 12/week @ 2021-08-31 12/week @ 2021-09-07 22/week @ 2021-09-14 28/week @ 2021-09-21 97/week @ 2021-09-28 187/week @ 2021-10-05 110/week @ 2021-10-12

644 downloads per month
Used in 3 crates

MIT license

110KB
2.5K SLoC

lit

Crates.io Build Status license

An integrated testing tool, similar to LLVM's integrated testing tool (llvm-lit) but in library form.

Rust API Documentation

Usage

Point lit at a directory containing test files and it will execute the commands and run the checks contained within the tests.

Any plain-text based file format that supports comments can be used as a test file, provided the comment character has been added to lit's source code.

All testing is done based on text comparisons with the output of various command line tools executed on each test file. The CHECK directives inside each test file validate that the command line tool contains the expected text.

Testing a bash script

Here is an example test file, it is a bash script. Assertions are added that ensure the bash script outputs the correct text to stdout/stderr.

# RUN: sh -ea @file

# CHECK: hello world
echo hello world

# CHECK: number 1
# CHECK: number 2
# CHECK: number 3
# CHECK: number 4
for i in $(seq 1 4); do echo number $i; done

Testing a C/C++ program

Here is an example C/C++ test file. Assertions are added that ensure the C compiler name mangles the main method as a particular way.

// RUN: gcc @file -S
//
// Note: '-S' compiles this C program to plain-text assembly.

// This next line verifies that there is an assembly label
// with a name mangled underscore prefix.
// CHECK: _main:
int main() {
  return 0;
}

The RUN directive

This directive runs an executable, almost always operating on the test file as the source file.

RUN: <command-line>

Each RUN directive runs the same test file in different conditions.

The CHECK directive

This directive is used to assert that the output of the RUN command contains a specific string.

CHECK: <substring to look for>

If the substring is not found, then the test immediately fails.

Variables

Variables can be used in directives by @<variable name>. The variable is substituted in-place with the value of the variable at the time of the test.

Default variables available to tests

These variables can be used by tests in directives.

Name (* = wildcard) Description Substituted value
@file The path the the test file being executed.
@*tempfile* Any variable containing the text tempfile A temporary file path. Subsequent uses of the same tempfile variable will give the same path. It is possible to use multiple tempfiles in one test by giving them separate names, like @first_tempfile and @second_tempfile

Dependencies

~7MB
~146K SLoC