├── .gitignore ├── doc ├── shunit2.txt ├── contributors.txt ├── TODO.txt ├── design_doc.txt ├── RELEASE_NOTES-2.1.3.txt ├── RELEASE_NOTES-2.1.1.txt ├── RELEASE_NOTES-2.1.2.txt ├── RELEASE_NOTES-2.1.4.txt ├── RELEASE_NOTES-2.1.0.txt ├── RELEASE_NOTES-2.1.6.txt ├── RELEASE_NOTES-2.1.5.txt ├── coding_standards.txt ├── rst2html.css ├── README.txt ├── CHANGES-2.1.txt ├── README.html └── LGPL-2.1 ├── examples ├── equality_test.sh ├── math.inc ├── party_test.sh ├── lineno_test.sh ├── math_test.sh └── mkdir_test.sh ├── sync-with-svn-repository ├── wiki ├── FeatureMatrix.wiki ├── .svn │ ├── text-base │ │ ├── FeatureMatrix.wiki.svn-base │ │ ├── HOWTO_TestPossibilityMatrix.wiki.svn-base │ │ ├── GeneralFaq.wiki.svn-base │ │ ├── ProjectInfo.wiki.svn-base │ │ └── HOWTO_TestAbsolutePathFn.wiki.svn-base │ ├── all-wcprops │ └── entries ├── HOWTO_TestPossibilityMatrix.wiki ├── GeneralFaq.wiki ├── ProjectInfo.wiki └── HOWTO_TestAbsolutePathFn.wiki ├── bin ├── which └── gen_test_results.sh ├── src ├── shunit2_test_standalone.sh ├── shunit2_test_failures.sh ├── shunit2_test.sh ├── shunit2_test_helpers ├── shunit2_test_misc.sh ├── shunit2_test_asserts.sh └── shunit2_test_macros.sh ├── lib ├── shlib └── versions └── README.wiki /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *~ 3 | -------------------------------------------------------------------------------- /doc/shunit2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zandev/shunit2/HEAD/doc/shunit2.txt -------------------------------------------------------------------------------- /examples/equality_test.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # file: examples/equality_test.sh 3 | 4 | testEquality() 5 | { 6 | assertEquals 1 1 7 | } 8 | 9 | # load shunit2 10 | . ../src/shunit2 11 | -------------------------------------------------------------------------------- /examples/math.inc: -------------------------------------------------------------------------------- 1 | # available as examples/math.inc 2 | 3 | add_generic() 4 | { 5 | num_a=$1 6 | num_b=$2 7 | 8 | expr $1 + $2 9 | } 10 | 11 | add_bash() 12 | { 13 | num_a=$1 14 | num_b=$2 15 | 16 | echo $(($1 + $2)) 17 | } 18 | -------------------------------------------------------------------------------- /sync-with-svn-repository: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e; set -u 3 | 4 | # https://github.com/nirvdrum/svn2git 5 | svn2git --rebase 6 | cd wiki 7 | svn up . 8 | git add . 9 | cd .. 10 | cp wiki/ProjectInfo.wiki README.wiki 11 | git add README.wiki 12 | git commit -m "Synced wiki" 13 | -------------------------------------------------------------------------------- /examples/party_test.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # file: examples/party_test.sh 3 | 4 | testEquality() 5 | { 6 | assertEquals 1 1 7 | } 8 | 9 | testPartyLikeItIs1999() 10 | { 11 | year=`date '+%Y'` 12 | assertEquals "It's not 1999 :-(" \ 13 | '1999' "${year}" 14 | } 15 | 16 | # load shunit2 17 | . ../src/shunit2 18 | -------------------------------------------------------------------------------- /doc/contributors.txt: -------------------------------------------------------------------------------- 1 | The original author of shunit2 is Kate Ward. The following people have 2 | contributed in some way or another to shunit2. 3 | 4 | Bryan Larsen 5 | Kevin Van Horn 6 | Maciej Bliziński 7 | Mario Sparada 8 | Mathias Goldau 9 | Richard Jensen 10 | Rob Holland 11 | Rocky Bernstein 12 | wood4321 (of code.google.com) 13 | 14 | $Revision$ 15 | -------------------------------------------------------------------------------- /examples/lineno_test.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # file: examples/lineno_test.sh 3 | 4 | testLineNo() 5 | { 6 | # this assert will have line numbers included (e.g. "ASSERT:[123] ...") if 7 | # they are supported. 8 | echo "_ASSERT_EQUALS_ macro value: ${_ASSERT_EQUALS_}" 9 | ${_ASSERT_EQUALS_} 'not equal' 1 2 10 | 11 | # this assert will not have line numbers included (e.g. "ASSERT: ...") 12 | assertEquals 'not equal' 1 2 13 | } 14 | 15 | # load shunit2 16 | . ../src/shunit2 17 | -------------------------------------------------------------------------------- /doc/TODO.txt: -------------------------------------------------------------------------------- 1 | Make it possible to execute a single test by passing the name of the test on 2 | the command line 3 | 4 | Add support for '--randomize-order' so that the test order is randomized to 5 | check for dependencies (which shouldn't be there) between tests. 6 | 7 | --debug option to display point in source code (line number and such) where the 8 | problem showed up. 9 | 10 | assertTrue() just gives 'ASSERT:', nothing else :-(. others too? 11 | upd: assertNull() will give message passed, but nothing else useful :-( 12 | 13 | $Revision$ 14 | -------------------------------------------------------------------------------- /examples/math_test.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # available as examples/math_test.sh 3 | 4 | testAdding() 5 | { 6 | result=`add_generic 1 2` 7 | assertEquals \ 8 | "the result of '${result}' was wrong" \ 9 | 3 "${result}" 10 | 11 | # disable non-generic tests 12 | [ -z "${BASH_VERSION:-}" ] && startSkipping 13 | 14 | result=`add_bash 1 2` 15 | assertEquals \ 16 | "the result of '${result}' was wrong" \ 17 | 3 "${result}" 18 | } 19 | 20 | oneTimeSetUp() 21 | { 22 | # load include to test 23 | . ./math.inc 24 | } 25 | 26 | # load and run shUnit2 27 | . ../src/shunit2 28 | -------------------------------------------------------------------------------- /wiki/FeatureMatrix.wiki: -------------------------------------------------------------------------------- 1 | #summary This page summarizes which shells and OSes support which features. 2 | #labels Featured 3 | 4 | = Introduction = 5 | 6 | In the world of Unix, and especially in the world of Unix shells, variety abounds. Some shells support some things, others support something else. shUnit2 tries both to work with the common denominator of shell and OS features, and provide as many useful features as possible. Unfortunately, not all features are supported in all combinations, and it is important to know what works where. 7 | 8 | = Features Matrix = 9 | 10 | == 2.1.6 == 11 | || *Feature* || *OS* || *Shell* || *Supported* || 12 | || Line numbers on asserts || Ubuntu 10.04 || bash 4.1 || *yes* || 13 | || || || dash 0.5.5.1 || no || -------------------------------------------------------------------------------- /wiki/.svn/text-base/FeatureMatrix.wiki.svn-base: -------------------------------------------------------------------------------- 1 | #summary This page summarizes which shells and OSes support which features. 2 | #labels Featured 3 | 4 | = Introduction = 5 | 6 | In the world of Unix, and especially in the world of Unix shells, variety abounds. Some shells support some things, others support something else. shUnit2 tries both to work with the common denominator of shell and OS features, and provide as many useful features as possible. Unfortunately, not all features are supported in all combinations, and it is important to know what works where. 7 | 8 | = Features Matrix = 9 | 10 | == 2.1.6 == 11 | || *Feature* || *OS* || *Shell* || *Supported* || 12 | || Line numbers on asserts || Ubuntu 10.04 || bash 4.1 || *yes* || 13 | || || || dash 0.5.5.1 || no || -------------------------------------------------------------------------------- /wiki/.svn/all-wcprops: -------------------------------------------------------------------------------- 1 | K 25 2 | svn:wc:ra_dav:version-url 3 | V 22 4 | /svn/!svn/ver/337/wiki 5 | END 6 | HOWTO_TestPossibilityMatrix.wiki 7 | K 25 8 | svn:wc:ra_dav:version-url 9 | V 55 10 | /svn/!svn/ver/280/wiki/HOWTO_TestPossibilityMatrix.wiki 11 | END 12 | HOWTO_TestAbsolutePathFn.wiki 13 | K 25 14 | svn:wc:ra_dav:version-url 15 | V 52 16 | /svn/!svn/ver/294/wiki/HOWTO_TestAbsolutePathFn.wiki 17 | END 18 | FeatureMatrix.wiki 19 | K 25 20 | svn:wc:ra_dav:version-url 21 | V 41 22 | /svn/!svn/ver/319/wiki/FeatureMatrix.wiki 23 | END 24 | ProjectInfo.wiki 25 | K 25 26 | svn:wc:ra_dav:version-url 27 | V 39 28 | /svn/!svn/ver/337/wiki/ProjectInfo.wiki 29 | END 30 | GeneralFaq.wiki 31 | K 25 32 | svn:wc:ra_dav:version-url 33 | V 38 34 | /svn/!svn/ver/284/wiki/GeneralFaq.wiki 35 | END 36 | -------------------------------------------------------------------------------- /bin/which: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # $Id$ 3 | # 4 | # This is a simple implementation of the 'which' command for those OSes that 5 | # don't have one. 6 | # 7 | 8 | true; TRUE=$? 9 | false; FALSE=$? 10 | 11 | showAll=${FALSE} 12 | 13 | # process command line flags 14 | while getopts 'a' opt; do 15 | case ${opt} in 16 | a) showAll=${TRUE} 17 | esac 18 | done 19 | shift `expr ${OPTIND} - 1` 20 | 21 | # exit if no arguments were given 22 | [ $# -eq 0 ] && exit 1 23 | 24 | command=$1 25 | 26 | # search for command 27 | out=`echo "${PATH}" |sed "s/:/\n/g" |\ 28 | while read path; do 29 | fullPath="${path}/${command}" 30 | if [ -x "${fullPath}" ]; then 31 | echo "${fullPath}" 32 | [ ${showAll} -eq ${FALSE} ] && break 33 | fi 34 | done` 35 | [ -z "${out}" ] && exit 1 36 | echo "${out}" 37 | -------------------------------------------------------------------------------- /src/shunit2_test_standalone.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # $Id$ 3 | # vim:et:ft=sh:sts=2:sw=2 4 | # 5 | # Copyright 2010 Kate Ward. All Rights Reserved. 6 | # Released under the LGPL (GNU Lesser General Public License) 7 | # Author: kate.ward@forestent.com (Kate Ward) 8 | # 9 | # shUnit2 unit test for standalone operation. 10 | # 11 | # This unit test is purely to test that calling shunit2 directly, while passing 12 | # the name of a unit test script, works. When run, this script determines if it 13 | # is running as a standalone program, and calls main() if it is. 14 | 15 | ARGV0=`basename "$0"` 16 | 17 | # load test helpers 18 | . ./shunit2_test_helpers 19 | 20 | #------------------------------------------------------------------------------ 21 | # suite tests 22 | # 23 | 24 | testStandalone() 25 | { 26 | assertTrue ${SHUNIT_TRUE} 27 | } 28 | 29 | #------------------------------------------------------------------------------ 30 | # main 31 | # 32 | 33 | main() 34 | { 35 | ${TH_SHUNIT} "${ARGV0}" 36 | } 37 | 38 | # are we running as a standalone? 39 | if [ "${ARGV0}" = 'shunit2_test_standalone.sh' ]; then 40 | if [ $# -gt 0 ]; then main "$@"; else main; fi 41 | fi 42 | -------------------------------------------------------------------------------- /lib/shlib: -------------------------------------------------------------------------------- 1 | # $Id: shlib 14 2007-02-18 19:43:41Z sfsetse $ 2 | # vim:et:ft=sh:sts=2:sw=2 3 | # 4 | # Copyright 2008 Kate Ward. All Rights Reserved. 5 | # Released under the LGPL (GNU Lesser General Public License). 6 | # Author: kate.ward@forestent.com (Kate Ward) 7 | # 8 | # Library of shell functions. 9 | 10 | # Convert a relative path into it's absolute equivalent. 11 | # 12 | # This function will automatically prepend the current working directory if the 13 | # path is not already absolute. It then removes all parent references (../) to 14 | # reconstruct the proper absolute path. 15 | # 16 | # Args: 17 | # shlib_path_: string: relative path 18 | # Outputs: 19 | # string: absolute path 20 | shlib_relToAbsPath() 21 | { 22 | shlib_path_=$1 23 | 24 | # prepend current directory to relative paths 25 | echo "${shlib_path_}" |grep '^/' >/dev/null 2>&1 \ 26 | || shlib_path_="`pwd`/${shlib_path_}" 27 | 28 | # clean up the path. if all seds supported true regular expressions, then 29 | # this is what it would be: 30 | shlib_old_=${shlib_path_} 31 | while true; do 32 | shlib_new_=`echo "${shlib_old_}" |sed 's/[^/]*\/\.\.\/*//g;s/\/\.\//\//'` 33 | [ "${shlib_old_}" = "${shlib_new_}" ] && break 34 | shlib_old_=${shlib_new_} 35 | done 36 | echo "${shlib_new_}" 37 | 38 | unset shlib_path_ shlib_old_ shlib_new_ 39 | } 40 | -------------------------------------------------------------------------------- /doc/design_doc.txt: -------------------------------------------------------------------------------- 1 | Design Doc for shUnit 2 | 3 | shUnit is based upon JUnit. The initial ideas for the script came from the book 4 | "Pragmatic Unit Testing - In Java with JUnit" by Andrew Hunt and David Thomas. 5 | 6 | The script was written to perform unit testing for log4sh. log4sh had grown 7 | enough that it was becoming difficult to easily test and and verify that the 8 | tests passed for the many different operating systems on which it was being 9 | used. 10 | 11 | The functions in shUnit are meant to match those in JUnit as much as possible 12 | where shell allows. In the initial version, there will be no concept of 13 | exceptions (as normal POSIX shell has no concept of them) but attempts to trap 14 | problems will be done. 15 | 16 | Programatic Standards: 17 | 18 | * SHUNIT_TRUE - public global constant 19 | * __SHUNIT_SHELL_FLAGS - private global constant 20 | * __shunit_oldShellFlags - private global variable 21 | 22 | * assertEquals - public unit test function 23 | * shunit_publicFunc - public shUnit function; can be called from parent unit 24 | test script 25 | * _shunit_privateFunc - private shUnit function; should not be called from 26 | parent script. meant for internal use by shUnit 27 | 28 | * _su_myVar - variable inside a public function. prefixing with '_su_' to 29 | reduce the chances that a variable outside of shUnit will be overridden. 30 | * _su__myVar - variable inside a private function. prefixing with '_su__' to 31 | reduce the chances that a variable in a shUnit public function, or a variable 32 | outside of shUnit will be overridden. 33 | 34 | $Revision$ 35 | -------------------------------------------------------------------------------- /bin/gen_test_results.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # $Id: gen_test_results.sh 54 2008-10-21 23:29:23Z kate.ward@forestent.com $ 3 | # vim:et:ft=sh:sts=2:sw=2 4 | # 5 | # Copyright 2008 Kate Ward. All Rights Reserved. 6 | # Released under the LGPL (GNU Lesser General Public License) 7 | # 8 | # Author: kate.ward@forestent.com (Kate Ward) 9 | # 10 | # This script runs the provided unit tests and sends the output to the 11 | # appropriate file. 12 | # 13 | 14 | # treat unset variables as an error 15 | set -u 16 | 17 | die() 18 | { 19 | [ $# -gt 0 ] && echo "error: $@" >&2 20 | exit 1 21 | } 22 | 23 | BASE_DIR="`dirname $0`/.." 24 | LIB_DIR="${BASE_DIR}/lib" 25 | 26 | # load libraries 27 | . ${LIB_DIR}/shflags || die 'unable to load shflags library' 28 | . ${LIB_DIR}/shlib || die 'unable to load shlib library' 29 | . ${LIB_DIR}/versions || die 'unable to load versions library' 30 | 31 | BASE_DIR=`shlib_relToAbsPath "${BASE_DIR}"` 32 | SRC_DIR="${BASE_DIR}/src" 33 | 34 | os_name=`versions_osName |sed 's/ /_/g'` 35 | os_version=`versions_osVersion` 36 | 37 | DEFINE_boolean force false 'force overwrite' f 38 | DEFINE_string output_dir "`pwd`" 'output dir' d 39 | DEFINE_string output_file "${os_name}-${os_version}.txt" 'output file' o 40 | DEFINE_string suite 'shunit2_test.sh' 'unit test suite' s 41 | FLAGS "${@:-}" || exit $?; shift ${FLAGS_ARGC} 42 | 43 | # determine output filename 44 | output="${FLAGS_output_dir:+${FLAGS_output_dir}/}${FLAGS_output_file}" 45 | output=`shlib_relToAbsPath "${output}"` 46 | 47 | # checks 48 | if [ -f "${output}" ]; then 49 | if [ ${FLAGS_force} -eq ${FLAGS_TRUE} ]; then 50 | rm -f "${output}" 51 | else 52 | echo "not overwriting '${output}'" >&2 53 | exit ${FLAGS_ERROR} 54 | fi 55 | fi 56 | touch "${output}" 2>/dev/null || die "unable to write to '${output}'" 57 | 58 | # run tests 59 | ( cd "${SRC_DIR}"; ./${FLAGS_suite} |tee "${output}" ) 60 | 61 | echo >&2 62 | echo "output written to '${output}'" >&2 63 | -------------------------------------------------------------------------------- /doc/RELEASE_NOTES-2.1.3.txt: -------------------------------------------------------------------------------- 1 | Release Notes for shUnit2 2.1.3 2 | =============================== 3 | 4 | This release is minor feature release. It improves support for zsh (although it 5 | still isn't what it could be) and adds automated testing framework support by 6 | returning a non-zero exit when tests fail. 7 | 8 | To use zsh with shUnit2, the following two requirements must be met: 9 | * The ``shwordsplit`` option must be set. 10 | * The ``function_argzero`` option must be unset. 11 | 12 | Please read the Shell Errata section of the documentation for guidance on how 13 | to meet these requirements. 14 | 15 | See the ``CHANGES-2.1.txt`` file for a full list of changes. 16 | 17 | 18 | Tested Platforms 19 | ---------------- 20 | 21 | Cygwin 22 | 23 | - bash 3.2.33(18) 24 | - pdksh 5.2.14 25 | 26 | Linux 27 | 28 | - bash 3.2.33(1) 29 | - dash 0.5.4 30 | - ksh 1993-12-28 31 | - pdksh 5.2.14 32 | - zsh 4.3.4 33 | 34 | Mac OS X 10.5.2 (Darwin 9.2.2) 35 | 36 | - bash 3.2.17(1) 37 | - ksh 1993-12-28 38 | - zsh 4.3.4 39 | 40 | Solaris 11 x86 (Nevada 77) 41 | 42 | - /bin/sh 43 | - bash 3.2.25(1) 44 | - ksh M-11/16/88i 45 | - zsh 4.3.4 46 | 47 | 48 | New Features 49 | ------------ 50 | 51 | None. 52 | 53 | 54 | Changes and Enhancements 55 | ------------------------ 56 | 57 | Support for automated testing frameworks. 58 | 59 | 60 | Bug Fixes 61 | --------- 62 | 63 | Fixed some issues with zsh support. 64 | 65 | 66 | Deprecated Features 67 | ------------------- 68 | 69 | None. 70 | 71 | 72 | Known Bugs and Issues 73 | --------------------- 74 | 75 | Functions do not properly test for an invalid number of arguments. 76 | 77 | ksh and pdksh do not pass null arguments (i.e. empty strings as '') properly, 78 | and as such checks do not work properly. 79 | 80 | zsh requires the ``shwordsplit`` option to be set, and the ``function_argzero`` 81 | option to be unset for proper operation. 82 | 83 | 84 | .. vim:fileencoding=latin1:ft=rst:spell:textwidth=80 85 | -------------------------------------------------------------------------------- /doc/RELEASE_NOTES-2.1.1.txt: -------------------------------------------------------------------------------- 1 | Release Notes for shUnit2 2.1.1 2 | =============================== 3 | 4 | This is mainly a bug fix release, but it also incorporates a realignment with 5 | the JUnit 4 code. Asserts now provide better failure messages, and the failure 6 | functions no longer perform tests. 7 | 8 | See the ``CHANGES-2.1.txt`` file for a full list of changes. 9 | 10 | 11 | Tested Platforms 12 | ---------------- 13 | 14 | This list of platforms comes from the latest version of log4sh as shUnit2 is 15 | used in the testing of log4sh on each of these platforms. 16 | 17 | Cygwin 18 | 19 | - bash 3.2.15(13) 20 | - pdksh 5.2.14 21 | 22 | Linux 23 | 24 | - bash 3.1.17(1), 3.2.10(1) 25 | - dash 0.5.3 26 | - ksh 1993-12-28 27 | - pdksh 5.2.14 28 | - zsh 4.3.2 (does not work) 29 | 30 | Mac OS X 10.4.9 (Darwin 8.9.1) 31 | 32 | - bash 2.05b.0(1) 33 | - ksh 1993-12-28 34 | 35 | Solaris 8 U3 (x86) 36 | 37 | - /bin/sh 38 | - bash 2.03.0(1) 39 | - ksh M-11/16/88i 40 | 41 | Solaris 10 U2 (sparc, x86) 42 | 43 | - /bin/sh 44 | - bash 3.00.16(1) 45 | - ksh M-11/16/88i 46 | 47 | 48 | New Features 49 | ------------ 50 | 51 | None. 52 | 53 | 54 | Changes and Enhancements 55 | ------------------------ 56 | 57 | The internal test in ``assertFalse()`` now accepts any non-zero value as false. 58 | 59 | The ``assertTrue()`` and ``assertFalse()`` functions now accept an integer value 60 | for a conditional test. A value of '0' is considered 'true', while any non-zero 61 | value is considered 'false'. 62 | 63 | Self-testing unit tests were added. 64 | 65 | 66 | Bug Fixes 67 | --------- 68 | 69 | The ``fail()`` assert now honors skipping. 70 | 71 | The ``docs-docbook-prep`` target now works properly. 72 | 73 | All asserts now properly unset their variables. 74 | 75 | 76 | Deprecated Features 77 | ------------------- 78 | 79 | None. 80 | 81 | 82 | Known Bugs and Issues 83 | --------------------- 84 | 85 | Functions do not properly test for an invalid number of arguments. 86 | 87 | 88 | .. vim:fileencoding=latin1:ft=rst:spell:textwidth=80 89 | -------------------------------------------------------------------------------- /doc/RELEASE_NOTES-2.1.2.txt: -------------------------------------------------------------------------------- 1 | Release Notes for shUnit2 2.1.2 2 | =============================== 3 | 4 | This release adds initial support for the zsh shell. Due to some differences 5 | with this shell as compared with others, some special checks have been added, 6 | and there are some extra requirements necessary when this shell is to be used. 7 | 8 | To use zsh with shUnit2, the following two requirements must be met: 9 | * The ``shwordsplit`` option must be set. 10 | * The ``function_argzero`` option must be unset. 11 | 12 | Please read the Shell Errata section of the documentation for guidance on how 13 | to meet these requirements. 14 | 15 | 16 | See the ``CHANGES-2.1.txt`` file for a full list of changes. 17 | 18 | 19 | Tested Platforms 20 | ---------------- 21 | 22 | This list of platforms comes from the latest version of log4sh as shUnit2 is 23 | used in the testing of log4sh on each of these platforms. 24 | 25 | Linux 26 | 27 | - bash 3.1.17(1), 3.2.25(1) 28 | - dash 0.5.4 29 | - ksh 1993-12-28 30 | - pdksh 5.2.14 31 | - zsh 4.2.5, 4.3.4 32 | 33 | Mac OS X 10.4.11 (Darwin 8.11.1) 34 | 35 | - bash 2.05b.0(1) 36 | - ksh 1993-12-28 37 | - zsh 4.2.3 38 | 39 | Solaris 10 U3 (x86) 40 | 41 | - /bin/sh 42 | - bash 3.00.16(1) 43 | - ksh M-11/16/88i 44 | - zsh 4.2.1 45 | 46 | 47 | New Features 48 | ------------ 49 | 50 | Support for the zsh shell. 51 | 52 | 53 | Changes and Enhancements 54 | ------------------------ 55 | 56 | Added some argument count checks. 57 | 58 | 59 | Bug Fixes 60 | --------- 61 | 62 | None. 63 | 64 | 65 | Deprecated Features 66 | ------------------- 67 | 68 | None. 69 | 70 | 71 | Known Bugs and Issues 72 | --------------------- 73 | 74 | Functions do not properly test for an invalid number of arguments. 75 | 76 | ksh and pdksh do not pass null arguments (i.e. empty strings as '') properly, 77 | and as such checks do not work properly. 78 | 79 | zsh requires the ``shwordsplit`` option to be set, and the ``function_argzero`` 80 | option to be unset for proper operation. 81 | 82 | 83 | .. vim:fileencoding=latin1:ft=rst:spell:textwidth=80 84 | -------------------------------------------------------------------------------- /wiki/.svn/entries: -------------------------------------------------------------------------------- 1 | 10 2 | 3 | dir 4 | 337 5 | http://shunit2.googlecode.com/svn/wiki 6 | http://shunit2.googlecode.com/svn 7 | 8 | 9 | 10 | 2011-05-01T21:11:46.417655Z 11 | 337 12 | kate.ward@forestent.com 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 0b216afc-fc4a-0410-87c2-ade1b7cef105 28 | 29 | HOWTO_TestPossibilityMatrix.wiki 30 | file 31 | 32 | 33 | 34 | 35 | 2011-10-31T09:45:45.991448Z 36 | f06cdae327ed83f02c42b30472442b1c 37 | 2008-10-29T21:27:09.786919Z 38 | 280 39 | kate.ward@forestent.com 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 2771 62 | 63 | HOWTO_TestAbsolutePathFn.wiki 64 | file 65 | 66 | 67 | 68 | 69 | 2011-10-31T09:45:45.991448Z 70 | e0ceabe34dc9f2d3edb59b94446ecb15 71 | 2009-06-06T10:12:12.659313Z 72 | 294 73 | kate.ward@forestent.com 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 9900 96 | 97 | FeatureMatrix.wiki 98 | file 99 | 100 | 101 | 102 | 103 | 2011-10-31T09:45:45.991448Z 104 | d4e7c6ec7e6d6bb7c605b86824954085 105 | 2011-03-15T22:41:41.927783Z 106 | 319 107 | kate.ward@forestent.com 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 683 130 | 131 | ProjectInfo.wiki 132 | file 133 | 134 | 135 | 136 | 137 | 2011-10-31T09:45:45.995448Z 138 | d7b4ec7d82aeeafc3b0e293c640c5937 139 | 2011-05-01T21:11:46.417655Z 140 | 337 141 | kate.ward@forestent.com 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 6147 164 | 165 | GeneralFaq.wiki 166 | file 167 | 168 | 169 | 170 | 171 | 2011-10-31T09:45:45.995448Z 172 | 07357c8efd3eb4d42a3fae35b3b9e55c 173 | 2008-11-17T18:20:15.537855Z 174 | 284 175 | kate.ward@forestent.com 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 5117 198 | 199 | -------------------------------------------------------------------------------- /doc/RELEASE_NOTES-2.1.4.txt: -------------------------------------------------------------------------------- 1 | Release Notes for shUnit2 2.1.4 2 | =============================== 3 | 4 | This release contains lots of bug fixes and changes. Mostly, it fixes zsh 5 | support in zsh 3.0, and the handling of null values in ksh. 6 | 7 | To use zsh with shUnit2, the following requirement must be met: 8 | 9 | - The ``shwordsplit`` option must be set. 10 | 11 | Please read the Shell Errata section of the documentation for guidance on how 12 | to meet these requirements. 13 | 14 | See the ``CHANGES-2.1.txt`` file for a full list of changes. 15 | 16 | 17 | Tested Platforms 18 | ---------------- 19 | 20 | Cygwin 21 | 22 | - bash 3.2.39(19) 23 | - pdksh 5.2.14 24 | - zsh 4.3.4 25 | 26 | Linux (Ubuntu Dapper 6.06) 27 | 28 | - bash 3.1.17(1) 29 | - pdksh 5.2.14 30 | - zsh 4.2.5 31 | 32 | Linux (Ubuntu Hardy 8.04) 33 | 34 | - bash 3.2.39(1) 35 | - dash 0.5.4 36 | - ksh 1993-12-28 37 | - pdksh 5.2.14 38 | - zsh 4.3.4 39 | 40 | Mac OS X 10.5.4 (Darwin 9.4.0) 41 | 42 | - bash 3.2.17(1) 43 | - ksh 1993-12-28 44 | - zsh 4.3.4 45 | 46 | Solaris 9 U6 x86 47 | 48 | - /bin/sh 49 | - bash 2.05.0(1) 50 | - ksh M-11/16/88i 51 | - zsh 3.0.8 52 | 53 | Solaris 11 x86 (Nevada 77) 54 | 55 | - /bin/sh 56 | - bash 3.2.25(1) 57 | - ksh M-11/16/88i 58 | - zsh 4.3.4 59 | 60 | 61 | New Features 62 | ------------ 63 | 64 | Support added to output assert source line number as part of assert messages. 65 | 66 | 67 | Changes and Enhancements 68 | ------------------------ 69 | 70 | Support for automated testing frameworks. 71 | 72 | Added argument count error checking to all functions. 73 | 74 | 75 | Bug Fixes 76 | --------- 77 | 78 | Fixed some issues with ksh and zsh support. 79 | 80 | Fixed off-by-one of exit value in trap handler. 81 | 82 | Fixed handling of null values under ksh. 83 | 84 | Fixed bug in last resort temporary directory creation. 85 | 86 | 87 | Deprecated Features 88 | ------------------- 89 | 90 | None. 91 | 92 | 93 | Known Bugs and Issues 94 | --------------------- 95 | 96 | zsh requires the ``shwordsplit`` option to be set. 97 | 98 | Line numbers in assert messages do not work properly with Bash 2.x. 99 | 100 | .. vim:fileencoding=latin1:ft=rst:spell:tw=80 101 | -------------------------------------------------------------------------------- /examples/mkdir_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # vim:et:ft=sh:sts=2:sw=2 3 | # 4 | # Copyright 2008 Kate Ward. All Rights Reserved. 5 | # Released under the LGPL (GNU Lesser General Public License) 6 | # 7 | # Author: kate.ward@forestent.com (Kate Ward) 8 | # 9 | # Example unit test for the mkdir command. 10 | # 11 | # There are times when an existing shell script needs to be tested. In this 12 | # example, we will test several aspects of the the mkdir command, but the 13 | # techniques could be used for any existing shell script. 14 | 15 | #----------------------------------------------------------------------------- 16 | # suite tests 17 | # 18 | 19 | testMissingDirectoryCreation() 20 | { 21 | ${mkdirCmd} "${testDir}" >${stdoutF} 2>${stderrF} 22 | rtrn=$? 23 | th_assertTrueWithNoOutput ${rtrn} "${stdoutF}" "${stderrF}" 24 | 25 | assertTrue 'directory missing' "[ -d '${testDir}' ]" 26 | } 27 | 28 | testExistingDirectoryCreationFails() 29 | { 30 | # create a directory to test against 31 | ${mkdirCmd} "${testDir}" 32 | 33 | # test for expected failure while trying to create directory that exists 34 | ${mkdirCmd} "${testDir}" >${stdoutF} 2>${stderrF} 35 | rtrn=$? 36 | assertFalse 'expecting return code of 1 (false)' ${rtrn} 37 | assertNull 'unexpected output to stdout' "`cat ${stdoutF}`" 38 | assertNotNull 'expected error message to stderr' "`cat ${stderrF}`" 39 | 40 | assertTrue 'directory missing' "[ -d '${testDir}' ]" 41 | } 42 | 43 | testRecursiveDirectoryCreation() 44 | { 45 | testDir2="${testDir}/test2" 46 | 47 | ${mkdirCmd} -p "${testDir2}" >${stdoutF} 2>${stderrF} 48 | rtrn=$? 49 | th_assertTrueWithNoOutput ${rtrn} "${stdoutF}" "${stderrF}" 50 | 51 | assertTrue 'first directory missing' "[ -d '${testDir}' ]" 52 | assertTrue 'second directory missing' "[ -d '${testDir2}' ]" 53 | } 54 | 55 | #----------------------------------------------------------------------------- 56 | # suite functions 57 | # 58 | 59 | th_assertTrueWithNoOutput() 60 | { 61 | th_return_=$1 62 | th_stdout_=$2 63 | th_stderr_=$3 64 | 65 | assertFalse 'unexpected output to STDOUT' "[ -s '${th_stdout_}' ]" 66 | assertFalse 'unexpected output to STDERR' "[ -s '${th_stderr_}' ]" 67 | 68 | unset th_return_ th_stdout_ th_stderr_ 69 | } 70 | 71 | oneTimeSetUp() 72 | { 73 | outputDir="${SHUNIT_TMPDIR}/output" 74 | mkdir "${outputDir}" 75 | stdoutF="${outputDir}/stdout" 76 | stderrF="${outputDir}/stderr" 77 | 78 | mkdirCmd='mkdir' # save command name in variable to make future changes easy 79 | testDir="${SHUNIT_TMPDIR}/some_test_dir" 80 | } 81 | 82 | tearDown() 83 | { 84 | rm -fr "${testDir}" 85 | } 86 | 87 | # load and run shUnit2 88 | [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 89 | . ../src/shunit2 90 | -------------------------------------------------------------------------------- /doc/RELEASE_NOTES-2.1.0.txt: -------------------------------------------------------------------------------- 1 | Release Notes for shUnit2 2.1.0 2 | =============================== 3 | 4 | This release was branched from shUnit2 2.0.1. It mostly adds new functionality, 5 | but there are couple of bugs fixed from the previous release. 6 | 7 | See the ``CHANGES-2.1.rst`` file for a full list of changes. 8 | 9 | 10 | Tested Platforms 11 | ---------------- 12 | 13 | This list of platforms comes from the latest version of log4sh as shUnit2 is 14 | used in the testing of log4sh on each of these platforms. 15 | 16 | Cygwin 17 | 18 | - bash 3.2.9(10) 19 | - pdksh 5.2.14 20 | 21 | Linux 22 | 23 | - bash 3.1.17(1), 3.2.10(1) 24 | - dash 0.5.3 25 | - ksh 1993-12-28 26 | - pdksh 5.2.14 27 | - zsh 4.3.2 (does not work) 28 | 29 | Mac OS X 10.4.8 (Darwin 8.8) 30 | 31 | - bash 2.05b.0(1) 32 | - ksh 1993-12-28 33 | 34 | Solaris 8 U3 (x86) 35 | 36 | - /bin/sh 37 | - bash 2.03.0(1) 38 | - ksh M-11/16/88i 39 | 40 | Solaris 10 U2 (sparc) 41 | 42 | - /bin/sh 43 | - bash 3.00.16(1) 44 | - ksh M-11/16/88i 45 | 46 | Solaris 10 U2 (x86) 47 | 48 | - /bin/sh 49 | - bash 3.00.16(1) 50 | - ksh M-11/16/88i 51 | 52 | 53 | New Features 54 | ------------ 55 | 56 | Test skipping 57 | 58 | Support added for test "skipping". A skip mode can be enabled so that 59 | subsequent ``assert`` and ``fail`` functions that are called will be recorded 60 | as "skipped" rather than as "passed" or "failed". This functionality can be 61 | used such that when a set of tests makes sense on one platform but not on 62 | another, they can be effectively disabled without altering the total number 63 | of tests. 64 | 65 | One example might be when something is supported under ``bash``, but not 66 | under a standard Bourne shell. 67 | 68 | New functions: ``startSkipping()``, ``endSkipping``, ``isSkipping`` 69 | 70 | 71 | Changes and Enhancements 72 | ------------------------ 73 | 74 | Moving to the use of `reStructured Text 75 | `_ for documentation. It is easy to 76 | read and edit in textual form, but converts nicely to HTML. 77 | 78 | The report format has changed. Rather than including a simple "success" 79 | percentage at the end, a percentage is given for each type of test. 80 | 81 | 82 | Bug Fixes 83 | --------- 84 | 85 | The ``fail()`` function did not output the optional failure message. 86 | 87 | Fixed the ``Makefile`` so that the DocBook XML and XSLT files would be 88 | downloaded before documentation parsing will continue. 89 | 90 | 91 | Deprecated Features 92 | ------------------- 93 | 94 | None. 95 | 96 | 97 | Known Bugs and Issues 98 | --------------------- 99 | 100 | None. 101 | 102 | 103 | .. $Revision$ 104 | .. vim:fileencoding=latin1:spell:syntax=rst:textwidth=80 105 | -------------------------------------------------------------------------------- /doc/RELEASE_NOTES-2.1.6.txt: -------------------------------------------------------------------------------- 1 | Release Notes for shUnit2 2.1.6 2 | =============================== 3 | 4 | This release contains bug fixes and changes. It is also the first release to 5 | support running shunit2 as a standalone program. 6 | 7 | Please read the Shell Errata section of the documentation for guidance on how 8 | to meet these requirements. 9 | 10 | See the ``CHANGES-2.1.txt`` file for a full list of changes. 11 | 12 | New Features 13 | ------------ 14 | 15 | Support for running shUnit2 as a standalone program. This makes it possible for 16 | users to execute their unit tests in a manner that is not dependent on the 17 | location an OS distribution maintainer chose to place shUnit2 in the file 18 | system. 19 | 20 | Added support for functions defined like 'function someFunction()'. 21 | 22 | Changes and Enhancements 23 | ------------------------ 24 | 25 | Renamed the public ``shunit_tmpDir`` variable to ``SHUNIT_TMPDIR`` to be more 26 | consistent with the ``TMPDIR`` variable. 27 | 28 | Bug Fixes 29 | --------- 30 | 31 | Fixed issue where shunit2 would fail on some distributions when creating a 32 | temporary directory because the **od** command was not present. 33 | 34 | Deprecated Features 35 | ------------------- 36 | 37 | None. 38 | 39 | Known Bugs and Issues 40 | --------------------- 41 | 42 | Zsh requires the ``shwordsplit`` option to be set. See the documentation for 43 | examples of how to do this. 44 | 45 | Line numbers in assert messages do not work properly with BASH 2.x. 46 | 47 | The Bourne shell of Solaris, BASH 2.x, and Zsh 3.0.x do not properly catch the 48 | SIGTERM signal. As such, shell interpreter failures due to such things as 49 | unbound variables cannot be caught. (See ``shunit_test_misc.sh``) 50 | 51 | Tested Platforms 52 | ---------------- 53 | 54 | Cygwin 1.7.9 (Windows XP SP2) 55 | 56 | - bash 4.1.10(4) 57 | - dash 0.5.6.1 58 | - ksh (sym-link to pdksh) 59 | - pdksh 5.2.14 60 | - zsh 4.3.11 61 | 62 | Linux (Ubuntu Dapper 6.06.2 LTS) 63 | 64 | - bash 3.1.17(1) 65 | - dash 0.5.3 66 | - ksh (sym-link to pdksh) 67 | - pdksh 5.2.14-99/07/13.2 68 | - zsh 4.2.5 69 | 70 | Linux (Ubuntu Hardy 8.04.4 LTS) 71 | 72 | - bash 3.2.39(1) 73 | - dash 0.5.4 74 | - ksh M-1993-12-28 75 | - pdksh 5.2.14-99/07/13.2 76 | - zsh 4.3.4 77 | 78 | Linux (Ubuntu Lucid 10.04.2 LTS) 79 | 80 | - bash 4.1.5(1) 81 | - dash 0.5.5.1 82 | - ksh JM-93t+-2009-05-01 83 | - pdksh 5.2.14-99/07/13.2 84 | - zsh 4.3.10 85 | 86 | Mac OS X 10.6.7 87 | 88 | - bash 3.2.48(1) 89 | - ksh M-1993-12-28 90 | - zsh 4.3.9 91 | 92 | Solaris 8 U7 x86 93 | 94 | - /bin/sh 95 | - bash 2.03.0(1) 96 | - ksh M-11/16/88i 97 | - zsh 3.0.6 98 | 99 | Solaris 9 U6 x86 100 | 101 | - /bin/sh 102 | - bash 2.05.0(1) 103 | - ksh M-11/16/88i 104 | - zsh 3.0.8 105 | 106 | OpenSolaris 2009.06(snv_111b) x86 107 | 108 | - /bin/sh 109 | - bash 3.2.25(1) 110 | - ksh 2008-11-04 111 | 112 | .. vim:fileencoding=latin1:ft=rst:spell:tw=80 113 | -------------------------------------------------------------------------------- /wiki/HOWTO_TestPossibilityMatrix.wiki: -------------------------------------------------------------------------------- 1 | #summary Demonstration of testing a possibility matrix. 2 | 3 | _The following code is pulled from the unit tests of [http://log4sh.sourceforge.net/ log4sh]. The example is somewhat complex, but it does demonstrate the use of a possibility matrix for test outcomes._ 4 | 5 | In this example, sending a logging message to a log4sh appender at a given logging level should result in a message at that logging level or above. Basically, what is happening is that a logging message is being sent at all six possible logging levels simultaneously, and the data file contains a list of the logging levels where a message should actually show up. Don't worry if that makes no sense as the example is for log4sh, but some studying of what is happening will help you understand how you might implement a possibility matrix of your own. 6 | 7 | The possibility matrix (`priorityMatrix.data`) 8 | {{{ 9 | # column definitions 10 | # priority 11 | # which priorities should generate a message 12 | # 13 | # note: the default IFS in pure POSIX shells seems to parse only spaces when 14 | # using the 'read' builtin. as such, only spaces are used as separation 15 | # characters below. 16 | # 17 | # priority TRACE DEBUG INFO WARN ERROR FATAL 18 | TRACE 1 1 1 1 1 1 19 | DEBUG 0 1 1 1 1 1 20 | INFO 0 0 1 1 1 1 21 | WARN 0 0 0 1 1 1 22 | ERROR 0 0 0 0 1 1 23 | FATAL 0 0 0 0 0 1 24 | OFF 0 0 0 0 0 0 25 | }}} 26 | 27 | The test function (actual log4sh-1.4.2 [http://log4sh.svn.sourceforge.net/viewvc/log4sh/tags/source/1.4.2/src/test/testPriority?revision=574&view=markup testPriority] unit test) 28 | {{{ 29 | testPriorityMatrix() 30 | { 31 | DEBUG=': ' 32 | PRIORITY_NAMES='TRACE DEBUG INFO WARN ERROR FATAL' 33 | PRIORITY_POS='1 2 3 4 5 6' 34 | TEST_DATA='priorityMatrix.data' 35 | 36 | # to enable debugging, uncomment the following line 37 | #DEBUG='' 38 | 39 | while read priority outputs; do 40 | # ignore comment lines or blank lines 41 | echo "${priority}" |egrep -v '^(#|$)' >/dev/null || continue 42 | 43 | ${DEBUG} echo "setting appender priority to '${priority}' priority" 44 | appender_setLevel ${APP_NAME} ${priority} 45 | appender_activateOptions ${APP_NAME} 46 | 47 | # the number of outputs must match the number of priority names and 48 | # positions for this to work 49 | for pos in ${PRIORITY_POS}; do 50 | testPriority=`echo ${PRIORITY_NAMES} |cut -d' ' -f${pos}` 51 | shouldOutput=`echo ${outputs} |cut -d' ' -f${pos}` 52 | 53 | ${DEBUG} echo "generating '${testPriority}' message" 54 | result=`log ${testPriority} 'dummy'` 55 | ${DEBUG} echo "result=${result}" 56 | 57 | if [ ${shouldOutput} -eq 1 ]; then 58 | assertNotNull \ 59 | "'${priority}' priority appender did not emit a '${testPriority}' message" \ 60 | "${result}" 61 | else 62 | assertNull \ 63 | "'${priority}' priority appender emitted a '${testPriority}' message" \ 64 | "${result}" 65 | fi 66 | done 67 | done <"${TEST_DATA}" 68 | } 69 | }}} -------------------------------------------------------------------------------- /src/shunit2_test_failures.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # $Id$ 3 | # vim:et:ft=sh:sts=2:sw=2 4 | # 5 | # Copyright 2008 Kate Ward. All Rights Reserved. 6 | # Released under the LGPL (GNU Lesser General Public License) 7 | # 8 | # Author: kate.ward@forestent.com (Kate Ward) 9 | # 10 | # shUnit2 unit test for failure functions 11 | 12 | # load common unit-test functions 13 | . ./shunit2_test_helpers 14 | 15 | #----------------------------------------------------------------------------- 16 | # suite tests 17 | # 18 | 19 | testFail() 20 | { 21 | ( fail >"${stdoutF}" 2>"${stderrF}" ) 22 | th_assertFalseWithOutput 'fail' $? "${stdoutF}" "${stderrF}" 23 | 24 | ( fail "${MSG}" >"${stdoutF}" 2>"${stderrF}" ) 25 | th_assertFalseWithOutput 'fail with msg' $? "${stdoutF}" "${stderrF}" 26 | 27 | ( fail arg1 >"${stdoutF}" 2>"${stderrF}" ) 28 | th_assertFalseWithOutput 'too many arguments' $? "${stdoutF}" "${stderrF}" 29 | } 30 | 31 | testFailNotEquals() 32 | { 33 | ( failNotEquals 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 34 | th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}" 35 | 36 | ( failNotEquals "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 37 | th_assertFalseWithOutput 'same with msg' $? "${stdoutF}" "${stderrF}" 38 | 39 | ( failNotEquals 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 40 | th_assertFalseWithOutput 'not same' $? "${stdoutF}" "${stderrF}" 41 | 42 | ( failNotEquals '' '' >"${stdoutF}" 2>"${stderrF}" ) 43 | th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}" 44 | 45 | ( failNotEquals >"${stdoutF}" 2>"${stderrF}" ) 46 | th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" 47 | 48 | ( failNotEquals arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" ) 49 | th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" 50 | } 51 | 52 | testFailSame() 53 | { 54 | ( failSame 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 55 | th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}" 56 | 57 | ( failSame "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 58 | th_assertFalseWithOutput 'same with msg' $? "${stdoutF}" "${stderrF}" 59 | 60 | ( failSame 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 61 | th_assertFalseWithOutput 'not same' $? "${stdoutF}" "${stderrF}" 62 | 63 | ( failSame '' '' >"${stdoutF}" 2>"${stderrF}" ) 64 | th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}" 65 | 66 | ( failSame >"${stdoutF}" 2>"${stderrF}" ) 67 | th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" 68 | 69 | ( failSame arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" ) 70 | th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" 71 | } 72 | 73 | #----------------------------------------------------------------------------- 74 | # suite functions 75 | # 76 | 77 | oneTimeSetUp() 78 | { 79 | tmpDir="${__shunit_tmpDir}/output" 80 | mkdir "${tmpDir}" 81 | stdoutF="${tmpDir}/stdout" 82 | stderrF="${tmpDir}/stderr" 83 | 84 | MSG='This is a test message' 85 | } 86 | 87 | # load and run shUnit2 88 | [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 89 | . ${TH_SHUNIT} 90 | -------------------------------------------------------------------------------- /wiki/.svn/text-base/HOWTO_TestPossibilityMatrix.wiki.svn-base: -------------------------------------------------------------------------------- 1 | #summary Demonstration of testing a possibility matrix. 2 | 3 | _The following code is pulled from the unit tests of [http://log4sh.sourceforge.net/ log4sh]. The example is somewhat complex, but it does demonstrate the use of a possibility matrix for test outcomes._ 4 | 5 | In this example, sending a logging message to a log4sh appender at a given logging level should result in a message at that logging level or above. Basically, what is happening is that a logging message is being sent at all six possible logging levels simultaneously, and the data file contains a list of the logging levels where a message should actually show up. Don't worry if that makes no sense as the example is for log4sh, but some studying of what is happening will help you understand how you might implement a possibility matrix of your own. 6 | 7 | The possibility matrix (`priorityMatrix.data`) 8 | {{{ 9 | # column definitions 10 | # priority 11 | # which priorities should generate a message 12 | # 13 | # note: the default IFS in pure POSIX shells seems to parse only spaces when 14 | # using the 'read' builtin. as such, only spaces are used as separation 15 | # characters below. 16 | # 17 | # priority TRACE DEBUG INFO WARN ERROR FATAL 18 | TRACE 1 1 1 1 1 1 19 | DEBUG 0 1 1 1 1 1 20 | INFO 0 0 1 1 1 1 21 | WARN 0 0 0 1 1 1 22 | ERROR 0 0 0 0 1 1 23 | FATAL 0 0 0 0 0 1 24 | OFF 0 0 0 0 0 0 25 | }}} 26 | 27 | The test function (actual log4sh-1.4.2 [http://log4sh.svn.sourceforge.net/viewvc/log4sh/tags/source/1.4.2/src/test/testPriority?revision=574&view=markup testPriority] unit test) 28 | {{{ 29 | testPriorityMatrix() 30 | { 31 | DEBUG=': ' 32 | PRIORITY_NAMES='TRACE DEBUG INFO WARN ERROR FATAL' 33 | PRIORITY_POS='1 2 3 4 5 6' 34 | TEST_DATA='priorityMatrix.data' 35 | 36 | # to enable debugging, uncomment the following line 37 | #DEBUG='' 38 | 39 | while read priority outputs; do 40 | # ignore comment lines or blank lines 41 | echo "${priority}" |egrep -v '^(#|$)' >/dev/null || continue 42 | 43 | ${DEBUG} echo "setting appender priority to '${priority}' priority" 44 | appender_setLevel ${APP_NAME} ${priority} 45 | appender_activateOptions ${APP_NAME} 46 | 47 | # the number of outputs must match the number of priority names and 48 | # positions for this to work 49 | for pos in ${PRIORITY_POS}; do 50 | testPriority=`echo ${PRIORITY_NAMES} |cut -d' ' -f${pos}` 51 | shouldOutput=`echo ${outputs} |cut -d' ' -f${pos}` 52 | 53 | ${DEBUG} echo "generating '${testPriority}' message" 54 | result=`log ${testPriority} 'dummy'` 55 | ${DEBUG} echo "result=${result}" 56 | 57 | if [ ${shouldOutput} -eq 1 ]; then 58 | assertNotNull \ 59 | "'${priority}' priority appender did not emit a '${testPriority}' message" \ 60 | "${result}" 61 | else 62 | assertNull \ 63 | "'${priority}' priority appender emitted a '${testPriority}' message" \ 64 | "${result}" 65 | fi 66 | done 67 | done <"${TEST_DATA}" 68 | } 69 | }}} -------------------------------------------------------------------------------- /src/shunit2_test.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # $Id$ 3 | # vim:et:ft=sh:sts=2:sw=2 4 | # 5 | # Copyright 2008 Kate Ward. All Rights Reserved. 6 | # Released under the LGPL (GNU Lesser General Public License) 7 | # Author: kate.ward@forestent.com (Kate Ward) 8 | # 9 | # shUnit2 unit test suite runner. 10 | # 11 | # This script runs all the unit tests that can be found, and generates a nice 12 | # report of the tests. 13 | 14 | MY_NAME=`basename $0` 15 | MY_PATH=`dirname $0` 16 | 17 | PREFIX='shunit2_test_' 18 | SHELLS='/bin/sh /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh' 19 | TESTS='' 20 | for test in ${PREFIX}[a-z]*.sh; do 21 | TESTS="${TESTS} ${test}" 22 | done 23 | 24 | # load common unit test functions 25 | . ../lib/versions 26 | . ./shunit2_test_helpers 27 | 28 | usage() 29 | { 30 | echo "usage: ${MY_NAME} [-e key=val ...] [-s shell(s)] [-t test(s)]" 31 | } 32 | 33 | env='' 34 | 35 | # process command line flags 36 | while getopts 'e:hs:t:' opt; do 37 | case ${opt} in 38 | e) # set an environment variable 39 | key=`expr "${OPTARG}" : '\([^=]*\)='` 40 | val=`expr "${OPTARG}" : '[^=]*=\(.*\)'` 41 | if [ -z "${key}" -o -z "${val}" ]; then 42 | usage 43 | exit 1 44 | fi 45 | eval "${key}='${val}'" 46 | export ${key} 47 | env="${env:+${env} }${key}" 48 | ;; 49 | h) usage; exit 0 ;; # output help 50 | s) shells=${OPTARG} ;; # list of shells to run 51 | t) tests=${OPTARG} ;; # list of tests to run 52 | *) usage; exit 1 ;; 53 | esac 54 | done 55 | shift `expr ${OPTIND} - 1` 56 | 57 | # fill shells and/or tests 58 | shells=${shells:-${SHELLS}} 59 | tests=${tests:-${TESTS}} 60 | 61 | # error checking 62 | if [ -z "${tests}" ]; then 63 | th_error 'no tests found to run; exiting' 64 | exit 1 65 | fi 66 | 67 | cat <&1; ) 123 | done 124 | done 125 | -------------------------------------------------------------------------------- /doc/RELEASE_NOTES-2.1.5.txt: -------------------------------------------------------------------------------- 1 | Release Notes for shUnit2 2.1.5 2 | =============================== 3 | 4 | This release contains several bug fixes and changes. Additionally, it includes 5 | a rewrite of the test output to better match JUnit and PyUnit. 6 | 7 | This version also includes a slightly expanded set of coding standards by which 8 | shUnit2 is coded. It should help anyone reading the code to better understand 9 | it. 10 | 11 | 12 | 13 | Please read the Shell Errata section of the documentation for guidance on how 14 | to meet these requirements. 15 | 16 | See the ``CHANGES-2.1.txt`` file for a full list of changes. 17 | 18 | 19 | Tested Platforms 20 | ---------------- 21 | 22 | Cygwin 23 | 24 | - bash 3.2.39(20) 25 | - ksh (sym-link to pdksh) 26 | - pdksh 5.2.14 27 | - zsh 4.3.4 28 | 29 | Linux (Ubuntu Dapper 6.06) 30 | 31 | - bash 3.1.17(1) 32 | - ksh M-1993-12-28 33 | - pdksh 5.2.14-99/07/13.2 34 | - zsh 4.2.5 35 | 36 | Linux (Ubuntu Hardy 8.04) 37 | 38 | - bash 3.2.39(1) 39 | - dash 0.5.4 40 | - ksh M-1993-12-28 41 | - pdksh 5.2.14-99/07/13.2 42 | - zsh 4.3.4 43 | 44 | Mac OS X 10.5.4 (Darwin 9.4.0) 45 | 46 | - bash 3.2.17(1) 47 | - ksh M-1993-12-28 48 | - zsh 4.3.4 49 | 50 | Solaris 9 U6 x86 51 | 52 | - /bin/sh 53 | - bash 2.05.0(1) 54 | - ksh M-11/16/88i 55 | - zsh 3.0.8 56 | 57 | Solaris 11 x86 (Nevada 77) 58 | 59 | - /bin/sh 60 | - bash 3.2.25(1) 61 | - ksh M-11/16/88i 62 | - zsh 4.3.4 63 | 64 | 65 | New Features 66 | ------------ 67 | 68 | Support added for output assert source line number as part of assert messages. 69 | 70 | Issue #2: Added assertNotEquals() assert. 71 | 72 | Provided a public ``shunit_tmpDir`` variable that can be used by unit test 73 | scripts that need automated and guaranteed cleanup. 74 | 75 | 76 | Changes and Enhancements 77 | ------------------------ 78 | 79 | Issue #3: Removed the check for unset variables as shUnit2 should not expect 80 | scripts being tested to be clean. 81 | 82 | Issue #4: Rewrote the test summary. It is now greatly simplified and much more 83 | script friendly. 84 | 85 | Issue #5: Fixed the documentation around the usage of failures. 86 | 87 | Issue #9: Added unit tests and improved documentation around the use of macros. 88 | 89 | Code updated to meet documented coding standards. 90 | 91 | Improved code reuse of ``_shunit_exit()`` and ``_shunit_fatal()`` functions. 92 | 93 | All output except shUnit2 error messages now goes to STDOUT. 94 | 95 | Converted DocBook documentation to reStructuredText for easier maintenance. 96 | 97 | 98 | Bug Fixes 99 | --------- 100 | 101 | Issue #1: Fixed bug in rap code where certain types of exit conditions did not 102 | generate the ending report. 103 | 104 | Issue #7: Fixed duplicated printing of messages passed to asserts. 105 | 106 | Fixed bugs in ``shlib_relToAbsPath()`` in ``shlib``. 107 | 108 | 109 | Deprecated Features 110 | ------------------- 111 | 112 | None. 113 | 114 | 115 | Known Bugs and Issues 116 | --------------------- 117 | 118 | Zsh requires the ``shwordsplit`` option to be set. See the documentation for 119 | examples of how to do this. 120 | 121 | Line numbers in assert messages do not work properly with BASH 2.x. 122 | 123 | The Bourne shell of Solaris, BASH 2.x, and Zsh 3.0.x do not properly catch the 124 | SIGTERM signal. As such, shell interpreter failures due to such things as 125 | unbound variables cannot be caught. (See ``shunit_test_misc.sh``) 126 | 127 | 128 | .. vim:fileencoding=latin1:ft=rst:spell:tw=80 129 | -------------------------------------------------------------------------------- /doc/coding_standards.txt: -------------------------------------------------------------------------------- 1 | Coding Standards 2 | ================ 3 | 4 | Variable and Function Names 5 | --------------------------- 6 | 7 | All shUnit2 specific constants, variables, and functions will be prefixed 8 | appropriately with 'shunit'. This is to distinguish usage in the shUnit2 code 9 | from users own scripts so that the shell name space remains predictable to 10 | users. The exceptions here are the standard ``assertEquals``, etc. functions. 11 | 12 | All non-builtin constants and variables will be surrouned with squiggle 13 | brackets, e.g. '${shunit_someVariable}' to improve code readability. 14 | 15 | Due to some shells not supporting local variables in functions, care in the 16 | naming and use of variables, both public and private, is very important. 17 | Accidental overriding of the variables can occur easily if care is not taken as 18 | all variables are technically global variables in some shells. 19 | 20 | +----------------------------------+---------------------------+ 21 | | *type* | *sample* | 22 | +==================================+===========================+ 23 | | global public constant | ``SHUNIT_TRUE`` | 24 | +----------------------------------+---------------------------+ 25 | | global private constant | ``__SHUNIT_SHELL_FLAGS`` | 26 | +----------------------------------+---------------------------+ 27 | | global public variable | not used | 28 | +----------------------------------+---------------------------+ 29 | | global private variable | ``__shunit_someVariable`` | 30 | +----------------------------------+---------------------------+ 31 | | global macro | ``_SHUNIT_SOME_MACRO_`` | 32 | +----------------------------------+---------------------------+ 33 | | public function | ``assertEquals`` | 34 | +----------------------------------+---------------------------+ 35 | | public function, local variable | ``shunit_someVariable_`` | 36 | +----------------------------------+---------------------------+ 37 | | private function | ``_shunit_someFunction`` | 38 | +----------------------------------+---------------------------+ 39 | | private function, local variable | ``_shunit_someVariable_`` | 40 | +----------------------------------+---------------------------+ 41 | 42 | Where it makes sense, variables can have the first letter of the second and 43 | later words capitalized. For example, the local variable name for the total 44 | number of test cases seen might be ``shunit_totalTestsSeen_``. 45 | 46 | Local Variable Cleanup 47 | ---------------------- 48 | 49 | As many shells do not support local variables, no support for cleanup of 50 | variables is present either. As such, all variables local to a function must be 51 | cleared up with the ``unset`` command at the end of each function. 52 | 53 | Indentation 54 | ----------- 55 | 56 | Code block indentation is two (2) spaces, and tabs may not be used. :: 57 | 58 | if [ -z 'some string' ]; then 59 | someFunction 60 | fi 61 | 62 | Lines of code should be no longer than 80 characters unless absolutely 63 | necessary. When lines are wrapped using the backslash character '\', subsequent 64 | lines should be indented with four (4) spaces so as to differentiate from the 65 | standard spacing of two characters. Tabs may *not* be used. :: 66 | 67 | for x in some set of very long set of arguments that make for a very long \ 68 | that extends much too long for one line 69 | do 70 | echo ${x} 71 | done 72 | 73 | .. vim:fileencoding=latin1:ft=rst:spell:tw=80 74 | .. $Revision$ 75 | -------------------------------------------------------------------------------- /src/shunit2_test_helpers: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # vim:et:ft=sh:sts=2:sw=2 3 | # 4 | # Copyright 2008 Kate Ward. All Rights Reserved. 5 | # Released under the LGPL (GNU Lesser General Public License) 6 | # 7 | # Author: kate.ward@forestent.com (Kate Ward) 8 | # 9 | # shUnit2 unit test common functions 10 | 11 | # treat unset variables as an error when performing parameter expansion 12 | set -u 13 | 14 | # set shwordsplit for zsh 15 | [ -n "${ZSH_VERSION:-}" ] && setopt shwordsplit 16 | 17 | # 18 | # constants 19 | # 20 | 21 | # path to shUnit2 library. can be overridden by setting SHUNIT_INC 22 | TH_SHUNIT=${SHUNIT_INC:-./shunit2} 23 | 24 | # configure debugging. set the DEBUG environment variable to any 25 | # non-empty value to enable debug output, or TRACE to enable trace 26 | # output. 27 | TRACE=${TRACE:+'th_trace '} 28 | [ -n "${TRACE}" ] && DEBUG=1 29 | [ -z "${TRACE}" ] && TRACE=':' 30 | 31 | DEBUG=${DEBUG:+'th_debug '} 32 | [ -z "${DEBUG}" ] && DEBUG=':' 33 | 34 | # 35 | # variables 36 | # 37 | 38 | th_RANDOM=0 39 | 40 | # 41 | # functions 42 | # 43 | 44 | # message functions 45 | th_trace() { echo "${MY_NAME}:TRACE $@" >&2; } 46 | th_debug() { echo "${MY_NAME}:DEBUG $@" >&2; } 47 | th_info() { echo "${MY_NAME}:INFO $@" >&2; } 48 | th_warn() { echo "${MY_NAME}:WARN $@" >&2; } 49 | th_error() { echo "${MY_NAME}:ERROR $@" >&2; } 50 | th_fatal() { echo "${MY_NAME}:FATAL $@" >&2; } 51 | 52 | # output subtest name 53 | th_subtest() { echo " $@" >&2; } 54 | 55 | # generate a random number 56 | th_generateRandom() 57 | { 58 | tfgr_random=${th_RANDOM} 59 | 60 | while [ "${tfgr_random}" = "${th_RANDOM}" ]; do 61 | if [ -n "${RANDOM:-}" ]; then 62 | # $RANDOM works 63 | tfgr_random=${RANDOM}${RANDOM}${RANDOM}$$ 64 | elif [ -r '/dev/urandom' ]; then 65 | tfgr_random=`od -vAn -N4 -tu4 "${unittestF}" <"${stdoutF}" 2>"${stderrF}" ) 37 | assertFalse 'expected a non-zero exit value' $? 38 | grep '^ASSERT:Unknown failure' "${stdoutF}" >/dev/null 39 | assertTrue 'assert message was not generated' $? 40 | grep '^Ran [0-9]* test' "${stdoutF}" >/dev/null 41 | assertTrue 'test count message was not generated' $? 42 | grep '^FAILED' "${stdoutF}" >/dev/null 43 | assertTrue 'failure message was not generated' $? 44 | } 45 | 46 | testIssue7() 47 | { 48 | ( assertEquals 'Some message.' 1 2 >"${stdoutF}" 2>"${stderrF}" ) 49 | diff "${stdoutF}" - >/dev/null < but was:<2> 51 | EOF 52 | rtrn=$? 53 | assertEquals ${SHUNIT_TRUE} ${rtrn} 54 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 55 | } 56 | 57 | testPrepForSourcing() 58 | { 59 | assertEquals '/abc' `_shunit_prepForSourcing '/abc'` 60 | assertEquals './abc' `_shunit_prepForSourcing './abc'` 61 | assertEquals './abc' `_shunit_prepForSourcing 'abc'` 62 | } 63 | 64 | testEscapeCharInStr() 65 | { 66 | actual=`_shunit_escapeCharInStr '\' ''` 67 | assertEquals '' "${actual}" 68 | assertEquals 'abc\\' `_shunit_escapeCharInStr '\' 'abc\'` 69 | assertEquals 'abc\\def' `_shunit_escapeCharInStr '\' 'abc\def'` 70 | assertEquals '\\def' `_shunit_escapeCharInStr '\' '\def'` 71 | 72 | actual=`_shunit_escapeCharInStr '"' ''` 73 | assertEquals '' "${actual}" 74 | assertEquals 'abc\"' `_shunit_escapeCharInStr '"' 'abc"'` 75 | assertEquals 'abc\"def' `_shunit_escapeCharInStr '"' 'abc"def'` 76 | assertEquals '\"def' `_shunit_escapeCharInStr '"' '"def'` 77 | 78 | actual=`_shunit_escapeCharInStr '$' ''` 79 | assertEquals '' "${actual}" 80 | assertEquals 'abc\$' `_shunit_escapeCharInStr '$' 'abc$'` 81 | assertEquals 'abc\$def' `_shunit_escapeCharInStr '$' 'abc$def'` 82 | assertEquals '\$def' `_shunit_escapeCharInStr '$' '$def'` 83 | 84 | # actual=`_shunit_escapeCharInStr "'" ''` 85 | # assertEquals '' "${actual}" 86 | # assertEquals "abc\\'" `_shunit_escapeCharInStr "'" "abc'"` 87 | # assertEquals "abc\\'def" `_shunit_escapeCharInStr "'" "abc'def"` 88 | # assertEquals "\\'def" `_shunit_escapeCharInStr "'" "'def"` 89 | 90 | # # must put the backtick in a variable so the shell doesn't misinterpret it 91 | # # while inside a backticked sequence (e.g. `echo '`'` would fail). 92 | # backtick='`' 93 | # actual=`_shunit_escapeCharInStr ${backtick} ''` 94 | # assertEquals '' "${actual}" 95 | # assertEquals '\`abc' \ 96 | # `_shunit_escapeCharInStr "${backtick}" ${backtick}'abc'` 97 | # assertEquals 'abc\`' \ 98 | # `_shunit_escapeCharInStr "${backtick}" 'abc'${backtick}` 99 | # assertEquals 'abc\`def' \ 100 | # `_shunit_escapeCharInStr "${backtick}" 'abc'${backtick}'def'` 101 | } 102 | 103 | testEscapeCharInStr_specialChars() 104 | { 105 | # make sure our forward slash doesn't upset sed 106 | assertEquals '/' `_shunit_escapeCharInStr '\' '/'` 107 | 108 | # some shells escape these differently 109 | #assertEquals '\\a' `_shunit_escapeCharInStr '\' '\a'` 110 | #assertEquals '\\b' `_shunit_escapeCharInStr '\' '\b'` 111 | } 112 | 113 | # Test the various ways of declaring functions. 114 | # 115 | # Prefixing (then stripping) with comment symbol so these functions aren't 116 | # treated as real functions by shUnit2. 117 | testExtractTestFunctions() 118 | { 119 | f="${tmpD}/extract_test_functions" 120 | sed 's/^#//' <"${f}" 121 | #testABC() { echo 'ABC'; } 122 | #test_def() { 123 | # echo 'def' 124 | #} 125 | #testG3 () 126 | #{ 127 | # echo 'G3' 128 | #} 129 | #function test4() { echo '4'; } 130 | # test5() { echo '5'; } 131 | #some_test_function() { echo 'some func'; } 132 | #func_with_test_vars() { 133 | # testVariable=1234 134 | #} 135 | EOF 136 | 137 | actual=`_shunit_extractTestFunctions "${f}"` 138 | assertEquals 'testABC test_def testG3 test4 test5' "${actual}" 139 | } 140 | 141 | #------------------------------------------------------------------------------ 142 | # suite functions 143 | # 144 | 145 | setUp() 146 | { 147 | for f in ${expectedF} ${stdoutF} ${stderrF}; do 148 | cp /dev/null ${f} 149 | done 150 | rm -fr "${tmpD}" 151 | mkdir "${tmpD}" 152 | } 153 | 154 | oneTimeSetUp() 155 | { 156 | tmpD="${SHUNIT_TMPDIR}/tmp" 157 | expectedF="${SHUNIT_TMPDIR}/expected" 158 | stdoutF="${SHUNIT_TMPDIR}/stdout" 159 | stderrF="${SHUNIT_TMPDIR}/stderr" 160 | unittestF="${SHUNIT_TMPDIR}/unittest" 161 | } 162 | 163 | # load and run shUnit2 164 | [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 165 | . ${TH_SHUNIT} 166 | -------------------------------------------------------------------------------- /wiki/GeneralFaq.wiki: -------------------------------------------------------------------------------- 1 | #summary General FAQ (Frequently Asked Questions). 2 | #labels Featured 3 | 4 | = General FAQ = 5 | 6 | 7 | _Note: All examples are written using portable shell, or rather shell that will run on as many platforms as possible._ 8 | 9 | = How do I end all testing immediately upon failure? = 10 | Due to the nature of shell scripting, it is not easy to do something like exception handling. As such, exiting from a tree of function calls to the outer-most call is not particularly easy. When writing unit tests, this is no different, which is why shUnit2 will run through each and every assert you have written rather than stopping after the first failure. If this is not the behavior you desire, there is something you can do. 11 | 12 | To stop the test after the first assert fails, you will need to add '` || return`' to the end of each `assert*()` call that you make. 13 | 14 | Below are two test functions. In the first function – `testAllAsserts()` – both asserts will be executed 100% of the time, even though the first assert will always fail. In the second function – `testUntilFailure()` – the entire test will be halted after the first failure is encountered. 15 | 16 | All asserts will be tested 17 | {{{ 18 | testAllAsserts() 19 | { 20 | assertEqual 1 2 21 | assertEqual 2 2 22 | } 23 | }}} 24 | 25 | Test will proceed until first failure 26 | {{{ 27 | testUntilFailure() 28 | { 29 | assertEqual 1 2 || return 30 | assertEqual 2 2 || return 31 | } 32 | }}} 33 | 34 | = How do I feed data from files as input to tests? = 35 | You have a choice between in-line data that is included as part of the test itself, or data that is stored in an external file. Strict adherents to proper unit testing will point out that unit tests should not touch the disk for any reason, which would indicate that in-line data should always be preferred over external files. 36 | 37 | == In-line data == 38 | There are times when you have a list of various inputs with expected output that you would like to test. The function below provides just one means of doing this fully in-line within the test (i.e. no external input file is required). 39 | 40 | This function is good, for example, when you want to pass a bunch of different input into a function and test the output is always the same. 41 | {{{ 42 | testTryInlineFile() 43 | { 44 | # save stdin, and redirect it from a file 45 | exec 9<&0 </dev/null || continue 54 | 55 | # run the test(s) 56 | assertTrue "[ ${try} -gt 0 ]" 57 | done 58 | # restore stdin 59 | exec 0<&9 9<&- 60 | } 61 | }}} 62 | 63 | There are other times when different input into a function produces different output. This test function allows for a 'try' and 'expected' value to be used. 64 | {{{ 65 | testTryExpectInlineFile() 66 | { 67 | # save stdin, and redirect it from a file 68 | exec 9<&0 </dev/null || continue 76 | 77 | # run the test(s) 78 | tryPlusOne=`expr ${try} + 1` 79 | assertEquals ${expected} ${tryPlusOne} 80 | done 81 | # restore stdin 82 | exec 0<&9 9<&- 83 | } 84 | }}} 85 | 86 | == External files == 87 | There are times when for whatever reason, you need to use an external file as input for running tests, and an in-line file just won't do. The code below demonstrates a test where the input file needs to be read one line at a time so that tests on each line can be evaluated. 88 | 89 | {{{ 90 | testExternalFile() 91 | { 92 | testFile='/path/to/some/test/file' 93 | 94 | while read try; do 95 | # ignore comment lines or blank lines 96 | echo "${try}" |egrep -v '^(#|$)' >/dev/null || continue 97 | 98 | # run the test(s) 99 | assertTrue "[ ${try} -gt 0 ]" 100 | done <"${testFile}" 101 | } 102 | }}} 103 | 104 | = How do I write my own custom asserts? = 105 | The following code is pulled from the unit tests of [http://log4sh.sourceforge.net/ log4sh]. The code demonstrates the testing of various conversion patterns in log4sh. The custom assert was written to reduce code duplication (think the [http://en.wikipedia.org/wiki/Don't_repeat_yourself DRY] principle) for many tests, although only one test is shown. 106 | 107 | {{{ 108 | assertPattern() 109 | { 110 | msg='' 111 | if [ $# -eq 3 ]; then 112 | msg=$1 113 | shift 114 | fi 115 | pattern=$1 116 | expected=$2 117 | 118 | appender_setPattern ${APP_NAME} "${pattern}" 119 | appender_activateOptions ${APP_NAME} 120 | actual=`logger_info 'dummy'` 121 | msg=`eval "echo \"${msg}\""` 122 | assertEquals "${msg}" "${expected}" "${actual}" 123 | } 124 | 125 | testCategoryPattern() 126 | { 127 | pattern='%c' 128 | expected='shell' 129 | msg="category '%c' pattern failed: '\${expected}' != '\${actual}'" 130 | assertPattern "${msg}" "${expected}" "${pattern}" 131 | } 132 | }}} 133 | 134 | = How do I write tests for an already existing command? = 135 | Writing unit tests for a pre-existing binary is not much different than writing unit tests for functions. The only real difference is that you do not have the degree of flexibility of being able to rewrite the command to make testing of unique conditions easier. 136 | 137 | If you would like to see an example of testing the *mkdir* command, look at the `examples/mkdir_test.sh` file in the 2.1.5 (or later) release, or you can browse the source of [http://code.google.com/p/shunit2/source/browse/trunk/source/2.1/examples/mkdir_test.sh mkdir_test.sh] locally. -------------------------------------------------------------------------------- /wiki/.svn/text-base/GeneralFaq.wiki.svn-base: -------------------------------------------------------------------------------- 1 | #summary General FAQ (Frequently Asked Questions). 2 | #labels Featured 3 | 4 | = General FAQ = 5 | 6 | 7 | _Note: All examples are written using portable shell, or rather shell that will run on as many platforms as possible._ 8 | 9 | = How do I end all testing immediately upon failure? = 10 | Due to the nature of shell scripting, it is not easy to do something like exception handling. As such, exiting from a tree of function calls to the outer-most call is not particularly easy. When writing unit tests, this is no different, which is why shUnit2 will run through each and every assert you have written rather than stopping after the first failure. If this is not the behavior you desire, there is something you can do. 11 | 12 | To stop the test after the first assert fails, you will need to add '` || return`' to the end of each `assert*()` call that you make. 13 | 14 | Below are two test functions. In the first function – `testAllAsserts()` – both asserts will be executed 100% of the time, even though the first assert will always fail. In the second function – `testUntilFailure()` – the entire test will be halted after the first failure is encountered. 15 | 16 | All asserts will be tested 17 | {{{ 18 | testAllAsserts() 19 | { 20 | assertEqual 1 2 21 | assertEqual 2 2 22 | } 23 | }}} 24 | 25 | Test will proceed until first failure 26 | {{{ 27 | testUntilFailure() 28 | { 29 | assertEqual 1 2 || return 30 | assertEqual 2 2 || return 31 | } 32 | }}} 33 | 34 | = How do I feed data from files as input to tests? = 35 | You have a choice between in-line data that is included as part of the test itself, or data that is stored in an external file. Strict adherents to proper unit testing will point out that unit tests should not touch the disk for any reason, which would indicate that in-line data should always be preferred over external files. 36 | 37 | == In-line data == 38 | There are times when you have a list of various inputs with expected output that you would like to test. The function below provides just one means of doing this fully in-line within the test (i.e. no external input file is required). 39 | 40 | This function is good, for example, when you want to pass a bunch of different input into a function and test the output is always the same. 41 | {{{ 42 | testTryInlineFile() 43 | { 44 | # save stdin, and redirect it from a file 45 | exec 9<&0 </dev/null || continue 54 | 55 | # run the test(s) 56 | assertTrue "[ ${try} -gt 0 ]" 57 | done 58 | # restore stdin 59 | exec 0<&9 9<&- 60 | } 61 | }}} 62 | 63 | There are other times when different input into a function produces different output. This test function allows for a 'try' and 'expected' value to be used. 64 | {{{ 65 | testTryExpectInlineFile() 66 | { 67 | # save stdin, and redirect it from a file 68 | exec 9<&0 </dev/null || continue 76 | 77 | # run the test(s) 78 | tryPlusOne=`expr ${try} + 1` 79 | assertEquals ${expected} ${tryPlusOne} 80 | done 81 | # restore stdin 82 | exec 0<&9 9<&- 83 | } 84 | }}} 85 | 86 | == External files == 87 | There are times when for whatever reason, you need to use an external file as input for running tests, and an in-line file just won't do. The code below demonstrates a test where the input file needs to be read one line at a time so that tests on each line can be evaluated. 88 | 89 | {{{ 90 | testExternalFile() 91 | { 92 | testFile='/path/to/some/test/file' 93 | 94 | while read try; do 95 | # ignore comment lines or blank lines 96 | echo "${try}" |egrep -v '^(#|$)' >/dev/null || continue 97 | 98 | # run the test(s) 99 | assertTrue "[ ${try} -gt 0 ]" 100 | done <"${testFile}" 101 | } 102 | }}} 103 | 104 | = How do I write my own custom asserts? = 105 | The following code is pulled from the unit tests of [http://log4sh.sourceforge.net/ log4sh]. The code demonstrates the testing of various conversion patterns in log4sh. The custom assert was written to reduce code duplication (think the [http://en.wikipedia.org/wiki/Don't_repeat_yourself DRY] principle) for many tests, although only one test is shown. 106 | 107 | {{{ 108 | assertPattern() 109 | { 110 | msg='' 111 | if [ $# -eq 3 ]; then 112 | msg=$1 113 | shift 114 | fi 115 | pattern=$1 116 | expected=$2 117 | 118 | appender_setPattern ${APP_NAME} "${pattern}" 119 | appender_activateOptions ${APP_NAME} 120 | actual=`logger_info 'dummy'` 121 | msg=`eval "echo \"${msg}\""` 122 | assertEquals "${msg}" "${expected}" "${actual}" 123 | } 124 | 125 | testCategoryPattern() 126 | { 127 | pattern='%c' 128 | expected='shell' 129 | msg="category '%c' pattern failed: '\${expected}' != '\${actual}'" 130 | assertPattern "${msg}" "${expected}" "${pattern}" 131 | } 132 | }}} 133 | 134 | = How do I write tests for an already existing command? = 135 | Writing unit tests for a pre-existing binary is not much different than writing unit tests for functions. The only real difference is that you do not have the degree of flexibility of being able to rewrite the command to make testing of unique conditions easier. 136 | 137 | If you would like to see an example of testing the *mkdir* command, look at the `examples/mkdir_test.sh` file in the 2.1.5 (or later) release, or you can browse the source of [http://code.google.com/p/shunit2/source/browse/trunk/source/2.1/examples/mkdir_test.sh mkdir_test.sh] locally. -------------------------------------------------------------------------------- /README.wiki: -------------------------------------------------------------------------------- 1 | #summary General information regarding the shUnit2 project. 2 | #labels Featured 3 | 4 | = Project Info = 5 | 6 | 7 | == Overview == 8 | [http://sourceforge.net/projects/shunit2 shUnit2] is a [http://en.wikipedia.org/wiki/XUnit xUnit] unit test framework for Bourne based shell scripts, and it is designed to work in a similar manner to [http://www.junit.org/ JUnit], [http://pyunit.sourceforge.net/ PyUnit], etc. If you have ever had the desire to write a unit test for a shell script, shUnit2 can do the job. 9 | 10 | shUnit2 was originally developed to provide a consistent testing solution for [http://log4sh.sourceforge.net/ log4sh], a shell based logging framework similar to [http://logging.apache.org/log4j/ log4j]. During the development of that product, I repeatedly ran into the problem of having things work just fine under one shell (`/bin/bash` on Linux to be specific), and then not working under another shell (`/bin/sh` on Solaris). Although I had some simple tests that I ran, I finally decided to develop a more robust unit test framework after releasing multiple brown-bag releases. 11 | 12 | Rather than reinvent the wheel again, I chose to base the shUnit2 framework as much as possible on JUnit. I wanted something that was both incredibly easy to use, but that was as well incredibly powerful. I knew that the code would be built only for log4sh at the start, but hoped that someday I could release the code as a separate project. Now that the code is stable and mature enough, I have done just that. 13 | 14 | You might ask why I didn't just use the already existing [http://shunit.sourceforge.net/ ShUnit] product. I took a look at it, but wasn't really happy with how it worked or how little it reflected the way JUnit and other unit test frameworks function. As such, I figured that it was probably better just to write my own. 15 | 16 | shUnit2 has been developed under the Bourne Again Shell (`/bin/bash`) on Linux, but _great care_ has been taken to make sure it works under the other Unix shells to insure maximum compatibility. If you like what you see, or have any suggestions on improvements, please feel free to drop me an email. 17 | 18 | _Supported Operating Systems_ 19 | * [http://www.cygwin.com/ Cygwin] (under Microsoft Windows XP) 20 | * [http://www.freebsd.org/ FreeBSD] (user supported) 21 | * Linux ([http://www.ubuntu.com/ Ubuntu]) 22 | * [http://www.apple.com/macosx/ Mac OS X] 23 | * [http://www.sun.com/software/solaris/ Solaris] 8-10 and [http://www.opensolaris.org/ OpenSolaris] 24 | 25 | _Tested Shells_ 26 | * Bourne Shell (*`sh`*) 27 | * [http://www.gnu.org/software/bash/ BASH] – GNU Bourne Again SHell (*`bash`*) 28 | * [http://gondor.apana.org.au/~herbert/dash/ DASH] (*`dash`*) 29 | * [http://www.kornshell.com/ Korn Shell] (*`ksh`*) 30 | * [http://web.cs.mun.ca/~michael/pdksh/ pdksh] – the Public Domain Korn Shell (*`pdksh`*) 31 | * [http://www.zsh.org/ Zsh] - (*`zsh`*) 32 | 33 | == Downloading == 34 | There are two current release series of shUnit2 available. The 2.0 series is the stable release, and it contains only bug fixes. The 2.1 series is meant for new features and is still under active development. The 2.1 series of shUnit2 has its own set of unit tests, and should be considered fine for daily use. 35 | 36 | If you would like to verify the GPG signatures of the releases, please take a look at my [http://forestent.com/wiki/Info:GnuPG GnuPG Info] page. 37 | 38 | === 2.0.x - Stable Releases === 39 | || *Release* || *Date* || 40 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.3.tgz 2.0.3] || Thu Jul 12 2007 || 41 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.2.tgz 2.0.2] || Mon Apr 23 2007 || 42 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.1.tgz 2.0.1] || Wed Feb 21 2007 || 43 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.0.tgz 2.0.0] || Mon Feb 19 2007 || 44 | 45 | === 2.1.x - Development Releases === 46 | || *Release* || *Date* || *Known Issues* || 47 | || [http://shunit2.googlecode.com/files/shunit2-2.1.6.tgz 2.1.6] || Sun May 1 2011 || || 48 | || [http://shunit2.googlecode.com/files/shunit2-2.1.5.tgz 2.1.5] || Wed Oct 29 2008 || || 49 | || [http://shunit2.googlecode.com/files/shunit2-2.1.4.tgz 2.1.4] || Fri Jul 11 2008 || || 50 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.3.tgz 2.1.3] || Sun May 10 2008 || Doesn't work with *`zsh`* versions prior to 4.0. || 51 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.2.tgz 2.1.2] || Mon Dec 31 2007 || || 52 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.1.tgz 2.1.1] || Fri Jul 13 2007 || || 53 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.0.tgz 2.1.0] || Mon Apr 23 2007 || || 54 | 55 | == Support == 56 | 57 | === Documentation === 58 | HTML documentation is also included in the `doc` directory of each distribution. Links to the latest version in Subversion are provided below. 59 | 60 | [http://shunit2.googlecode.com/svn/trunk/source/2.0/doc/shunit2.html 2.0] · 61 | [http://shunit2.googlecode.com/svn/trunk/source/2.1/doc/shunit2.html 2.1] 62 | 63 | You might also be interested in our GeneralFaq page. 64 | 65 | === Examples === 66 | One case study for writing a function to convert a relative path to an absolute path ([http://code.google.com/p/shunit2/wiki/HOWTO_TestAbsolutePathFn HOWTO_TestAbsolutePathFn]). 67 | 68 | Starting with the 2.1.x series, additional examples are included with the source code in the `examples` directory. 69 | * `mkdir_test.sh` – demonstration of testing an existing Unix command (e.g. an already written shell script) 70 | 71 | === Mailing Lists === 72 | A [mailto:shunit2-users@googlegroups.com shunit2-users@googlegroups.com] mailing list now exists. Everyone is free to [http://groups.google.com/group/shunit2-users/topics view the discussions] or to subscribe. 73 | 74 | == Miscellaneous == 75 | 76 | === Licensing === 77 | shUnit2 is licensed under the GNU [http://www.gnu.org/licenses/lgpl.html Lesser General Public License] (LGPL). The contents and copyright of this site and all provided source code are owned by [http://www.linkedin.com/pub/0/9b9/111 Kate Ward]. 78 | 79 | === Thanks === 80 | A list of contributors is provided with each release (found as `doc/contributors.txt`). Many thanks go out to each of these individuals for finding bugs and/or providing patches. 81 | 82 | Hosting resources are gracefully provided by [http://code.google.com/ Google Code]. -------------------------------------------------------------------------------- /wiki/ProjectInfo.wiki: -------------------------------------------------------------------------------- 1 | #summary General information regarding the shUnit2 project. 2 | #labels Featured 3 | 4 | = Project Info = 5 | 6 | 7 | == Overview == 8 | [http://sourceforge.net/projects/shunit2 shUnit2] is a [http://en.wikipedia.org/wiki/XUnit xUnit] unit test framework for Bourne based shell scripts, and it is designed to work in a similar manner to [http://www.junit.org/ JUnit], [http://pyunit.sourceforge.net/ PyUnit], etc. If you have ever had the desire to write a unit test for a shell script, shUnit2 can do the job. 9 | 10 | shUnit2 was originally developed to provide a consistent testing solution for [http://log4sh.sourceforge.net/ log4sh], a shell based logging framework similar to [http://logging.apache.org/log4j/ log4j]. During the development of that product, I repeatedly ran into the problem of having things work just fine under one shell (`/bin/bash` on Linux to be specific), and then not working under another shell (`/bin/sh` on Solaris). Although I had some simple tests that I ran, I finally decided to develop a more robust unit test framework after releasing multiple brown-bag releases. 11 | 12 | Rather than reinvent the wheel again, I chose to base the shUnit2 framework as much as possible on JUnit. I wanted something that was both incredibly easy to use, but that was as well incredibly powerful. I knew that the code would be built only for log4sh at the start, but hoped that someday I could release the code as a separate project. Now that the code is stable and mature enough, I have done just that. 13 | 14 | You might ask why I didn't just use the already existing [http://shunit.sourceforge.net/ ShUnit] product. I took a look at it, but wasn't really happy with how it worked or how little it reflected the way JUnit and other unit test frameworks function. As such, I figured that it was probably better just to write my own. 15 | 16 | shUnit2 has been developed under the Bourne Again Shell (`/bin/bash`) on Linux, but _great care_ has been taken to make sure it works under the other Unix shells to insure maximum compatibility. If you like what you see, or have any suggestions on improvements, please feel free to drop me an email. 17 | 18 | _Supported Operating Systems_ 19 | * [http://www.cygwin.com/ Cygwin] (under Microsoft Windows XP) 20 | * [http://www.freebsd.org/ FreeBSD] (user supported) 21 | * Linux ([http://www.ubuntu.com/ Ubuntu]) 22 | * [http://www.apple.com/macosx/ Mac OS X] 23 | * [http://www.sun.com/software/solaris/ Solaris] 8-10 and [http://www.opensolaris.org/ OpenSolaris] 24 | 25 | _Tested Shells_ 26 | * Bourne Shell (*`sh`*) 27 | * [http://www.gnu.org/software/bash/ BASH] – GNU Bourne Again SHell (*`bash`*) 28 | * [http://gondor.apana.org.au/~herbert/dash/ DASH] (*`dash`*) 29 | * [http://www.kornshell.com/ Korn Shell] (*`ksh`*) 30 | * [http://web.cs.mun.ca/~michael/pdksh/ pdksh] – the Public Domain Korn Shell (*`pdksh`*) 31 | * [http://www.zsh.org/ Zsh] - (*`zsh`*) 32 | 33 | == Downloading == 34 | There are two current release series of shUnit2 available. The 2.0 series is the stable release, and it contains only bug fixes. The 2.1 series is meant for new features and is still under active development. The 2.1 series of shUnit2 has its own set of unit tests, and should be considered fine for daily use. 35 | 36 | If you would like to verify the GPG signatures of the releases, please take a look at my [http://forestent.com/wiki/Info:GnuPG GnuPG Info] page. 37 | 38 | === 2.0.x - Stable Releases === 39 | || *Release* || *Date* || 40 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.3.tgz 2.0.3] || Thu Jul 12 2007 || 41 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.2.tgz 2.0.2] || Mon Apr 23 2007 || 42 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.1.tgz 2.0.1] || Wed Feb 21 2007 || 43 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.0.tgz 2.0.0] || Mon Feb 19 2007 || 44 | 45 | === 2.1.x - Development Releases === 46 | || *Release* || *Date* || *Known Issues* || 47 | || [http://shunit2.googlecode.com/files/shunit2-2.1.6.tgz 2.1.6] || Sun May 1 2011 || || 48 | || [http://shunit2.googlecode.com/files/shunit2-2.1.5.tgz 2.1.5] || Wed Oct 29 2008 || || 49 | || [http://shunit2.googlecode.com/files/shunit2-2.1.4.tgz 2.1.4] || Fri Jul 11 2008 || || 50 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.3.tgz 2.1.3] || Sun May 10 2008 || Doesn't work with *`zsh`* versions prior to 4.0. || 51 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.2.tgz 2.1.2] || Mon Dec 31 2007 || || 52 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.1.tgz 2.1.1] || Fri Jul 13 2007 || || 53 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.0.tgz 2.1.0] || Mon Apr 23 2007 || || 54 | 55 | == Support == 56 | 57 | === Documentation === 58 | HTML documentation is also included in the `doc` directory of each distribution. Links to the latest version in Subversion are provided below. 59 | 60 | [http://shunit2.googlecode.com/svn/trunk/source/2.0/doc/shunit2.html 2.0] · 61 | [http://shunit2.googlecode.com/svn/trunk/source/2.1/doc/shunit2.html 2.1] 62 | 63 | You might also be interested in our GeneralFaq page. 64 | 65 | === Examples === 66 | One case study for writing a function to convert a relative path to an absolute path ([http://code.google.com/p/shunit2/wiki/HOWTO_TestAbsolutePathFn HOWTO_TestAbsolutePathFn]). 67 | 68 | Starting with the 2.1.x series, additional examples are included with the source code in the `examples` directory. 69 | * `mkdir_test.sh` – demonstration of testing an existing Unix command (e.g. an already written shell script) 70 | 71 | === Mailing Lists === 72 | A [mailto:shunit2-users@googlegroups.com shunit2-users@googlegroups.com] mailing list now exists. Everyone is free to [http://groups.google.com/group/shunit2-users/topics view the discussions] or to subscribe. 73 | 74 | == Miscellaneous == 75 | 76 | === Licensing === 77 | shUnit2 is licensed under the GNU [http://www.gnu.org/licenses/lgpl.html Lesser General Public License] (LGPL). The contents and copyright of this site and all provided source code are owned by [http://www.linkedin.com/pub/0/9b9/111 Kate Ward]. 78 | 79 | === Thanks === 80 | A list of contributors is provided with each release (found as `doc/contributors.txt`). Many thanks go out to each of these individuals for finding bugs and/or providing patches. 81 | 82 | Hosting resources are gracefully provided by [http://code.google.com/ Google Code]. -------------------------------------------------------------------------------- /wiki/.svn/text-base/ProjectInfo.wiki.svn-base: -------------------------------------------------------------------------------- 1 | #summary General information regarding the shUnit2 project. 2 | #labels Featured 3 | 4 | = Project Info = 5 | 6 | 7 | == Overview == 8 | [http://sourceforge.net/projects/shunit2 shUnit2] is a [http://en.wikipedia.org/wiki/XUnit xUnit] unit test framework for Bourne based shell scripts, and it is designed to work in a similar manner to [http://www.junit.org/ JUnit], [http://pyunit.sourceforge.net/ PyUnit], etc. If you have ever had the desire to write a unit test for a shell script, shUnit2 can do the job. 9 | 10 | shUnit2 was originally developed to provide a consistent testing solution for [http://log4sh.sourceforge.net/ log4sh], a shell based logging framework similar to [http://logging.apache.org/log4j/ log4j]. During the development of that product, I repeatedly ran into the problem of having things work just fine under one shell (`/bin/bash` on Linux to be specific), and then not working under another shell (`/bin/sh` on Solaris). Although I had some simple tests that I ran, I finally decided to develop a more robust unit test framework after releasing multiple brown-bag releases. 11 | 12 | Rather than reinvent the wheel again, I chose to base the shUnit2 framework as much as possible on JUnit. I wanted something that was both incredibly easy to use, but that was as well incredibly powerful. I knew that the code would be built only for log4sh at the start, but hoped that someday I could release the code as a separate project. Now that the code is stable and mature enough, I have done just that. 13 | 14 | You might ask why I didn't just use the already existing [http://shunit.sourceforge.net/ ShUnit] product. I took a look at it, but wasn't really happy with how it worked or how little it reflected the way JUnit and other unit test frameworks function. As such, I figured that it was probably better just to write my own. 15 | 16 | shUnit2 has been developed under the Bourne Again Shell (`/bin/bash`) on Linux, but _great care_ has been taken to make sure it works under the other Unix shells to insure maximum compatibility. If you like what you see, or have any suggestions on improvements, please feel free to drop me an email. 17 | 18 | _Supported Operating Systems_ 19 | * [http://www.cygwin.com/ Cygwin] (under Microsoft Windows XP) 20 | * [http://www.freebsd.org/ FreeBSD] (user supported) 21 | * Linux ([http://www.ubuntu.com/ Ubuntu]) 22 | * [http://www.apple.com/macosx/ Mac OS X] 23 | * [http://www.sun.com/software/solaris/ Solaris] 8-10 and [http://www.opensolaris.org/ OpenSolaris] 24 | 25 | _Tested Shells_ 26 | * Bourne Shell (*`sh`*) 27 | * [http://www.gnu.org/software/bash/ BASH] – GNU Bourne Again SHell (*`bash`*) 28 | * [http://gondor.apana.org.au/~herbert/dash/ DASH] (*`dash`*) 29 | * [http://www.kornshell.com/ Korn Shell] (*`ksh`*) 30 | * [http://web.cs.mun.ca/~michael/pdksh/ pdksh] – the Public Domain Korn Shell (*`pdksh`*) 31 | * [http://www.zsh.org/ Zsh] - (*`zsh`*) 32 | 33 | == Downloading == 34 | There are two current release series of shUnit2 available. The 2.0 series is the stable release, and it contains only bug fixes. The 2.1 series is meant for new features and is still under active development. The 2.1 series of shUnit2 has its own set of unit tests, and should be considered fine for daily use. 35 | 36 | If you would like to verify the GPG signatures of the releases, please take a look at my [http://forestent.com/wiki/Info:GnuPG GnuPG Info] page. 37 | 38 | === 2.0.x - Stable Releases === 39 | || *Release* || *Date* || 40 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.3.tgz 2.0.3] || Thu Jul 12 2007 || 41 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.2.tgz 2.0.2] || Mon Apr 23 2007 || 42 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.1.tgz 2.0.1] || Wed Feb 21 2007 || 43 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.0.0.tgz 2.0.0] || Mon Feb 19 2007 || 44 | 45 | === 2.1.x - Development Releases === 46 | || *Release* || *Date* || *Known Issues* || 47 | || [http://shunit2.googlecode.com/files/shunit2-2.1.6.tgz 2.1.6] || Sun May 1 2011 || || 48 | || [http://shunit2.googlecode.com/files/shunit2-2.1.5.tgz 2.1.5] || Wed Oct 29 2008 || || 49 | || [http://shunit2.googlecode.com/files/shunit2-2.1.4.tgz 2.1.4] || Fri Jul 11 2008 || || 50 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.3.tgz 2.1.3] || Sun May 10 2008 || Doesn't work with *`zsh`* versions prior to 4.0. || 51 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.2.tgz 2.1.2] || Mon Dec 31 2007 || || 52 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.1.tgz 2.1.1] || Fri Jul 13 2007 || || 53 | || [http://downloads.sourceforge.net/shunit2/shunit2-2.1.0.tgz 2.1.0] || Mon Apr 23 2007 || || 54 | 55 | == Support == 56 | 57 | === Documentation === 58 | HTML documentation is also included in the `doc` directory of each distribution. Links to the latest version in Subversion are provided below. 59 | 60 | [http://shunit2.googlecode.com/svn/trunk/source/2.0/doc/shunit2.html 2.0] · 61 | [http://shunit2.googlecode.com/svn/trunk/source/2.1/doc/shunit2.html 2.1] 62 | 63 | You might also be interested in our GeneralFaq page. 64 | 65 | === Examples === 66 | One case study for writing a function to convert a relative path to an absolute path ([http://code.google.com/p/shunit2/wiki/HOWTO_TestAbsolutePathFn HOWTO_TestAbsolutePathFn]). 67 | 68 | Starting with the 2.1.x series, additional examples are included with the source code in the `examples` directory. 69 | * `mkdir_test.sh` – demonstration of testing an existing Unix command (e.g. an already written shell script) 70 | 71 | === Mailing Lists === 72 | A [mailto:shunit2-users@googlegroups.com shunit2-users@googlegroups.com] mailing list now exists. Everyone is free to [http://groups.google.com/group/shunit2-users/topics view the discussions] or to subscribe. 73 | 74 | == Miscellaneous == 75 | 76 | === Licensing === 77 | shUnit2 is licensed under the GNU [http://www.gnu.org/licenses/lgpl.html Lesser General Public License] (LGPL). The contents and copyright of this site and all provided source code are owned by [http://www.linkedin.com/pub/0/9b9/111 Kate Ward]. 78 | 79 | === Thanks === 80 | A list of contributors is provided with each release (found as `doc/contributors.txt`). Many thanks go out to each of these individuals for finding bugs and/or providing patches. 81 | 82 | Hosting resources are gracefully provided by [http://code.google.com/ Google Code]. -------------------------------------------------------------------------------- /lib/versions: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # $Id: versions 100 2008-11-15 20:24:03Z kate.ward@forestent.com $ 3 | # vim:et:ft=sh:sts=2:sw=2 4 | # 5 | # Copyright 2008 Kate Ward. All Rights Reserved. 6 | # Released under the LGPL (GNU Lesser General Public License) 7 | # 8 | # Author: kate.ward@forestent.com (Kate Ward) 9 | # 10 | # This library provides reusable functions that determine actual names and 11 | # versions of installed shells and the OS. The library can also be run as a 12 | # script if set execuatable. 13 | 14 | ARGV0=`basename "$0"` 15 | LSB_RELEASE='/etc/lsb-release' 16 | VERSIONS_SHELLS="/bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/sh /bin/zsh" 17 | 18 | TRUE=0 19 | FALSE=1 20 | ERROR=2 21 | 22 | __versions_haveStrings=${ERROR} 23 | 24 | #------------------------------------------------------------------------------ 25 | # functions 26 | # 27 | 28 | versions_osName() 29 | { 30 | os_name_='unrecognized' 31 | os_system_=`uname -s` 32 | case ${os_system_} in 33 | CYGWIN_NT-*) os_name_='Cygwin' ;; 34 | Darwin) os_name_='Mac OS X' ;; 35 | FreeBSD) os_name_='FreeBSD' ;; 36 | Linux) os_name_='Linux' ;; 37 | SunOS) 38 | if grep 'OpenSolaris' /etc/release >/dev/null; then 39 | os_name_='OpenSolaris' 40 | else 41 | os_name_='Solaris' 42 | fi 43 | ;; 44 | esac 45 | echo ${os_name_} 46 | unset os_name_ os_system_ 47 | } 48 | 49 | versions_osVersion() 50 | { 51 | os_version_='unrecognized' 52 | os_system_=`uname -s` 53 | os_release_=`uname -r` 54 | case ${os_system_} in 55 | CYGWIN_NT-*) 56 | os_version_=`expr "${os_release_}" : '\([0-9]*\.[0-9]\.[0-9]*\).*'` 57 | ;; 58 | Darwin) 59 | major_='10' 60 | sub_=`echo ${os_release_} |sed 's/^[0-9]*\.\([0-9]*\)\.[0-9]*$/\1/'` 61 | case ${os_release_} in 62 | 8.*) minor_='4' ;; 63 | 9.*) minor_='5' ;; 64 | 10.*) minor_='6' ;; 65 | *) minor_='X'; sub_='X' ;; 66 | esac 67 | os_version_="${major_}.${minor_}.${sub_}" 68 | ;; 69 | FreeBSD) 70 | os_version_=`expr "${os_release_}" : '\([0-9]*\.[0-9]*\)-.*'` 71 | ;; 72 | Linux) 73 | if [ -r "${LSB_RELEASE}" ]; then 74 | if grep -q 'DISTRIB_ID=Ubuntu' "${LSB_RELEASE}"; then 75 | os_version_=`cat "${LSB_RELEASE}" \ 76 | |awk -F= '$1~/DISTRIB_DESCRIPTION/{print $2}' \ 77 | |sed 's/"//g;s/ /-/g'` 78 | fi 79 | elif [ -r '/etc/redhat-release' ]; then 80 | os_version_=`cat /etc/redhat-release` 81 | fi 82 | ;; 83 | SunOS) 84 | if grep 'OpenSolaris' /etc/release >/dev/null; then 85 | os_version_=`grep 'OpenSolaris' /etc/release |awk '{print $2"("$3")"}'` 86 | else 87 | major_=`echo ${os_release_} |sed 's/[0-9]*\.\([0-9]*\)/\1/'` 88 | minor_=`grep Solaris /etc/release |sed 's/[^u]*\(u[0-9]*\).*/\1/'` 89 | os_version_="${major_}${minor_}" 90 | fi 91 | ;; 92 | esac 93 | echo ${os_version_} 94 | unset os_name_ os_release_ os_version_ major_ minor_ sub_ 95 | } 96 | 97 | versions_shellVersion() 98 | { 99 | shell_=$1 100 | 101 | if [ ! -x "${shell_}" ]; then 102 | echo 'not installed' 103 | return 104 | fi 105 | 106 | version_='' 107 | case ${shell_} in 108 | */sh) 109 | # TODO(kward): fix this 110 | ## this could be one of any number of shells. try until one fits. 111 | #version_=`versions_shell_bash ${shell_}` 112 | ## dash cannot be self determined yet 113 | #[ -z "${version_}" ] && version_=`versions_shell_ksh ${shell_}` 114 | ## pdksh is covered in versions_shell_ksh() 115 | #[ -z "${version_}" ] && version_=`versions_shell_zsh ${shell_}` 116 | ;; 117 | */bash) version_=`versions_shell_bash ${shell_}` ;; 118 | */dash) 119 | # simply assuming Ubuntu Linux until somebody comes up with a better 120 | # test. the following test will return an empty string if dash is not 121 | # installed. 122 | version_=`versions_shell_dash` 123 | ;; 124 | */ksh) version_=`versions_shell_ksh ${shell_}` ;; 125 | */pdksh) version_=`versions_shell_pdksh ${shell_}` ;; 126 | */zsh) version_=`versions_shell_zsh ${shell_}` ;; 127 | *) version_='invalid' 128 | esac 129 | 130 | echo ${version_:-unknown} 131 | unset shell_ version_ 132 | } 133 | 134 | versions_shell_bash() 135 | { 136 | $1 --version 2>&1 |grep 'GNU bash' |sed 's/.*version \([^ ]*\).*/\1/' 137 | } 138 | 139 | versions_shell_dash() 140 | { 141 | eval dpkg >/dev/null 2>&1 142 | [ $? -eq 127 ] && return # return if dpkg not found 143 | 144 | dpkg -l |grep ' dash ' |awk '{print $3}' 145 | } 146 | 147 | versions_shell_ksh() 148 | { 149 | versions_shell_=$1 150 | 151 | # see if --version gives a result 152 | versions_version_=`${versions_shell_} --version 2>&1 \ 153 | |sed 's/.*\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\).*/\1/'` 154 | 155 | # --version didn't work... look into the binary 156 | if [ $? -ne ${TRUE} ]; then 157 | _versions_have_strings 158 | versions_version_=`strings ${versions_shell_} 2>&1 \ 159 | |grep Version \ 160 | |sed 's/^.*Version \(.*\)$/\1/;s/ s+ \$$//;s/ /-/g'` 161 | [ -z "${versions_version_}" ] \ 162 | && versions_version_=`versions_shell_pdksh ${versions_shell_}` 163 | fi 164 | 165 | echo ${versions_version_} 166 | 167 | unset versions_shell_ versions_version_ 168 | } 169 | 170 | versions_shell_pdksh() 171 | { 172 | _versions_have_strings 173 | strings $1 2>&1 \ 174 | |grep 'PD KSH' \ 175 | |sed -e 's/.*PD KSH \(.*\)/\1/;s/ /-/g' 176 | } 177 | 178 | versions_shell_zsh() 179 | { 180 | versions_shell_=$1 181 | 182 | versions_version_=`${versions_shell_} --version 2>&1 |awk '{print $2}'` 183 | 184 | if [ $? -ne ${TRUE} ]; then 185 | versions_version_=`echo 'echo ${ZSH_VERSION}' |${versions_shell_}` 186 | fi 187 | 188 | echo ${versions_version_} 189 | 190 | unset versions_shell_ versions_version_ 191 | } 192 | 193 | # Determine if the 'strings' binary installed. 194 | _versions_have_strings() 195 | { 196 | [ ${__versions_haveStrings} -ne ${ERROR} ] && return 197 | eval strings /dev/null >/dev/null 2>&1 198 | if [ $? -eq 0 ]; then 199 | __versions_haveStrings=${TRUE} 200 | else 201 | echo 'WARN: strings not installed. try installing binutils?' >&2 202 | __versions_haveStrings=${FALSE} 203 | fi 204 | } 205 | 206 | #------------------------------------------------------------------------------ 207 | # main 208 | # 209 | 210 | versions_main() 211 | { 212 | # treat unset variables as an error 213 | set -u 214 | 215 | os_name=`versions_osName` 216 | os_version=`versions_osVersion` 217 | echo "os: ${os_name} version: ${os_version}" 218 | 219 | for shell in ${VERSIONS_SHELLS}; do 220 | shell_version=`versions_shellVersion ${shell}` 221 | echo "shell: ${shell} version: ${shell_version}" 222 | done 223 | } 224 | 225 | if [ "${ARGV0}" = 'versions' ]; then 226 | versions_main "$@" 227 | fi 228 | -------------------------------------------------------------------------------- /doc/rst2html.css: -------------------------------------------------------------------------------- 1 | /* 2 | :Author: David Goodger 3 | :Contact: goodger@users.sourceforge.net 4 | :Date: $Date: 2007-04-11 11:48:16 +0100 (Wed, 11 Apr 2007) $ 5 | :Revision: $Revision: 2791 $ 6 | :Copyright: This stylesheet has been placed in the public domain. 7 | :Modified by: Kate Ward 8 | 9 | Default cascading style sheet for the HTML output of Docutils. 10 | 11 | See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to 12 | customize this style sheet. 13 | */ 14 | 15 | /* used to remove borders from tables and images */ 16 | .borderless, table.borderless td, table.borderless th { 17 | border: 0 } 18 | 19 | table.borderless td, table.borderless th { 20 | /* Override padding for "table.docutils td" with "! important". 21 | The right padding separates the table cells. */ 22 | padding: 0 0.5em 0 0 ! important } 23 | 24 | .first { 25 | /* Override more specific margin styles with "! important". */ 26 | margin-top: 0 ! important } 27 | 28 | .last, .with-subtitle { 29 | margin-bottom: 0 ! important } 30 | 31 | .hidden { 32 | display: none } 33 | 34 | a.toc-backref { 35 | text-decoration: none ; 36 | color: black } 37 | 38 | blockquote.epigraph { 39 | margin: 2em 5em ; } 40 | 41 | dl.docutils dd { 42 | margin-bottom: 0.5em } 43 | 44 | /* Uncomment (and remove this text!) to get bold-faced definition list terms 45 | dl.docutils dt { 46 | font-weight: bold } 47 | */ 48 | 49 | div.abstract { 50 | margin: 2em 5em } 51 | 52 | div.abstract p.topic-title { 53 | font-weight: bold ; 54 | text-align: center } 55 | 56 | div.admonition, div.attention, div.caution, div.danger, div.error, 57 | div.hint, div.important, div.note, div.tip, div.warning { 58 | margin: 2em ; 59 | border: medium outset ; 60 | padding: 1em } 61 | 62 | div.admonition p.admonition-title, div.hint p.admonition-title, 63 | div.important p.admonition-title, div.note p.admonition-title, 64 | div.tip p.admonition-title { 65 | font-weight: bold ; 66 | font-family: sans-serif } 67 | 68 | div.attention p.admonition-title, div.caution p.admonition-title, 69 | div.danger p.admonition-title, div.error p.admonition-title, 70 | div.warning p.admonition-title { 71 | color: red ; 72 | font-weight: bold ; 73 | font-family: sans-serif } 74 | 75 | /* Uncomment (and remove this text!) to get reduced vertical space in 76 | compound paragraphs. 77 | div.compound .compound-first, div.compound .compound-middle { 78 | margin-bottom: 0.5em } 79 | 80 | div.compound .compound-last, div.compound .compound-middle { 81 | margin-top: 0.5em } 82 | */ 83 | 84 | div.dedication { 85 | margin: 2em 5em ; 86 | text-align: center ; 87 | font-style: italic } 88 | 89 | div.dedication p.topic-title { 90 | font-weight: bold ; 91 | font-style: normal } 92 | 93 | div.figure { 94 | margin-left: 2em ; 95 | margin-right: 2em } 96 | 97 | div.footer, div.header { 98 | clear: both; 99 | font-size: smaller } 100 | 101 | div.line-block { 102 | display: block ; 103 | margin-top: 1em ; 104 | margin-bottom: 1em } 105 | 106 | div.line-block div.line-block { 107 | margin-top: 0 ; 108 | margin-bottom: 0 ; 109 | margin-left: 1.5em } 110 | 111 | div.sidebar { 112 | margin-left: 1em ; 113 | border: medium outset ; 114 | padding: 1em ; 115 | background-color: #ffffee ; 116 | width: 40% ; 117 | float: right ; 118 | clear: right } 119 | 120 | div.sidebar p.rubric { 121 | font-family: sans-serif ; 122 | font-size: medium } 123 | 124 | div.system-messages { 125 | margin: 5em } 126 | 127 | div.system-messages h1 { 128 | color: red } 129 | 130 | div.system-message { 131 | border: medium outset ; 132 | padding: 1em } 133 | 134 | div.system-message p.system-message-title { 135 | color: red ; 136 | font-weight: bold } 137 | 138 | div.topic { 139 | margin: 2em } 140 | 141 | h1.section-subtitle, h2.section-subtitle, h3.section-subtitle, 142 | h4.section-subtitle, h5.section-subtitle, h6.section-subtitle { 143 | margin-top: 0.4em } 144 | 145 | h1.title { 146 | text-align: center } 147 | 148 | h2.subtitle { 149 | text-align: center } 150 | 151 | hr.docutils { 152 | width: 75% } 153 | 154 | img.align-left { 155 | clear: left } 156 | 157 | img.align-right { 158 | clear: right } 159 | 160 | ol.simple, ul.simple { 161 | margin-bottom: 1em } 162 | 163 | ol.arabic { 164 | list-style: decimal } 165 | 166 | ol.loweralpha { 167 | list-style: lower-alpha } 168 | 169 | ol.upperalpha { 170 | list-style: upper-alpha } 171 | 172 | ol.lowerroman { 173 | list-style: lower-roman } 174 | 175 | ol.upperroman { 176 | list-style: upper-roman } 177 | 178 | p.attribution { 179 | text-align: right ; 180 | margin-left: 50% } 181 | 182 | p.caption { 183 | font-style: italic } 184 | 185 | p.credits { 186 | font-style: italic ; 187 | font-size: smaller } 188 | 189 | p.label { 190 | white-space: nowrap } 191 | 192 | p.rubric { 193 | font-weight: bold ; 194 | font-size: larger ; 195 | color: maroon ; 196 | text-align: center } 197 | 198 | p.sidebar-title { 199 | font-family: sans-serif ; 200 | font-weight: bold ; 201 | font-size: larger } 202 | 203 | p.sidebar-subtitle { 204 | font-family: sans-serif ; 205 | font-weight: bold } 206 | 207 | p.topic-title { 208 | font-weight: bold } 209 | 210 | pre.address { 211 | margin-bottom: 0 ; 212 | margin-top: 0 ; 213 | font-family: serif ; 214 | font-size: 100% } 215 | 216 | pre.literal-block, pre.doctest-block { 217 | margin-left: 2em ; 218 | margin-right: 2em ; 219 | background-color: #eeeeee } 220 | 221 | span.classifier { 222 | font-family: sans-serif ; 223 | font-style: oblique } 224 | 225 | span.classifier-delimiter { 226 | font-family: sans-serif ; 227 | font-weight: bold } 228 | 229 | span.interpreted { 230 | font-family: sans-serif } 231 | 232 | span.option { 233 | white-space: nowrap } 234 | 235 | span.pre { 236 | white-space: pre } 237 | 238 | span.problematic { 239 | color: red } 240 | 241 | span.section-subtitle { 242 | /* font-size relative to parent (h1..h6 element) */ 243 | font-size: 80% } 244 | 245 | table.citation { 246 | border-left: solid 1px gray; 247 | margin-left: 1px } 248 | 249 | table.docinfo { 250 | margin: 2em 4em } 251 | 252 | /* 253 | table.docutils { 254 | margin-top: 0.5em ; 255 | margin-bottom: 0.5em } 256 | */ 257 | 258 | table.footnote { 259 | border-left: solid 1px black; 260 | margin-left: 1px ; 261 | font-size: 80% } 262 | } 263 | 264 | table.docutils td, table.docutils th, 265 | table.docinfo td, table.docinfo th { 266 | padding-left: 0.5em ; 267 | padding-right: 0.5em ; 268 | vertical-align: top } 269 | 270 | table.docutils th.field-name, table.docinfo th.docinfo-name { 271 | font-weight: bold ; 272 | text-align: left ; 273 | white-space: nowrap ; 274 | padding-left: 0 } 275 | 276 | h1 tt.docutils, h2 tt.docutils, h3 tt.docutils, 277 | h4 tt.docutils, h5 tt.docutils, h6 tt.docutils { 278 | font-size: 100% } 279 | 280 | /* 281 | tt.docutils { 282 | background-color: #eeeeee } 283 | */ 284 | 285 | ul.auto-toc { 286 | list-style-type: none } 287 | 288 | /* customizations by kward */ 289 | 290 | h1 { font-size: 133%; border-top:1px solid #CCCCFF; } 291 | h1.title { font-size: 150%; border-top:0px; padding-top: 1em; } 292 | /* div.document { font-size: 90% } */ 293 | -------------------------------------------------------------------------------- /src/shunit2_test_asserts.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # $Id$ 3 | # vim:et:ft=sh:sts=2:sw=2 4 | # 5 | # Copyright 2008 Kate Ward. All Rights Reserved. 6 | # Released under the LGPL (GNU Lesser General Public License) 7 | # 8 | # Author: kate.ward@forestent.com (Kate Ward) 9 | # 10 | # shUnit2 unit test for assert functions 11 | 12 | # load test helpers 13 | . ./shunit2_test_helpers 14 | 15 | #------------------------------------------------------------------------------ 16 | # suite tests 17 | # 18 | 19 | commonEqualsSame() 20 | { 21 | fn=$1 22 | 23 | ( ${fn} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 24 | th_assertTrueWithNoOutput 'equal' $? "${stdoutF}" "${stderrF}" 25 | 26 | ( ${fn} "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 27 | th_assertTrueWithNoOutput 'equal; with msg' $? "${stdoutF}" "${stderrF}" 28 | 29 | ( ${fn} 'abc def' 'abc def' >"${stdoutF}" 2>"${stderrF}" ) 30 | th_assertTrueWithNoOutput 'equal with spaces' $? "${stdoutF}" "${stderrF}" 31 | 32 | ( ${fn} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 33 | th_assertFalseWithOutput 'not equal' $? "${stdoutF}" "${stderrF}" 34 | 35 | ( ${fn} '' '' >"${stdoutF}" 2>"${stderrF}" ) 36 | th_assertTrueWithNoOutput 'null values' $? "${stdoutF}" "${stderrF}" 37 | 38 | ( ${fn} arg1 >"${stdoutF}" 2>"${stderrF}" ) 39 | th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" 40 | 41 | ( ${fn} arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" ) 42 | th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" 43 | } 44 | 45 | commonNotEqualsSame() 46 | { 47 | fn=$1 48 | 49 | ( ${fn} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 50 | th_assertTrueWithNoOutput 'not same' $? "${stdoutF}" "${stderrF}" 51 | 52 | ( ${fn} "${MSG}" 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 53 | th_assertTrueWithNoOutput 'not same, with msg' $? "${stdoutF}" "${stderrF}" 54 | 55 | ( ${fn} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 56 | th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}" 57 | 58 | ( ${fn} '' '' >"${stdoutF}" 2>"${stderrF}" ) 59 | th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}" 60 | 61 | ( ${fn} arg1 >"${stdoutF}" 2>"${stderrF}" ) 62 | th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" 63 | 64 | ( ${fn} arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" ) 65 | th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" 66 | } 67 | 68 | testAssertEquals() 69 | { 70 | commonEqualsSame 'assertEquals' 71 | } 72 | 73 | testAssertNotEquals() 74 | { 75 | commonNotEqualsSame 'assertNotEquals' 76 | } 77 | 78 | testAssertSame() 79 | { 80 | commonEqualsSame 'assertSame' 81 | } 82 | 83 | testAssertNotSame() 84 | { 85 | commonNotEqualsSame 'assertNotSame' 86 | } 87 | 88 | testAssertNull() 89 | { 90 | ( assertNull '' >"${stdoutF}" 2>"${stderrF}" ) 91 | th_assertTrueWithNoOutput 'null' $? "${stdoutF}" "${stderrF}" 92 | 93 | ( assertNull "${MSG}" '' >"${stdoutF}" 2>"${stderrF}" ) 94 | th_assertTrueWithNoOutput 'null, with msg' $? "${stdoutF}" "${stderrF}" 95 | 96 | ( assertNull 'x' >"${stdoutF}" 2>"${stderrF}" ) 97 | th_assertFalseWithOutput 'not null' $? "${stdoutF}" "${stderrF}" 98 | 99 | ( assertNull >"${stdoutF}" 2>"${stderrF}" ) 100 | th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" 101 | 102 | ( assertNull arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" ) 103 | th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" 104 | } 105 | 106 | testAssertNotNull() 107 | { 108 | ( assertNotNull 'x' >"${stdoutF}" 2>"${stderrF}" ) 109 | th_assertTrueWithNoOutput 'not null' $? "${stdoutF}" "${stderrF}" 110 | 111 | ( assertNotNull "${MSG}" 'x' >"${stdoutF}" 2>"${stderrF}" ) 112 | th_assertTrueWithNoOutput 'not null, with msg' $? "${stdoutF}" "${stderrF}" 113 | 114 | ( assertNotNull 'x"b' >"${stdoutF}" 2>"${stderrF}" ) 115 | th_assertTrueWithNoOutput 'not null, with double-quote' $? \ 116 | "${stdoutF}" "${stderrF}" 117 | 118 | ( assertNotNull "x'b" >"${stdoutF}" 2>"${stderrF}" ) 119 | th_assertTrueWithNoOutput 'not null, with single-quote' $? \ 120 | "${stdoutF}" "${stderrF}" 121 | 122 | ( assertNotNull 'x$b' >"${stdoutF}" 2>"${stderrF}" ) 123 | th_assertTrueWithNoOutput 'not null, with dollar' $? \ 124 | "${stdoutF}" "${stderrF}" 125 | 126 | ( assertNotNull 'x`b' >"${stdoutF}" 2>"${stderrF}" ) 127 | th_assertTrueWithNoOutput 'not null, with backtick' $? \ 128 | "${stdoutF}" "${stderrF}" 129 | 130 | ( assertNotNull '' >"${stdoutF}" 2>"${stderrF}" ) 131 | th_assertFalseWithOutput 'null' $? "${stdoutF}" "${stderrF}" 132 | 133 | # there is no test for too few arguments as $1 might actually be null 134 | 135 | ( assertNotNull arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" ) 136 | th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" 137 | } 138 | 139 | testAssertTrue() 140 | { 141 | ( assertTrue 0 >"${stdoutF}" 2>"${stderrF}" ) 142 | th_assertTrueWithNoOutput 'true' $? "${stdoutF}" "${stderrF}" 143 | 144 | ( assertTrue "${MSG}" 0 >"${stdoutF}" 2>"${stderrF}" ) 145 | th_assertTrueWithNoOutput 'true, with msg' $? "${stdoutF}" "${stderrF}" 146 | 147 | ( assertTrue '[ 0 -eq 0 ]' >"${stdoutF}" 2>"${stderrF}" ) 148 | th_assertTrueWithNoOutput 'true condition' $? "${stdoutF}" "${stderrF}" 149 | 150 | ( assertTrue 1 >"${stdoutF}" 2>"${stderrF}" ) 151 | th_assertFalseWithOutput 'false' $? "${stdoutF}" "${stderrF}" 152 | 153 | ( assertTrue '[ 0 -eq 1 ]' >"${stdoutF}" 2>"${stderrF}" ) 154 | th_assertFalseWithOutput 'false condition' $? "${stdoutF}" "${stderrF}" 155 | 156 | ( assertTrue '' >"${stdoutF}" 2>"${stderrF}" ) 157 | th_assertFalseWithOutput 'null' $? "${stdoutF}" "${stderrF}" 158 | 159 | ( assertTrue >"${stdoutF}" 2>"${stderrF}" ) 160 | th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" 161 | 162 | ( assertTrue arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" ) 163 | th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" 164 | } 165 | 166 | testAssertFalse() 167 | { 168 | ( assertFalse 1 >"${stdoutF}" 2>"${stderrF}" ) 169 | th_assertTrueWithNoOutput 'false' $? "${stdoutF}" "${stderrF}" 170 | 171 | ( assertFalse "${MSG}" 1 >"${stdoutF}" 2>"${stderrF}" ) 172 | th_assertTrueWithNoOutput 'false, with msg' $? "${stdoutF}" "${stderrF}" 173 | 174 | ( assertFalse '[ 0 -eq 1 ]' >"${stdoutF}" 2>"${stderrF}" ) 175 | th_assertTrueWithNoOutput 'false condition' $? "${stdoutF}" "${stderrF}" 176 | 177 | ( assertFalse 0 >"${stdoutF}" 2>"${stderrF}" ) 178 | th_assertFalseWithOutput 'true' $? "${stdoutF}" "${stderrF}" 179 | 180 | ( assertFalse '[ 0 -eq 0 ]' >"${stdoutF}" 2>"${stderrF}" ) 181 | th_assertFalseWithOutput 'true condition' $? "${stdoutF}" "${stderrF}" 182 | 183 | ( assertFalse '' >"${stdoutF}" 2>"${stderrF}" ) 184 | th_assertFalseWithOutput 'true condition' $? "${stdoutF}" "${stderrF}" 185 | 186 | ( assertFalse >"${stdoutF}" 2>"${stderrF}" ) 187 | th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" 188 | 189 | ( assertFalse arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" ) 190 | th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" 191 | } 192 | 193 | #------------------------------------------------------------------------------ 194 | # suite functions 195 | # 196 | 197 | oneTimeSetUp() 198 | { 199 | tmpDir="${__shunit_tmpDir}/output" 200 | mkdir "${tmpDir}" 201 | stdoutF="${tmpDir}/stdout" 202 | stderrF="${tmpDir}/stderr" 203 | 204 | MSG='This is a test message' 205 | } 206 | 207 | # load and run shUnit2 208 | [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 209 | . ${TH_SHUNIT} 210 | -------------------------------------------------------------------------------- /doc/README.txt: -------------------------------------------------------------------------------- 1 | ==================== 2 | shUnit2 2.1.x README 3 | ==================== 4 | 5 | code.google.com 6 | =============== 7 | 8 | This project is stored on code.google.com as http://code.google.com/p/shunit2/. 9 | All releases as of 2.1.4 and full source are available there. Documentation is 10 | included as part of the source and each release. Source code is stored in 11 | Subversion and can be accessed using the following information. 12 | 13 | Browse the code in a web browser: 14 | 15 | - http://code.google.com/p/shunit2/source/browse 16 | - svn > trunk > source > 2.1 17 | 18 | Check out the code locally :: 19 | 20 | $ svn checkout http://shunit2.googlecode.com/svn/trunk/ shflags-read-only 21 | 22 | 23 | SourceForge 24 | =========== 25 | 26 | DEPRECATED 27 | 28 | This project is stored on SourceForge as http://sf.net/projects/shunit2. The 29 | source code is stored in Subversion and can be accessed using the following 30 | information. 31 | 32 | Check out the code locally :: 33 | 34 | $ svn co https://shunit2.svn.sourceforge.net/svnroot/shunit2/trunk/source/2.1 shunit2 35 | 36 | Browse the code in a web browser: 37 | 38 | - http://shunit2.svn.sourceforge.net/viewvc/shunit2/trunk/source/2.1/ 39 | - http://shunit2.svn.sourceforge.net/svnroot/shunit2/trunk/source/2.1/ 40 | 41 | 42 | Making a release 43 | ================ 44 | 45 | For these steps, it is assumed we are working with release 2.0.0. 46 | 47 | Steps: 48 | 49 | - write release notes 50 | - update version 51 | - finish changelog 52 | - check all the code in 53 | - tag the release 54 | - export the release 55 | - create tarball 56 | - md5sum the tarball and sign with gpg 57 | - update website 58 | - post to SourceForge and Freshmeat 59 | 60 | Write Release Notes 61 | ------------------- 62 | 63 | This should be pretty self explanatory. Use one of the release notes from a 64 | previous release as an example. 65 | 66 | The versions of the various platforms and shells are included when the 67 | master unit test script is run, or when ``bin/gen_test_results.sh`` is 68 | used. To determine the versions of the installed shells by hand, use the 69 | ``lib/versions`` script. 70 | 71 | Alternatively, do the following: 72 | 73 | +-------+---------+-----------------------------------------------------------+ 74 | | Shell | OS | Notes | 75 | +=======+=========+===========================================================+ 76 | | bash | | ``$ bash --version`` | 77 | +-------+---------+-----------------------------------------------------------+ 78 | | dash | Linux | ``$ dpkg -l |grep dash`` | 79 | +-------+---------+-----------------------------------------------------------+ 80 | | ksh | | ``$ ksh --version`` | 81 | | | | -or- | 82 | | | | ``$ echo 'echo $KSH_VERSION' |ksh`` | 83 | | +---------+-----------------------------------------------------------+ 84 | | | Cygwin | see pdksh | 85 | | +---------+-----------------------------------------------------------+ 86 | | | Solaris | ``$ strings /usr/bin/ksh |grep 'Version'`` | 87 | +-------+---------+-----------------------------------------------------------+ 88 | | pdksh | | ``$ strings /bin/pdksh |grep 'PD KSH'`` | 89 | | +---------+-----------------------------------------------------------+ 90 | | | Cygwin | look in the downloaded Cygwin directory | 91 | +-------+---------+-----------------------------------------------------------+ 92 | | sh | Solaris | not possible | 93 | +-------+---------+-----------------------------------------------------------+ 94 | | zsh | | ``$ zsh --version`` | 95 | +-------+---------+-----------------------------------------------------------+ 96 | 97 | Update Version 98 | -------------- 99 | 100 | Edit ``src/shell/shunit2`` and change the version number in the comment, as well 101 | as in the ``SHUNIT_VERSION`` variable. 102 | 103 | Finish Documentation 104 | -------------------- 105 | 106 | Make sure that any remaining changes get put into the ``CHANGES-X.X.txt`` file. 107 | 108 | Finish writing the ``RELEASE_NOTES-X.X.X.txt``. If necessary, run it 109 | through the **fmt** command to make it pretty (hopefully it is already). :: 110 | 111 | $ fmt -w 80 RELEASE_NOTES-2.0.0.txt >RELEASE_NOTES-2.0.0.txt.new 112 | $ mv RELEASE_NOTES-2.0.0.txt.new RELEASE_NOTES-2.0.0.txt 113 | 114 | We want to have an up-to-date version of the documentation in the release, so 115 | we'd better build it. :: 116 | 117 | $ pwd 118 | .../shunit2/source/2.1 119 | $ cd doc 120 | $ RST2HTML_OPTS='--stylesheet-path=rst2html.css' 121 | $ rst2html ${RST2HTML_OPTS} shunit2.txt >shunit2.html 122 | $ rst2html ${RST2HTML_OPTS} README.txt >README.html 123 | 124 | Check In All the Code 125 | --------------------- 126 | 127 | This step is pretty self-explanatory :: 128 | 129 | $ pwd 130 | .../shunit2/source/2.0 131 | $ svn ci -m "finalizing release" 132 | 133 | Tag the Release 134 | --------------- 135 | :: 136 | 137 | $ pwd 138 | .../shunit2/source 139 | $ ls 140 | 2.0 2.1 141 | $ svn cp -m "Release 2.0.0" 2.0 https://shunit2.googlecode.com/svn/tags/source/2.0.0 142 | 143 | Export the Release 144 | ------------------ 145 | :: 146 | 147 | $ pwd 148 | .../shunit2/builds 149 | $ svn export https://shunit2.googlecode.com/svn/tags/source/2.0.0 shunit2-2.0.0 150 | 151 | Create Tarball 152 | -------------- 153 | :: 154 | 155 | $ tar cfz ../releases/shunit2-2.0.0.tgz shunit2-2.0.0 156 | 157 | Sign the Tarball with gpg 158 | ------------------------- 159 | :: 160 | 161 | $ cd ../releases 162 | $ gpg --default-key kate.ward@forestent.com --detach-sign shunit2-2.0.0.tgz 163 | 164 | Update Website 165 | -------------- 166 | 167 | Again, pretty self-explanatory. Make sure to copy the GPG signature file. Once 168 | that is done, make sure to tag the website so we can go back in time if needed. 169 | :: 170 | 171 | $ pwd 172 | .../shunit2 173 | $ ls 174 | source website 175 | $ svn cp -m "Release 2.0.0" \ 176 | website https://shunit2.googlecode.com/svn/tags/website/20060916 177 | 178 | Now, update the website. It too is held in Subversion, so **ssh** into the web 179 | server and use ``svn up`` to grab the latest version. 180 | 181 | Post to code.google.com and Freshmeat 182 | ------------------------------------- 183 | 184 | - http://code.google.com/p/shunit2/ 185 | - http://freshmeat.net/ 186 | 187 | 188 | Related Documentation 189 | ===================== 190 | 191 | Docbook: 192 | http://www.docbook.org/ 193 | 194 | Docbook XML 195 | docbook-xml-4.4.zip: 196 | http://www.docbook.org/xml/4.4/docbook-xml-4.4.zip 197 | http://www.oasis-open.org/docbook/xml/4.4/docbook-xml-4.4.zip 198 | docbook-xml-4.5.zip: 199 | http://www.docbook.org/xml/4.5/docbook-xml-4.5.zip 200 | Docbook XSL 201 | docbook-xsl-1.71.0.tar.bz2: 202 | http://prdownloads.sourceforge.net/docbook/docbook-xsl-1.71.0.tar.bz2?download 203 | docbook-xsl-1.71.1.tar.bz2: 204 | http://downloads.sourceforge.net/docbook/docbook-xsl-1.71.1.tar.bz2?use_mirror=puzzle 205 | JUnit: 206 | http://www.junit.org/ 207 | reStructuredText: 208 | http://docutils.sourceforge.net/docs/user/rst/quickstart.html 209 | 210 | .. generate HTML using rst2html from Docutils of 211 | .. http://docutils.sourceforge.net/ 212 | .. 213 | .. vim:fileencoding=latin1:ft=rst:spell:tw=80 214 | .. $Revision$ 215 | -------------------------------------------------------------------------------- /doc/CHANGES-2.1.txt: -------------------------------------------------------------------------------- 1 | Changes in shUnit2 2.1.X 2 | ======================== 3 | 4 | Changes with 2.1.6 5 | ------------------ 6 | 7 | Removed all references to the DocBook documentation. 8 | 9 | Simplified the 'src' structure. 10 | 11 | Fixed error message in fail() that stated wrong number of required arguments. 12 | 13 | Updated lib/versions. 14 | 15 | Fixed bug in _shunit_mktempDir() where a failure occurred when the 'od' command was not present in /usr/bin. 16 | 17 | Renamed shunit_tmpDir variable to SHUNIT_TMPDIR to closer match the standard 18 | TMPDIR variable. 19 | 20 | Added support for calling shunit2 as an executable, in addition to the existing 21 | method of sourcing it in as a library. This allows users to keep tests working 22 | despite the location of the shunit2 executable being different for each OS 23 | distribution. 24 | 25 | Issue #14: Improved handling of some strange chars (e.g. single and double 26 | quotes) in messages. 27 | 28 | Issue# 27: Fixed error message for assertSame(). 29 | 30 | Issue# 25: Added check and error message to user when phantom functions are 31 | written to a partition mounted with noexec. 32 | 33 | Issue# 11: Added support for defining functions like 'function someFunction()'. 34 | 35 | 36 | Changes with 2.1.5 37 | ------------------ 38 | 39 | Issue# 1: Fixed bug pointed out by R Bernstein in the trap code where certain 40 | types of exit conditions did not generate the ending report. 41 | 42 | Issue# 2: Added assertNotEquals() assert. 43 | 44 | Issue# 3: Moved check for unset variables out of shUnit2 into the unit tests. 45 | Testing poorly written software blows up if this check is in, but it is only 46 | interesting for shUnit2 itself. Added shunit_test_output.sh unit test for this. 47 | Some shells still do not catch such errors properly (e.g. Bourne shell and BASH 48 | 2.x). 49 | 50 | Added new custom assert in test_helpers to check for output to STDOUT, and none 51 | to STDERR. 52 | 53 | Replaced fatal message in the temp directory creation with a _shunit_fatal() 54 | function call. 55 | 56 | Fixed test_output unit test so it works now that the 'set -u' stuff was removed 57 | for Issue# 3. 58 | 59 | Flushed out the coding standards in the README.txt a bit more, and brought the 60 | shunit2 code up to par with the documented standards. 61 | 62 | Issue# 4: Completely changed the reporting output to be a closer match for 63 | JUnit and PyUnit. As a result, tests are counted separately from assertions. 64 | 65 | Provide public shunit_tmpDir variable that can be used by unit test scripts that 66 | need automated and guaranteed cleanup. 67 | 68 | Issue# 7: Fixed duplicated printing of messages passed to asserts. 69 | 70 | Per code review, fixed wording of failSame() and failNotSame() messages. 71 | 72 | Replaced version_info.sh with versions library and made appropriate changes in 73 | other scripts to use it. 74 | 75 | Added gen_test_results.sh to make releases easier. 76 | 77 | Fixed bugs in shlib_relToAbsPath() in shlib. 78 | 79 | Converted DocBook documentation to reStructuredText for easier maintenance. The 80 | DocBook documentation is now considered obsolete, and will be removed in a 81 | future release. 82 | 83 | Issue# 5: Fixed the documentation around the usage of failures. 84 | 85 | Issue# 9: Added unit tests and updated documentation to demonstrate the 86 | requirement of quoting values twice when macros are used. This is due to how 87 | shell parses arguments. 88 | 89 | When an invalid number of arguments is passed to a function, the invalid number 90 | is returned to the user so they are more aware of what the cause might be. 91 | 92 | 93 | Changes with 2.1.4 94 | ------------------ 95 | 96 | Removed the _shunit_functionExists() function as it was dead code. 97 | 98 | Fixed zsh version number check in version_info. 99 | 100 | Fixed bug in last resort temporary directory creation. 101 | 102 | Fixed off-by-one in exit value for scripts caught by the trap handler. 103 | 104 | Added argument count error checking to all functions. 105 | 106 | Added mkdir_test.sh example. 107 | 108 | Moved src/test into src/shell to better match structure used with shFlags. 109 | 110 | Fixed problem where null values were not handled properly under ksh. 111 | 112 | Added support for outputting line numbers as part of assert messages. 113 | 114 | Started documenting the coding standards, and changed some variable names as a 115 | result. 116 | 117 | Improved zsh version and option checks. 118 | 119 | Renamed the __SHUNIT_VERSION variable to SHUNIT_VERSION. 120 | 121 | 122 | Changes with 2.1.3 123 | ------------------ 124 | 125 | Added some explicit variable defaults, even though the variables are set, as 126 | they sometimes behave strange when the script is canceled. 127 | 128 | Additional workarounds for zsh compatibility. 129 | 130 | shUnit2 now exits with a non-zero exit code if any of the tests failed. This was 131 | done for automated testing frameworks. Tests that were skipped are not 132 | considered failures, and do not affect the exit code. 133 | 134 | Changed detection of STDERR output in unit tests. 135 | 136 | 137 | Changes with 2.1.2 138 | ------------------ 139 | 140 | Unset additional variables that were missed. 141 | 142 | Added checks and workarounds to improve zsh compatibility. 143 | 144 | Added some argument count checks ``assertEquals()``, ``assertNull()``, and 145 | ``assertSame()`` 146 | 147 | 148 | Changes with 2.1.1 149 | ------------------ 150 | 151 | Fixed bug where ``fail()`` was not honoring skipping. 152 | 153 | Fixed problem with ``docs-docbook-prep`` target that prevented it from working. 154 | (Thanks to Bryan Larsen for pointing this out.) 155 | 156 | Changed the test in ``assertFalse()`` so that any non-zero value registers as 157 | false. (Credits to Bryan Larsen) 158 | 159 | Major fiddling to bring more in line with `JUnit `. Asserts 160 | give better output when no message is given, and failures now just fail. 161 | 162 | It was pointed out that the simple 'failed' message for a failed assert was not 163 | only insufficient, it was nonstandard (when compared to JUnit) and didn't 164 | provide the user with an expected vs actual result. The code was revised 165 | somewhat to bring closer into alignment with JUnit (v4.3.1 specifically) so 166 | that it feels more "normal". (Credits to Richard Jensen) 167 | 168 | As part of the JUnit realignment, it was noticed that fail*() functions in 169 | JUnit don't actually do any comparisons themselves. They only generate a 170 | failure message. Updated the code to match. 171 | 172 | Added self-testing unit tests. Kinda horkey, but they did find bugs during the 173 | JUnit realignment. 174 | 175 | Fixed the code for returning from asserts as the return was being called before 176 | the unsetting of variables occurred. (Credits to Mathias Goldau) 177 | 178 | The assert(True|False)() functions now accept an integer value for a 179 | conditional test. A value of '0' is considered 'true', while any non-zero value 180 | is considered 'false'. 181 | 182 | All public functions now fill use default values to work properly with the '-x' 183 | shell debugging flag. 184 | 185 | Fixed the method of percent calculation for the report to get achieve better 186 | accuracy. 187 | 188 | 189 | Changes with 2.1.0 (since 2.0.1) 190 | -------------------------------- 191 | 192 | This release is a branch of the 2.0.1 release. 193 | 194 | Moving to `reStructured Text `_ for 195 | the documentation. 196 | 197 | Fixed problem with ``fail()``. The failure message was not properly printed. 198 | 199 | Fixed the ``Makefile`` so that the DocBook XML and XSLT files would be 200 | downloaded before parsing can continue. 201 | 202 | Renamed the internal ``__SHUNIT_TRUE`` and ``__SHUNIT_FALSE`` variables to 203 | ``SHUNIT_TRUE`` and ``SHUNIT_FALSE`` so that unit tests can "use" them. 204 | 205 | Added support for test "skipping". If skipping is turned on with the 206 | ``startSkip()`` function, ``assert`` and ``fail`` functions will return 207 | immediately, and the skip will be recorded. 208 | 209 | The report output format was changed to include the percentage for each test 210 | result, rather than just those successful. 211 | 212 | 213 | .. $Revision$ 214 | .. vim:fileencoding=latin1:ft=text:spell:tw=80 215 | -------------------------------------------------------------------------------- /src/shunit2_test_macros.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # $Id$ 3 | # vim:et:ft=sh:sts=2:sw=2 4 | # 5 | # Copyright 2008 Kate Ward. All Rights Reserved. 6 | # Released under the LGPL (GNU Lesser General Public License) 7 | # Author: kate.ward@forestent.com (Kate Ward) 8 | # 9 | # shUnit2 unit test for macros. 10 | 11 | # load test helpers 12 | . ./shunit2_test_helpers 13 | 14 | #------------------------------------------------------------------------------ 15 | # suite tests 16 | # 17 | 18 | testAssertEquals() 19 | { 20 | # start skipping if LINENO not available 21 | [ -z "${LINENO:-}" ] && startSkipping 22 | 23 | ( ${_ASSERT_EQUALS_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 24 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 25 | rtrn=$? 26 | assertTrue '_ASSERT_EQUALS_ failure' ${rtrn} 27 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 28 | 29 | ( ${_ASSERT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 30 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 31 | rtrn=$? 32 | assertTrue '_ASSERT_EQUALS_ w/ msg failure' ${rtrn} 33 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 34 | } 35 | 36 | testAssertNotEquals() 37 | { 38 | # start skipping if LINENO not available 39 | [ -z "${LINENO:-}" ] && startSkipping 40 | 41 | ( ${_ASSERT_NOT_EQUALS_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 42 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 43 | rtrn=$? 44 | assertTrue '_ASSERT_NOT_EQUALS_ failure' ${rtrn} 45 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 46 | 47 | ( ${_ASSERT_NOT_EQUALS_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 48 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 49 | rtrn=$? 50 | assertTrue '_ASSERT_NOT_EQUALS_ w/ msg failure' ${rtrn} 51 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 52 | } 53 | 54 | testSame() 55 | { 56 | # start skipping if LINENO not available 57 | [ -z "${LINENO:-}" ] && startSkipping 58 | 59 | ( ${_ASSERT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 60 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 61 | rtrn=$? 62 | assertTrue '_ASSERT_SAME_ failure' ${rtrn} 63 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 64 | 65 | ( ${_ASSERT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 66 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 67 | rtrn=$? 68 | assertTrue '_ASSERT_SAME_ w/ msg failure' ${rtrn} 69 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 70 | } 71 | 72 | testNotSame() 73 | { 74 | # start skipping if LINENO not available 75 | [ -z "${LINENO:-}" ] && startSkipping 76 | 77 | ( ${_ASSERT_NOT_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 78 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 79 | rtrn=$? 80 | assertTrue '_ASSERT_NOT_SAME_ failure' ${rtrn} 81 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 82 | 83 | ( ${_ASSERT_NOT_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 84 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 85 | rtrn=$? 86 | assertTrue '_ASSERT_NOT_SAME_ w/ msg failure' ${rtrn} 87 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 88 | } 89 | 90 | testNull() 91 | { 92 | # start skipping if LINENO not available 93 | [ -z "${LINENO:-}" ] && startSkipping 94 | 95 | ( ${_ASSERT_NULL_} 'x' >"${stdoutF}" 2>"${stderrF}" ) 96 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 97 | rtrn=$? 98 | assertTrue '_ASSERT_NULL_ failure' ${rtrn} 99 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 100 | 101 | ( ${_ASSERT_NULL_} '"some msg"' 'x' >"${stdoutF}" 2>"${stderrF}" ) 102 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 103 | rtrn=$? 104 | assertTrue '_ASSERT_NULL_ w/ msg failure' ${rtrn} 105 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 106 | } 107 | 108 | testNotNull() 109 | { 110 | # start skipping if LINENO not available 111 | [ -z "${LINENO:-}" ] && startSkipping 112 | 113 | ( ${_ASSERT_NOT_NULL_} '' >"${stdoutF}" 2>"${stderrF}" ) 114 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 115 | rtrn=$? 116 | assertTrue '_ASSERT_NOT_NULL_ failure' ${rtrn} 117 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 118 | 119 | ( ${_ASSERT_NOT_NULL_} '"some msg"' '""' >"${stdoutF}" 2>"${stderrF}" ) 120 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 121 | rtrn=$? 122 | assertTrue '_ASSERT_NOT_NULL_ w/ msg failure' ${rtrn} 123 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stdoutF}" "${stderrF}" >&2 124 | } 125 | 126 | testAssertTrue() 127 | { 128 | # start skipping if LINENO not available 129 | [ -z "${LINENO:-}" ] && startSkipping 130 | 131 | ( ${_ASSERT_TRUE_} ${SHUNIT_FALSE} >"${stdoutF}" 2>"${stderrF}" ) 132 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 133 | rtrn=$? 134 | assertTrue '_ASSERT_TRUE_ failure' ${rtrn} 135 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 136 | 137 | 138 | ( ${_ASSERT_TRUE_} '"some msg"' ${SHUNIT_FALSE} >"${stdoutF}" 2>"${stderrF}" ) 139 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 140 | rtrn=$? 141 | assertTrue '_ASSERT_TRUE_ w/ msg failure' ${rtrn} 142 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 143 | } 144 | 145 | testAssertFalse() 146 | { 147 | # start skipping if LINENO not available 148 | [ -z "${LINENO:-}" ] && startSkipping 149 | 150 | ( ${_ASSERT_FALSE_} ${SHUNIT_TRUE} >"${stdoutF}" 2>"${stderrF}" ) 151 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 152 | rtrn=$? 153 | assertTrue '_ASSERT_FALSE_ failure' ${rtrn} 154 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 155 | 156 | ( ${_ASSERT_FALSE_} '"some msg"' ${SHUNIT_TRUE} >"${stdoutF}" 2>"${stderrF}" ) 157 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 158 | rtrn=$? 159 | assertTrue '_ASSERT_FALSE_ w/ msg failure' ${rtrn} 160 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 161 | } 162 | 163 | testFail() 164 | { 165 | # start skipping if LINENO not available 166 | [ -z "${LINENO:-}" ] && startSkipping 167 | 168 | ( ${_FAIL_} >"${stdoutF}" 2>"${stderrF}" ) 169 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 170 | rtrn=$? 171 | assertTrue '_FAIL_ failure' ${rtrn} 172 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 173 | 174 | ( ${_FAIL_} '"some msg"' >"${stdoutF}" 2>"${stderrF}" ) 175 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 176 | rtrn=$? 177 | assertTrue '_FAIL_ w/ msg failure' ${rtrn} 178 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 179 | } 180 | 181 | testFailNotEquals() 182 | { 183 | # start skipping if LINENO not available 184 | [ -z "${LINENO:-}" ] && startSkipping 185 | 186 | ( ${_FAIL_NOT_EQUALS_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 187 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 188 | rtrn=$? 189 | assertTrue '_FAIL_NOT_EQUALS_ failure' ${rtrn} 190 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 191 | 192 | ( ${_FAIL_NOT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 193 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 194 | rtrn=$? 195 | assertTrue '_FAIL_NOT_EQUALS_ w/ msg failure' ${rtrn} 196 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 197 | } 198 | 199 | testFailSame() 200 | { 201 | # start skipping if LINENO not available 202 | [ -z "${LINENO:-}" ] && startSkipping 203 | 204 | ( ${_FAIL_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 205 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 206 | rtrn=$? 207 | assertTrue '_FAIL_SAME_ failure' ${rtrn} 208 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 209 | 210 | ( ${_FAIL_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) 211 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 212 | rtrn=$? 213 | assertTrue '_FAIL_SAME_ w/ msg failure' ${rtrn} 214 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 215 | } 216 | 217 | testFailNotSame() 218 | { 219 | # start skipping if LINENO not available 220 | [ -z "${LINENO:-}" ] && startSkipping 221 | 222 | ( ${_FAIL_NOT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 223 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 224 | rtrn=$? 225 | assertTrue '_FAIL_NOT_SAME_ failure' ${rtrn} 226 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 227 | 228 | ( ${_FAIL_NOT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) 229 | grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null 230 | rtrn=$? 231 | assertTrue '_FAIL_NOT_SAME_ w/ msg failure' ${rtrn} 232 | [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 233 | } 234 | 235 | #------------------------------------------------------------------------------ 236 | # suite functions 237 | # 238 | 239 | oneTimeSetUp() 240 | { 241 | tmpDir="${__shunit_tmpDir}/output" 242 | mkdir "${tmpDir}" 243 | stdoutF="${tmpDir}/stdout" 244 | stderrF="${tmpDir}/stderr" 245 | } 246 | 247 | # load and run shUnit2 248 | [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 249 | . ${TH_SHUNIT} 250 | -------------------------------------------------------------------------------- /wiki/HOWTO_TestAbsolutePathFn.wiki: -------------------------------------------------------------------------------- 1 | #summary Demonstration of testing a simple path to absolute path conversion function. 2 | 3 | 4 | 5 | This example is based upon a real battle I encountered trying to get a particular regular expression to work. I'm not the best when it comes to writing new regexes off the top of my head, and so I end up doing what one might consider a brute-force attack in getting my regexes to work. You might wonder why I don't just learn them, but I must admit that I don't write them often enough for the nuances to stick in my brain. I'm sure others have a better way of doing what you see here (there always is), but I didn't have one at the time. In any case, maybe some of you will sympathize with my battle, and maybe this will give somebody else some ideas for testing their own code. 6 | 7 | = First Go = 8 | _Jan 2007_ 9 | 10 | == Problem == 11 | I once had a tiny shell function I needed to write that took a relative path (e.g. `./bin`) and turned it into the absolute path (e.g. `/home/kward/bin`). 12 | 13 | == Solution == 14 | Here was my first go. I wrapped the function in a simple shell script for easier testing and got the following: 15 | {{{ 16 | #! /bin/sh 17 | 18 | myBase="`basename $0`" 19 | myDir="`dirname $0`" 20 | 21 | relToAbsPath() 22 | { 23 | path=$1 24 | 25 | dir=`dirname "${path}"` 26 | base=`basename "${path}"` 27 | echo "`( cd \"${dir}\" && pwd )`/${base}" 28 | } 29 | 30 | myDir=`relToAbsPath "${myDir}"` 31 | echo "myDir='${myDir}' myBase='${myBase}'" 32 | }}} 33 | 34 | I saved the script as `${HOME}/bin/reltoabs` and called it from my home directory like this: 35 | {{{ 36 | [kward@laptop]~$ ./bin/reltoabs 37 | myDir='/home/kward/bin' myBase='reltoabs' 38 | }}} 39 | 40 | Perfect! It did _exactly_ what I wanted it to do, so I stuck the function in another script and started using it. 41 | 42 | = Second Go = 43 | _Jan 2007_ 44 | 45 | == Problem == 46 | After time, I found a case where my function wasn't doing quite what I wanted. Let's say I had some non-existant relative path `abc/def/ghi` that I wanted to turn into an absolute path. If you noticed, the first version of the function used the *cd* command to change to the *dirname* of the relative directory, and used that information to determine the absolute path. In this case, I had a directory that didn't exist, but I still wanted the function to work. 47 | 48 | Using the same test wrapper script, I changed the `myDir=` line to {{{myDir="`reltoabs 'abc/def/ghi'`"}}} and ran the script just as I did in the first go. Here is what my function gave as output: 49 | {{{ 50 | $ bin/reltoabs.sh 51 | cd: 15: can't cd to abc/def 52 | myDir='/ghi' myBase='reltoabs.sh' 53 | }}} 54 | 55 | As you can see, it didn't work. I spent the next half-hour fighting with various *sed* regexes on the command-line trying to get things to work. Just as I would get something to work for one case, another case wouldn't work. (I had by this time expanded my expected functionality to several different patterns that my function should work properly for, and testing on the command-line was becoming _very_ tedious.) 56 | 57 | After enough time, I decided that I'd better wrap this in some sort of bigger testing script so that I could test the various multiple cases. I thought through it a bit and eventually settled on using shUnit2 as it just made the job very easy. 58 | 59 | == Solution == 60 | Below are two files. The first is a shell script snippit that gets included (a.k.a. "sourced" in shell speak) into the shUnit2 unit test, and the second file is the unit test itself. 61 | 62 | By the time I was to this stage, I had already included the `reltoabs()` function into a more general `shlib_base.inc` library and renamed it to `shlib_relToAbsPath()`, so the source provided looks a bit different than before. You will also notice that I keep a copy of `shunit2` in my HOME directory referenced as `${HOME}/lib/sh/shunit2`. The second file expects this, so if you want to duplicate these results, you will need to fix that. 63 | 64 | `shlib_base.inc` 65 | {{{ 66 | shlib_relToAbsPath() 67 | { 68 | _shlib_path=$1 69 | 70 | # deal with paths that start with / 71 | echo "${_shlib_path}" |grep '^/' >/dev/null 2>&1 72 | if [ $? -ne 0 ]; then 73 | _shlib_pwd=`pwd` 74 | _shlib_path="${_shlib_pwd}/${_shlib_path}" 75 | unset _shlib_pwd 76 | fi 77 | 78 | # clean up the path. 79 | echo "${_shlib_path}" |sed -r 's/[^/]*\/+\.{2}\/*//g;s/\/\.\//\//;s/\/+$//' 80 | 81 | unset _shlib_path 82 | } 83 | }}} 84 | 85 | `shlib_base_test` 86 | {{{ 87 | #! /bin/sh 88 | 89 | #----------------------------------------------------------------------------- 90 | # suite tests 91 | # 92 | 93 | testRelToAbsPath() 94 | { 95 | parent=`dirname ${PWD}` 96 | exec 9<&0 </dev/null 2>&1 && continue 114 | newPath=`shlib_relToAbsPath "${relPath}"` 115 | assertSame \ 116 | "'${relPath}' -> '${newPath}' != '${absPath}'" \ 117 | "${newPath}" "${absPath}" 118 | done 119 | exec 0<&9 9<&- 120 | } 121 | 122 | #----------------------------------------------------------------------------- 123 | # suite functions 124 | # 125 | 126 | oneTimeSetUp() 127 | { 128 | # load shlib 129 | . ./shlib_base.inc 130 | } 131 | 132 | # load and run shUnit2 133 | . ${HOME}/lib/sh/shunit2 134 | }}} 135 | 136 | After a small chunk of time (something like 15min) I had a working regex. The unit test greatly improved my testing rate. Running the eventual unit test produces the following output: 137 | {{{ 138 | $ ./shlib_base_test 139 | # 140 | # Performing tests 141 | # 142 | testRelToAbsPath 143 | 144 | # 145 | # Test report 146 | # 147 | tests passed: 14 148 | tests failed: 0 149 | tests total: 14 150 | success rate: 100% 151 | }}} 152 | 153 | Perfect! It did _exactly_ what I wanted it to do, so I now had a working function that was usable. 154 | 155 | _Based on previous experience, I did not delete the unit test. I figured that if ever the occasion presented itself where my function failed, I would still have the unit test available to work from._ 156 | 157 | = Third Go = 158 | _Feb 2007_ 159 | 160 | == Problem == 161 | The majority of shell scripts that I write are for Linux. There is however the rare occasion where I must write something for Solaris. When I do, I want that all the scripts that I have written be functional under Solaris as well as Linux. I have the added difficulty that I sometimes run on very old Solaris releases (2.5.1 and 2.6), and I want my scripts to function there as well. This presents a problem for the average script writer as they never leave Linux these days, but for me I cope just fine. 162 | 163 | Well, as you can imagine, the above `shlib_relToAbsPath()` function did not work under Solaris. I'm not perfect, and I'd forgotten that the nice little `-r` command-line flag to *sed* was not present on Solaris. Argh! Oh, but wait! Learning from previous pain, I had left my *shlib_base_test* unit test in the same directory as my `shlib_base.inc` library, so I already had a way to begin my debugging. 164 | 165 | == Solution == 166 | To start with, I ran my unit test to see what kind of output I would get. It failed miserably. 167 | 168 | Well, needless to say, I removed the offending `-r` command-line flag from *sed*, and got to work. The process was much easier this time as I already had a working unit test, so all I had to do was tweak my regex until it worked. It didn't take long, maybe 5 minutes, before I had a working test. This time, I tested the regex in both Linux _and_ Solaris, and as such I was confident that I had a working function for both platforms. 169 | 170 | Final `shlib_base.inc` 171 | {{{ 172 | shlib_relToAbsPath() 173 | { 174 | _shlib_path=$1 175 | 176 | # deal with paths that start with / 177 | echo "${_shlib_path}" |grep '^/' >/dev/null 2>&1 178 | if [ $? -ne 0 ]; then 179 | _shlib_pwd=`pwd` 180 | _shlib_path="${_shlib_pwd}/${_shlib_path}" 181 | unset _shlib_pwd 182 | fi 183 | 184 | # clean up the path. if all seds supported true regular expressions, then 185 | # this is what it would be: 186 | # echo "${_shlib_path}" |sed -r 's/[^/]*\/+\.{2}\/*//g;s/\/\.\//\//;s/\/+$//' 187 | echo "${_shlib_path}" |sed 's/[^/]*\/*\.\.\/*//g;s/\/\.\//\//' 188 | 189 | unset _shlib_path 190 | } 191 | }}} 192 | 193 | _The `shlib_base_test` unit test remained unchanged, so it is not re-listed._ 194 | 195 | = Fourth Go = 196 | _*Update:* Oct 2008_ 197 | 198 | Believe it or not, more than a year and a half after I wrote the original document, I found more bugs! I bet you're not surprised. Basically, including multiple parent references caused problems. Here is the latest version of my code. 199 | 200 | `shlib_base.inc` 201 | {{{ 202 | shlib_relToAbsPath() 203 | { 204 | shlib_path_=$1 205 | 206 | # prepend current directory to relative paths 207 | echo "${shlib_path_}" |grep '^/' >/dev/null 2>&1 \ 208 | || shlib_path_="`pwd`/${shlib_path_}" 209 | 210 | # clean up the path. if all seds supported true regular expressions, then 211 | # this is what it would be: 212 | shlib_old_=${shlib_path_} 213 | while true; do 214 | shlib_new_=`echo "${shlib_old_}" |sed 's/[^/]*\/\.\.\/*//g;s/\/\.\//\//'` 215 | [ "${shlib_old_}" = "${shlib_new_}" ] && break 216 | shlib_old_=${shlib_new_} 217 | done 218 | echo "${shlib_new_}" 219 | 220 | unset shlib_path_ shlib_old_ shlib_new_ 221 | } 222 | }}} 223 | 224 | `shlib_base_test` 225 | {{{ 226 | testRelToAbsPath() 227 | { 228 | parent=`dirname ${PWD}` 229 | 230 | # save stdin and redirect it from an in-line file 231 | exec 9<&0 </dev/null || continue 252 | 253 | # test the function 254 | newPath=`shlib_relToAbsPath "${relPath}"` 255 | assertEquals "${relPath}" "${absPath}" "${newPath}" 256 | done 257 | exec 0<&9 9<&- 258 | } 259 | }}} -------------------------------------------------------------------------------- /wiki/.svn/text-base/HOWTO_TestAbsolutePathFn.wiki.svn-base: -------------------------------------------------------------------------------- 1 | #summary Demonstration of testing a simple path to absolute path conversion function. 2 | 3 | 4 | 5 | This example is based upon a real battle I encountered trying to get a particular regular expression to work. I'm not the best when it comes to writing new regexes off the top of my head, and so I end up doing what one might consider a brute-force attack in getting my regexes to work. You might wonder why I don't just learn them, but I must admit that I don't write them often enough for the nuances to stick in my brain. I'm sure others have a better way of doing what you see here (there always is), but I didn't have one at the time. In any case, maybe some of you will sympathize with my battle, and maybe this will give somebody else some ideas for testing their own code. 6 | 7 | = First Go = 8 | _Jan 2007_ 9 | 10 | == Problem == 11 | I once had a tiny shell function I needed to write that took a relative path (e.g. `./bin`) and turned it into the absolute path (e.g. `/home/kward/bin`). 12 | 13 | == Solution == 14 | Here was my first go. I wrapped the function in a simple shell script for easier testing and got the following: 15 | {{{ 16 | #! /bin/sh 17 | 18 | myBase="`basename $0`" 19 | myDir="`dirname $0`" 20 | 21 | relToAbsPath() 22 | { 23 | path=$1 24 | 25 | dir=`dirname "${path}"` 26 | base=`basename "${path}"` 27 | echo "`( cd \"${dir}\" && pwd )`/${base}" 28 | } 29 | 30 | myDir=`relToAbsPath "${myDir}"` 31 | echo "myDir='${myDir}' myBase='${myBase}'" 32 | }}} 33 | 34 | I saved the script as `${HOME}/bin/reltoabs` and called it from my home directory like this: 35 | {{{ 36 | [kward@laptop]~$ ./bin/reltoabs 37 | myDir='/home/kward/bin' myBase='reltoabs' 38 | }}} 39 | 40 | Perfect! It did _exactly_ what I wanted it to do, so I stuck the function in another script and started using it. 41 | 42 | = Second Go = 43 | _Jan 2007_ 44 | 45 | == Problem == 46 | After time, I found a case where my function wasn't doing quite what I wanted. Let's say I had some non-existant relative path `abc/def/ghi` that I wanted to turn into an absolute path. If you noticed, the first version of the function used the *cd* command to change to the *dirname* of the relative directory, and used that information to determine the absolute path. In this case, I had a directory that didn't exist, but I still wanted the function to work. 47 | 48 | Using the same test wrapper script, I changed the `myDir=` line to {{{myDir="`reltoabs 'abc/def/ghi'`"}}} and ran the script just as I did in the first go. Here is what my function gave as output: 49 | {{{ 50 | $ bin/reltoabs.sh 51 | cd: 15: can't cd to abc/def 52 | myDir='/ghi' myBase='reltoabs.sh' 53 | }}} 54 | 55 | As you can see, it didn't work. I spent the next half-hour fighting with various *sed* regexes on the command-line trying to get things to work. Just as I would get something to work for one case, another case wouldn't work. (I had by this time expanded my expected functionality to several different patterns that my function should work properly for, and testing on the command-line was becoming _very_ tedious.) 56 | 57 | After enough time, I decided that I'd better wrap this in some sort of bigger testing script so that I could test the various multiple cases. I thought through it a bit and eventually settled on using shUnit2 as it just made the job very easy. 58 | 59 | == Solution == 60 | Below are two files. The first is a shell script snippit that gets included (a.k.a. "sourced" in shell speak) into the shUnit2 unit test, and the second file is the unit test itself. 61 | 62 | By the time I was to this stage, I had already included the `reltoabs()` function into a more general `shlib_base.inc` library and renamed it to `shlib_relToAbsPath()`, so the source provided looks a bit different than before. You will also notice that I keep a copy of `shunit2` in my HOME directory referenced as `${HOME}/lib/sh/shunit2`. The second file expects this, so if you want to duplicate these results, you will need to fix that. 63 | 64 | `shlib_base.inc` 65 | {{{ 66 | shlib_relToAbsPath() 67 | { 68 | _shlib_path=$1 69 | 70 | # deal with paths that start with / 71 | echo "${_shlib_path}" |grep '^/' >/dev/null 2>&1 72 | if [ $? -ne 0 ]; then 73 | _shlib_pwd=`pwd` 74 | _shlib_path="${_shlib_pwd}/${_shlib_path}" 75 | unset _shlib_pwd 76 | fi 77 | 78 | # clean up the path. 79 | echo "${_shlib_path}" |sed -r 's/[^/]*\/+\.{2}\/*//g;s/\/\.\//\//;s/\/+$//' 80 | 81 | unset _shlib_path 82 | } 83 | }}} 84 | 85 | `shlib_base_test` 86 | {{{ 87 | #! /bin/sh 88 | 89 | #----------------------------------------------------------------------------- 90 | # suite tests 91 | # 92 | 93 | testRelToAbsPath() 94 | { 95 | parent=`dirname ${PWD}` 96 | exec 9<&0 </dev/null 2>&1 && continue 114 | newPath=`shlib_relToAbsPath "${relPath}"` 115 | assertSame \ 116 | "'${relPath}' -> '${newPath}' != '${absPath}'" \ 117 | "${newPath}" "${absPath}" 118 | done 119 | exec 0<&9 9<&- 120 | } 121 | 122 | #----------------------------------------------------------------------------- 123 | # suite functions 124 | # 125 | 126 | oneTimeSetUp() 127 | { 128 | # load shlib 129 | . ./shlib_base.inc 130 | } 131 | 132 | # load and run shUnit2 133 | . ${HOME}/lib/sh/shunit2 134 | }}} 135 | 136 | After a small chunk of time (something like 15min) I had a working regex. The unit test greatly improved my testing rate. Running the eventual unit test produces the following output: 137 | {{{ 138 | $ ./shlib_base_test 139 | # 140 | # Performing tests 141 | # 142 | testRelToAbsPath 143 | 144 | # 145 | # Test report 146 | # 147 | tests passed: 14 148 | tests failed: 0 149 | tests total: 14 150 | success rate: 100% 151 | }}} 152 | 153 | Perfect! It did _exactly_ what I wanted it to do, so I now had a working function that was usable. 154 | 155 | _Based on previous experience, I did not delete the unit test. I figured that if ever the occasion presented itself where my function failed, I would still have the unit test available to work from._ 156 | 157 | = Third Go = 158 | _Feb 2007_ 159 | 160 | == Problem == 161 | The majority of shell scripts that I write are for Linux. There is however the rare occasion where I must write something for Solaris. When I do, I want that all the scripts that I have written be functional under Solaris as well as Linux. I have the added difficulty that I sometimes run on very old Solaris releases (2.5.1 and 2.6), and I want my scripts to function there as well. This presents a problem for the average script writer as they never leave Linux these days, but for me I cope just fine. 162 | 163 | Well, as you can imagine, the above `shlib_relToAbsPath()` function did not work under Solaris. I'm not perfect, and I'd forgotten that the nice little `-r` command-line flag to *sed* was not present on Solaris. Argh! Oh, but wait! Learning from previous pain, I had left my *shlib_base_test* unit test in the same directory as my `shlib_base.inc` library, so I already had a way to begin my debugging. 164 | 165 | == Solution == 166 | To start with, I ran my unit test to see what kind of output I would get. It failed miserably. 167 | 168 | Well, needless to say, I removed the offending `-r` command-line flag from *sed*, and got to work. The process was much easier this time as I already had a working unit test, so all I had to do was tweak my regex until it worked. It didn't take long, maybe 5 minutes, before I had a working test. This time, I tested the regex in both Linux _and_ Solaris, and as such I was confident that I had a working function for both platforms. 169 | 170 | Final `shlib_base.inc` 171 | {{{ 172 | shlib_relToAbsPath() 173 | { 174 | _shlib_path=$1 175 | 176 | # deal with paths that start with / 177 | echo "${_shlib_path}" |grep '^/' >/dev/null 2>&1 178 | if [ $? -ne 0 ]; then 179 | _shlib_pwd=`pwd` 180 | _shlib_path="${_shlib_pwd}/${_shlib_path}" 181 | unset _shlib_pwd 182 | fi 183 | 184 | # clean up the path. if all seds supported true regular expressions, then 185 | # this is what it would be: 186 | # echo "${_shlib_path}" |sed -r 's/[^/]*\/+\.{2}\/*//g;s/\/\.\//\//;s/\/+$//' 187 | echo "${_shlib_path}" |sed 's/[^/]*\/*\.\.\/*//g;s/\/\.\//\//' 188 | 189 | unset _shlib_path 190 | } 191 | }}} 192 | 193 | _The `shlib_base_test` unit test remained unchanged, so it is not re-listed._ 194 | 195 | = Fourth Go = 196 | _*Update:* Oct 2008_ 197 | 198 | Believe it or not, more than a year and a half after I wrote the original document, I found more bugs! I bet you're not surprised. Basically, including multiple parent references caused problems. Here is the latest version of my code. 199 | 200 | `shlib_base.inc` 201 | {{{ 202 | shlib_relToAbsPath() 203 | { 204 | shlib_path_=$1 205 | 206 | # prepend current directory to relative paths 207 | echo "${shlib_path_}" |grep '^/' >/dev/null 2>&1 \ 208 | || shlib_path_="`pwd`/${shlib_path_}" 209 | 210 | # clean up the path. if all seds supported true regular expressions, then 211 | # this is what it would be: 212 | shlib_old_=${shlib_path_} 213 | while true; do 214 | shlib_new_=`echo "${shlib_old_}" |sed 's/[^/]*\/\.\.\/*//g;s/\/\.\//\//'` 215 | [ "${shlib_old_}" = "${shlib_new_}" ] && break 216 | shlib_old_=${shlib_new_} 217 | done 218 | echo "${shlib_new_}" 219 | 220 | unset shlib_path_ shlib_old_ shlib_new_ 221 | } 222 | }}} 223 | 224 | `shlib_base_test` 225 | {{{ 226 | testRelToAbsPath() 227 | { 228 | parent=`dirname ${PWD}` 229 | 230 | # save stdin and redirect it from an in-line file 231 | exec 9<&0 </dev/null || continue 252 | 253 | # test the function 254 | newPath=`shlib_relToAbsPath "${relPath}"` 255 | assertEquals "${relPath}" "${absPath}" "${newPath}" 256 | done 257 | exec 0<&9 9<&- 258 | } 259 | }}} -------------------------------------------------------------------------------- /doc/README.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | shUnit2 2.1.x README 8 | 304 | 305 | 306 |
307 |

shUnit2 2.1.x README

308 | 309 |
310 |

code.google.com

311 |

This project is stored on code.google.com as http://code.google.com/p/shunit2/. 312 | All releases as of 2.1.4 and full source are available there. Documentation is 313 | included as part of the source and each release. Source code is stored in 314 | Subversion and can be accessed using the following information.

315 |

Browse the code in a web browser:

316 | 320 |

Check out the code locally

321 |
322 | $ svn checkout http://shunit2.googlecode.com/svn/trunk/ shflags-read-only
323 | 
324 |
325 |
326 |

SourceForge

327 |

DEPRECATED

328 |

This project is stored on SourceForge as http://sf.net/projects/shunit2. The 329 | source code is stored in Subversion and can be accessed using the following 330 | information.

331 |

Check out the code locally

332 |
333 | $ svn co https://shunit2.svn.sourceforge.net/svnroot/shunit2/trunk/source/2.1 shunit2
334 | 
335 |

Browse the code in a web browser:

336 | 340 |
341 |
342 |

Making a release

343 |

For these steps, it is assumed we are working with release 2.0.0.

344 |

Steps:

345 |
    346 |
  • write release notes
  • 347 |
  • update version
  • 348 |
  • finish changelog
  • 349 |
  • check all the code in
  • 350 |
  • tag the release
  • 351 |
  • export the release
  • 352 |
  • create tarball
  • 353 |
  • md5sum the tarball and sign with gpg
  • 354 |
  • update website
  • 355 |
  • post to SourceForge and Freshmeat
  • 356 |
357 |
358 |

Write Release Notes

359 |

This should be pretty self explanatory. Use one of the release notes from a 360 | previous release as an example.

361 |

The versions of the various platforms and shells are included when the 362 | master unit test script is run, or when bin/gen_test_results.sh is 363 | used. To determine the versions of the installed shells by hand, use the 364 | lib/versions script.

365 |

Alternatively, do the following:

366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 |
ShellOSNotes
bash $ bash --version
dashLinux$ dpkg -l |grep dash
ksh $ ksh --version 390 | -or- 391 | $ echo 'echo $KSH_VERSION' |ksh
Cygwinsee pdksh
Solaris$ strings /usr/bin/ksh |grep 'Version'
pdksh $ strings /bin/pdksh |grep 'PD KSH'
Cygwinlook in the downloaded Cygwin directory
shSolarisnot possible
zsh $ zsh --version
416 |
417 |
418 |

Update Version

419 |

Edit src/shell/shunit2 and change the version number in the comment, as well 420 | as in the SHUNIT_VERSION variable.

421 |
422 |
423 |

Finish Documentation

424 |

Make sure that any remaining changes get put into the CHANGES-X.X.txt file.

425 |

Finish writing the RELEASE_NOTES-X.X.X.txt. If necessary, run it 426 | through the fmt command to make it pretty (hopefully it is already).

427 |
428 | $ fmt -w 80 RELEASE_NOTES-2.0.0.txt >RELEASE_NOTES-2.0.0.txt.new
429 | $ mv RELEASE_NOTES-2.0.0.txt.new RELEASE_NOTES-2.0.0.txt
430 | 
431 |

We want to have an up-to-date version of the documentation in the release, so 432 | we'd better build it.

433 |
434 | $ pwd
435 | .../shunit2/source/2.1
436 | $ cd doc
437 | $ RST2HTML_OPTS='--stylesheet-path=rst2html.css'
438 | $ rst2html ${RST2HTML_OPTS} shunit2.txt >shunit2.html
439 | $ rst2html ${RST2HTML_OPTS} README.txt >README.html
440 | 
441 |
442 |
443 |

Check In All the Code

444 |

This step is pretty self-explanatory

445 |
446 | $ pwd
447 | .../shunit2/source/2.0
448 | $ svn ci -m "finalizing release"
449 | 
450 |
451 |
452 |

Tag the Release

453 |
454 | $ pwd
455 | .../shunit2/source
456 | $ ls
457 | 2.0  2.1
458 | $ svn cp -m "Release 2.0.0" 2.0 https://shunit2.googlecode.com/svn/tags/source/2.0.0
459 | 
460 |
461 |
462 |

Export the Release

463 |
464 | $ pwd
465 | .../shunit2/builds
466 | $ svn export https://shunit2.googlecode.com/svn/tags/source/2.0.0 shunit2-2.0.0
467 | 
468 |
469 |
470 |

Create Tarball

471 |
472 | $ tar cfz ../releases/shunit2-2.0.0.tgz shunit2-2.0.0
473 | 
474 |
475 |
476 |

Sign the Tarball with gpg

477 |
478 | $ cd ../releases
479 | $ gpg --default-key kate.ward@forestent.com --detach-sign shunit2-2.0.0.tgz
480 | 
481 |
482 |
483 |

Update Website

484 |

Again, pretty self-explanatory. Make sure to copy the GPG signature file. Once 485 | that is done, make sure to tag the website so we can go back in time if needed.

486 |
487 | $ pwd
488 | .../shunit2
489 | $ ls
490 | source  website
491 | $ svn cp -m "Release 2.0.0" \
492 | website https://shunit2.googlecode.com/svn/tags/website/20060916
493 | 
494 |

Now, update the website. It too is held in Subversion, so ssh into the web 495 | server and use svn up to grab the latest version.

496 |
497 |
498 |

Post to code.google.com and Freshmeat

499 | 503 |
504 |
505 | 538 |
539 | 540 | 541 | -------------------------------------------------------------------------------- /doc/LGPL-2.1: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | 504 | 505 | --------------------------------------------------------------------------------