Light wrapper script over kward/shlib and kward/shunit2. Provides some shell script unit testing granularity.
- Adds option for running only one specific test from one unit test file.
- Enables separation of shlib and a directory containing unit tests.
- Passes through options for specifying which shells to test with, and for narrowing which unit test files to run.
- Tested in bash, mksh, dash, zsh.
- kward/shlib
- kward/shunit2 (for your individual unit test files)
- Create a script (e.g.
myscript.sh
) that you want to test. - Copy the
shunit-test-handler.sh
script from this repo into your project. - Create a
unit_tests
directory in your project. - Add some shunit2 unit test files to the
unit_tests
directory. - Ensure you have both shlib and shunit2 somewhere in your project.
At this point, your project should look something like this:
└─┬ my_project/
├── myscript.sh
├─┬ tests/
│ ├── shunit-test-handler.sh
│ └─┬ unit_tests/
│ ├── test_a.sh
│ └── test_b.sh
└─┬ third_party/
├── shlib/
└── shunit2/
-
Run all unit test files, with all available shells.
$ ./shunit-test-handler ../third_party/shlib ./unit_tests
-
Only test with the bash shell.
$ ./shunit-test-handler -s /bin/bash ../third_party/shlib ./unit_tests
-
Only run a specified list of unit test files.
$ ./shunit-test-handler -t test_a.sh ../third_party/shlib ./unit_tests
-
Only run one specified test function within a unit test file.
$ ./shunit-test-handler -t test_a.sh -x someTestFunc ../third_party/shlib ./unit_tests
SYNOPSIS
test_driver.sh -h
test_driver.sh [-s "<path> [<path> ...]"] [-t "<file> [<file> ...]"]
[-x <function_name>] <path_to_shlib_dir>
<path_to_unit_tests_dir>
OPTIONS:
-h, --help
print this help message
-s "<path> [<path> ...]", --test-shells="<path> [<path> ...]"
use specified list of shells for tests (default is sys shell)
-t "<file> [<file> ...]", --unit-test-files="<file> [<file> ...]"
only run specified list of unit test files
-x "<function_name>", --unit-test-function="<function_name>"
only run single specified unit test function
- Pass through environment vars to test_runner.
- Allow running multiple test functions within a unit test file.
- Enable testing multiple unit-test directories, and recursing.
- Redo -x option unit_test_function hack: find better alternative to passing env var.
Distributed under the MIT License