Skip to content

Light wrapper script over shlib and shunit2, adding unit test granularity

License

Notifications You must be signed in to change notification settings

digimokan/shunit-test-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

shunit-test-handler

Light wrapper script over kward/shlib and kward/shunit2. Provides some shell script unit testing granularity.

Table Of Contents

Features

  • 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.

Dependencies

Setup

  1. Create a script (e.g. myscript.sh) that you want to test.
  2. Copy the shunit-test-handler.sh script from this repo into your project.
  3. Create a unit_tests directory in your project.
  4. Add some shunit2 unit test files to the unit_tests directory.
  5. 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/

Examples

  • 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

Usage

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

Todo

  • 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.

Meta

Developers

License

Distributed under the MIT License

About

Light wrapper script over shlib and shunit2, adding unit test granularity

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages