Test Anything Protocol in Shell scripts

十年热恋 提交于 2019-11-30 07:33:38
Chas. Owens

See the list of TAP Producers for a list of libraries. On that list you will find Tap-functions for shell code.

I usually write my own small test framework for my shell scripts. Some things to keep in mind when doing this:

  • When working with files, make all paths relative to some variable which you can modify in your tests.
  • diff(1) is great to verify test results (and to display a useful error message to the user)
  • Use local variables extensively
  • Everything must be in a function

That said, my "test framework" is mostly a set of shell functions (named test*) and a runTests function which calls them one by one. Nothing fancy, really. Tests create a work directory for the test, copy all necessary files into it, run a function, verify the results against a know-good set of files.

weynhamz
  • Bats is simple Bash only test framwork, tests could be written in a very clear syntax.
  • shUnit is the oldest shell test framework, little documentation.
  • shUnit2 is a most recently project inspired by shUnit, but completely different. Tests could be written in a more xUnit fashion. Most importantly, it is POSIX compatible.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!