unit test your command line interfaces and use your tests as usage documentation
(install latest successful build from drone.io)
cli-unitw.shto your project
- run your test files:
### 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
test: Vanilla test run
Pass (4/4 tests successful)
test: Optionally get verbose output
./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)
test: failed tests should show what the problem is (also handle expected error)
./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")
test: check some output
You can put whatever you want here
echo -e "foo"
- and not
- just text
test: check some more output
when not using
(strict), empty lines count as part of your
and trailing whitespace characters aren't compared
echo -e "foo\n\n\nbar\n\n"
test: (strict) check some strict output
(strict), empty lines terminate your
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