Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/spencertipping/lazytest

Tests for lazy developers (not that I know of any)
https://github.com/spencertipping/lazytest

Last synced: 7 days ago
JSON representation

Tests for lazy developers (not that I know of any)

Awesome Lists containing this project

README

        

# LazyTest: tests for developers too lazy to write them
[MIT license as usual](LICENSE)

I don't mind writing documentation that includes examples, but I don't really
like to write tests. LazyTest finds `bash` fenced code regions in Markdown
files and interprets them as examples that should produce the demonstrated
output. For example:

```bash
$ seq 4 # command with output below
1
2
3
4
```

This works by compiling Markdown files into bash scripts that contain the
assertions.

## Using LazyTest
```sh
$ ./lazytest *.md > tests.sh
$ bash tests.sh && echo 'woohoo, everything works'
```

You can write shell script snippets that aren't tests by using `sh` instead of
`bash`; for example:

```sh
# this code region won't turn into a test
$ false
woohoo, you ran /bin/false!
```

## How to write examples
LazyTest is pretty good at figuring out what's a command and what's
expected-output, but there are a few things that can throw it off. First,
things that work:

### Multiline strings
These work most of the time because lazytest reads until it has an even number
of them.

```bash
$ echo 'multiline single-
quoted strings' | perl -lne 'print "$_ FTW"'
multiline single- FTW
quoted strings FTW
```

```bash
$ echo "that's confusing"
that's confusing
```

```bash
$ echo "it's also possible
to have multiline double quoted strings"
it's also possible
to have multiline double quoted strings
```

### Line continuations
```bash
$ seq 1 \
5
1
2
3
4
5
```

### Heredocs
You can have a heredoc and lazytest will figure out where it ends:

```bash
$ cat <