Skip to content

peterwwillis/test.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ABOUT

  If you want to write a bunch of little shell script functions as tests,
  run them all and see which ones passed or failed, this makes it easy.

COMPILING

  Install 'm4' and 'shellcheck'.

  Run `make clean all`.

INSTALLING

  Run `make install`, or copy 'src/test.sh' to wherever you would like to
  install it.

USAGE

  1. Copy test.sh to your project and make some tests.
  2. Write some shell script functions (these are your tests).
  3. Add the names of the functions to a global variable called 'ext_tests'.
  4. Put the variable and functions in a file ending with ".t" and pass it to 
     `test.sh` (e.g. `test.sh some-file.t`).

  The functions listed in 'ext_tests' get called, and pass/fail is determined
  by their return status. The results are reported at the end.

FEATURES

  The variable 'testbasename' is available to the test functions as the file name
  of the test, minus the extension ".t".

  The variable 'testtmpdir' is available to the test functions. It is a new temporary
  directory created right before each test file is loaded, and removed after the
  file's tests run.

  If a function or command '_testsh_pre_test' or '_testsh_post_test' exist, they
  are run before and after each test.

  Set environment variable TESTSH_LOGGING=1 to redirect each test's output to
  its own log file. Successful test logs are automatically deleted unless
  you set 'TESTSH_LOGGING_KEEP_SUCCESS=1'.

  Set environment variable TESTSH_ENVRC to a shell script to be loaded by test.sh
  at start time. All variables in said script are exported.
  If TESTSH_ENVRC doesn't exist, the file .testshrc is loaded from TESTSH_SRCDIR
  (which defaults to $PWD or `pwd`).

  You can change the default extension of tests ('.t') by setting environment
  variable TESTSH_TESTEXT.
  
  Set environment variable DEBUG=1 before running test.sh to enable shell tracing.

NOTES

  There is a collection of Makefiles in this project. You don't need to use them,
  but they show a handy way to call tests in subdirectories of your project.
  Or you could go minimalist:
      find . -type f -name *.t -exec ./test.sh {} \;

About

Minimalist shell script testing framework

Resources

Stars

Watchers

Forks

Packages

No packages published