unit test your command line interfaces and use your tests as usage documentation
(install latest successful build from drone.io)
- add
cli-unitw.sh
to your project - add
.fli-unit
to your.gitignore
file - run your test files:
./cli-unitw.sh *_test.md
### test:
signals the start of a new test. Also sets the test description#### when:
starts the block where you can define your script usage#### then:
starts the block where you define the expected output
./cli-unit ./ex_test.md
Pass (4/4 tests successful)
./cli-unit -v ./ex_test.md
--- OK: echo should work
--- OK: echo -e should preserve special chars
--- OK: (strict) strict flag enables testing trailing white space
--- OK: pipes should work too
Pass (4/4 tests successful)
./cli-unit failures_ex.md || true
--- FAIL: this isn't right
"Fool" != "Foo"
--- FAIL: failed when clauses should cause an error
exit status 2: ls: cannot access not_a_file: No such file or directory
Fail (0/2 tests successful)
you can have multiple blocks of tests in your markdown files (we didn't have to jump directly from "Examples" to "Formatting Examples")
You can put whatever you want here
or here
echo -e "foo"
- and not
- just text
or here
foo
or here...
when not using (strict)
, empty lines count as part of your when
and then
blocks
and trailing whitespace characters aren't compared
echo -e "foo\n\n\nbar\n\n"
foo
bar
when using (strict)
, empty lines terminate your when
and then
blocksand trailing
tabbed lines are compared
echo -e "foo\nbar\n"
strict mode is hard to set up right if you're using some editors like sublime text which will do a bunch of auto trimming.
foo
bar
this is not part of the test