├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── VERSION ├── install.sh ├── screenshots ├── shunt.png ├── shunt_plain.png ├── shunt_quiet.png └── shunt_verbose.png ├── scripts └── update_shml.sh ├── shunt.sh └── test ├── failures.sh ├── testOne.sh └── testTwo.sh /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | script: 3 | - make test 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## CHANGELOG 2 | 3 | ### 0.2.3 4 | 5 | * Fixing multi-file run errors for issues #11. 6 | 7 | ### 0.2.2 8 | 9 | * Update assert|refute_grep error messaging. 10 | 11 | ### 0.2.1 12 | 13 | * Adding line break after Running message (Issue: #12) 14 | * Tweaking assert|refute_grep (Issue: #13) 15 | * Fixing refute error message. 16 | 17 | ### 0.2.0 18 | 19 | * Renaming to 'shunt'. 20 | * Adding CLIstyle for coloring and icons. 21 | * Depricating legacy method of sourcing shunt. 22 | * Adding error trapping and output. Disabled via quite flag. 23 | * Adding verbose test output via verbose flag. 24 | * Fixing issues with before and after show errors when not present. See Issue #5. 25 | 26 | ### 0.1.1 27 | 28 | * Obfuscating internal functions and variables. 29 | * Adding installer (see README). 30 | * Adding argument support for CLIunit.sh (see: '--help') 31 | 32 | ### 0.1.0 33 | 34 | * Supporting ./CLIunit.sh ./test.sh method of running. See Issue #2. 35 | 36 | ### 0.0.3 37 | 38 | * Adding before and after handling. See README for details. 39 | 40 | ### 0.0.2 41 | 42 | * Adding color (thanks [jdorfman](https://github.com/jdorfman)). 43 | * Fixing critical issues with some refute tests. 44 | * Adding `example.sh` for more examples. It also doubles as a sort of test suite. 45 | 46 | ### 0.0.1 47 | 48 | * Initial migration from gist. 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Joshua Mervine 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: .PHONY 2 | # Should be failures to display/test failures. 3 | -@./shunt.sh ./test/testOne.sh ./test/testTwo.sh 4 | -@./shunt.sh --plain ./test/testOne.sh ./test/testTwo.sh 5 | -@./shunt.sh --verbose ./test/testOne.sh ./test/testTwo.sh 6 | 7 | shml: 8 | bash ./scripts/update_shml.sh 9 | 10 | .PHONY: 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [shunt](https://github.com/odb/shunt) 2 | 3 | ##### Simple Shell Testing Pseudo-Framework 4 | 5 | [![shunt](https://raw.githubusercontent.com/odb/shunt/master/screenshots/shunt.png)](https://raw.githubusercontent.com/odb/shunt/master/screenshots/shunt.png) 6 | 7 | ### What!? Why? 8 | 9 | For a recent project, I wanted a very simple way to run some simple tests against my script output. 10 | I know there are a number of these kinds of things out there, but most of the ones I looked at were more complex then I wanted. 11 | To start, I created a basic shell script to test my scripts, but as I began to add to it, and want more from it, I decided to take 12 | a few minutes and build a pseudo-framework out of it. 13 | 14 | I call it a "pseudo-framework" because it's really more of a helper, which gives you a handfull of assertions to run against 15 | bash commands. Well, that and it doesn't really have a name. 16 | 17 | ### How? 18 | 19 | ##### Install 20 | 21 | Note, in shunt `latest` means latest stable version. 22 | 23 | curl -L https://raw.githubusercontent.com/odb/shunt/master/install.sh | bash 24 | # installs latest to ~/.bin/shunt 25 | 26 | curl -L https://raw.githubusercontent.com/odb/shunt/master/install.sh | bash -s master 27 | # installs master to ~/.bin/shunt 28 | 29 | curl -L https://raw.githubusercontent.com/odb/shunt/master/install.sh | bash -s global 30 | # installs latest to /usr/local/bin/shunt 31 | 32 | curl -L https://raw.githubusercontent.com/odb/shunt/master/install.sh | bash -s master local 33 | # installs master to ./shunt.sh 34 | 35 | ##### Basic Usage 36 | 37 | A basic test file looks like this: 38 | 39 | # file: tests.sh 40 | 41 | function run_tests { 42 | #################################################### 43 | # Tests go here. 44 | #################################################### 45 | COMMAND="/path/to/your/command" 46 | assert_grep "$COMMAND" "Usage" \ 47 | "deplay usage without params" 48 | assert_grep "$COMMAND --help" "Usage" \ 49 | "deplay usage with help" 50 | assert_grep "$COMMAND --arg2 foobar" "Usage" \ 51 | "deplay usage without required arg" 52 | refute_grep "$COMMAND --arg1 foobar" "Usage" \ 53 | "work with required arg" 54 | #################################################### 55 | } 56 | 57 | Run like this: 58 | 59 | $ ./shunt.sh ./tests.sh 60 | 61 | Usage: 62 | ``` bash 63 | Usage: ./shunt.sh 64 | 65 | Options: 66 | --plain Disable colors and icons. 67 | --quiet Do not print error messages. 68 | --verbose Display success messages. 69 | --version Display version information. 70 | --help Display this message. 71 | ``` 72 | 73 | > See `test/testOne.sh` for more examples. 74 | 75 | ##### Before / After Hooks 76 | 77 | In addition to assertion, shunt also supports before and after hooks. Simply define a `before` or `after` function. 78 | 79 | function before { 80 | ./some_setup_script.sh 81 | echo "Running before shunt assertions. 82 | } 83 | 84 | function after { 85 | ./some_cleanup_script.sh 86 | echo "Running after shunt assertions. 87 | } 88 | 89 | ##### Assertions 90 | 91 | Here's a full list of assertions at the time of this writing: 92 | 93 | * `assert "CMD" "FAIL MESSAGE"` 94 | * `refute "CMD" "FAIL MESSAGE"` 95 | * `assert_equal "FIRST" "SECOND" "FAIL MESSAGE"` 96 | * `refute_equal "FIRST" "SECOND" "FAIL MESSAGE"` 97 | * `assert_numeq "FIRST" "SECOND" "FAIL MESSAGE"` 98 | * `refute_numeq "FIRST" "SECOND" "FAIL MESSAGE"` 99 | * `assert_grep "CMD" "GREP" "FAIL MESSAGE"` 100 | * `refute_grep "CMD" "GREP" "FAIL MESSAGE"` 101 | * `assert_file "FILE" "FAIL MESSAGE"` 102 | * `refute_file "FILE" "FAIL MESSAGE"` 103 | * `assert_dir "DIR" "FAIL MESSAGE"` 104 | * `refute_dir "DIR" "FAIL MESSAGE"` 105 | 106 | 107 | ### Development 108 | 109 | * To run tests use: `make test` 110 | 111 | ### Additional Screenshots 112 | 113 | [![shunt --verbose](https://raw.githubusercontent.com/odb/shunt/master/screenshots/shunt_verbose.png)](https://raw.githubusercontent.com/odb/shunt/master/screenshots/shunt_verbose.png) 114 | 115 | [![shunt --quiet](https://raw.githubusercontent.com/odb/shunt/master/screenshots/shunt_quiet.png)](https://raw.githubusercontent.com/odb/shunt/master/screenshots/shunt_quiet.png) 116 | 117 | [![shunt --plain](https://raw.githubusercontent.com/odb/shunt/master/screenshots/shunt_plain.png)](https://raw.githubusercontent.com/odb/shunt/master/screenshots/shunt_plain.png) 118 | 119 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.2.5 2 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eET 4 | 5 | # Options 6 | ## 7 | __usage() 8 | { 9 | cat << EOF 10 | Usage: $0 [BRANCH] [INSTALL METHOD] 11 | 12 | INSTALL METHOD: 13 | global Install globally. 14 | user Install to user. (default) 15 | local Install to current directory. 16 | 17 | OPTIONS: 18 | --help Show this message. 19 | 20 | EOF 21 | exit 0 22 | } 23 | 24 | _sudo="" 25 | if test "$*"; then 26 | options="$*" 27 | if echo "$options" | grep "\-\-help" > /dev/null; then 28 | __usage 29 | fi 30 | if echo "$options" | grep "global" > /dev/null; then 31 | install_method=global 32 | options="$(echo "$options" | sed 's/global//')" 33 | install_path="/usr/local/bin" 34 | if (( UID != 0 )); then 35 | _sudo="sudo " 36 | fi 37 | elif echo "$options" | grep "local" > /dev/null; then 38 | install_method=local 39 | install_path="." 40 | options="$(echo "$options" | sed 's/local//')" 41 | elif echo "$options" | grep "user" > /dev/null; then 42 | install_method=user 43 | install_path="$HOME/.bin" 44 | options="$(echo "$options" | sed 's/user//')" 45 | fi 46 | fi 47 | 48 | # setup 49 | ## 50 | options=$( echo $options ) 51 | test "$options" && version=$options 52 | test "$version" || version="latest" 53 | source="https://raw.githubusercontent.com/odb/shunt/master/shunt.sh" 54 | target="shunt.sh" 55 | execln="shunt" 56 | 57 | # display banner 58 | ## 59 | echo "Installing shunt" 60 | echo "------------------" 61 | echo " " 62 | 63 | # check superuser if method not specified 64 | ## 65 | if ! test "$install_method"; then 66 | install_method="user" 67 | install_path="$HOME/.bin" 68 | if (( UID == 0 )); then 69 | install_method="global" 70 | install_path="/usr/local/bin" 71 | fi 72 | fi 73 | 74 | # ensure install directory 75 | ## 76 | test -d $install_path || $_sudo mkdir -p $install_path 77 | 78 | # fetch latest 79 | ## 80 | cd $install_path 81 | if test -f $target; then 82 | echo "> Backing up previous version:" 83 | $_sudo mv -v $target $target.bak 84 | echo " " 85 | fi 86 | echo "> Downloading $source:" 87 | $_sudo curl -O $source 88 | $_sudo chmod 755 $install_path/$target 89 | 90 | # create executable symlink 91 | ## 92 | if [ "$install_method" != "local" ]; then 93 | test -L $execln || $_sudo ln -s $target $execln 94 | echo "> Install path: $install_path/$execln" 95 | else 96 | echo "> Install path: $install_path/$target" 97 | fi 98 | 99 | # update path 100 | ## 101 | 102 | export_string="\nexport PATH=$install_path:\$PATH # Add shunt to PATH" 103 | report=false 104 | if [ "$install_method" = "user" ]; then 105 | if test -f $HOME/.zshrc; then 106 | if ! grep "$install_path" $HOME/.zshrc 2>&1 > /dev/null; then 107 | echo -e "$export_string" >> $HOME/.zshrc 108 | fi 109 | elif test -f $HOME/.profile; then 110 | if ! grep "$install_path" $HOME/.profile 2>&1 > /dev/null; then 111 | echo -e "$export_string" >> $HOME/.profile 112 | report=true 113 | fi 114 | elif test -f $HOME/.bashrc; then 115 | if ! grep "$install_path" $HOME/.bashrc 2>&1 > /dev/null; then 116 | echo -e "$export_string" >> $HOME/.bashrc 117 | report=true 118 | fi 119 | else 120 | echo " " 121 | echo "WARNING: Please add $install_path to your PATH." 122 | fi 123 | else 124 | report=false 125 | fi 126 | 127 | if $report; then 128 | echo " " 129 | echo "NOTE: Please log out and log back in to ensure that 'shunt' is available to your shell." 130 | fi 131 | 132 | echo " " 133 | echo "DONE" 134 | # vim: ft=sh: 135 | -------------------------------------------------------------------------------- /screenshots/shunt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/odb/shunt/fb4587e2367f451c2c4893fb2f46b259b191daa3/screenshots/shunt.png -------------------------------------------------------------------------------- /screenshots/shunt_plain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/odb/shunt/fb4587e2367f451c2c4893fb2f46b259b191daa3/screenshots/shunt_plain.png -------------------------------------------------------------------------------- /screenshots/shunt_quiet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/odb/shunt/fb4587e2367f451c2c4893fb2f46b259b191daa3/screenshots/shunt_quiet.png -------------------------------------------------------------------------------- /screenshots/shunt_verbose.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/odb/shunt/fb4587e2367f451c2c4893fb2f46b259b191daa3/screenshots/shunt_verbose.png -------------------------------------------------------------------------------- /scripts/update_shml.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Grabs the latest version of shml.sh (github.com/odb/shml) and imports it 3 | # in to shunt.sh 4 | 5 | set -xue 6 | curl -L https://raw.githubusercontent.com/odb/shml/master/shml.sh > shml.sh 7 | awk '/SHML:START/,/SHML:END/' shml.sh | grep -v "SHML:\(START\|END\)" > tmp 8 | mv tmp shml.sh 9 | awk 'FNR==NR{ _[++d]=$0;next}; /SHML:START/{ print; for(i=1;i<=d;i++){ print _[i] }; f=1;next; }; /SHML:END/{f=0}!f' shml.sh shunt.sh > tmp 10 | mv tmp shunt.sh 11 | chmod 755 shunt.sh 12 | rm shml.sh 13 | 14 | # vim: ft=sh: 15 | -------------------------------------------------------------------------------- /shunt.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ################################################################################ 3 | # 4 | # Simple Shell Testing Psudo-Framework 5 | # ---------------------------------- 6 | # 7 | # Source: https://github.com/odb/shunt 8 | # Author: Joshua Mervine (@mervinej) 9 | # 10 | # ---------------------------------- 11 | # Contributors: 12 | # ---------------------------------- 13 | # - Justin Dorfman (@jdorfman) 14 | # 15 | ################################################################################ 16 | 17 | SHUNT_VERSION="0.3.1" 18 | 19 | if echo "$*" | grep "\-\-version" > /dev/null; then 20 | echo "$0 version $SHUNT_VERSION" 21 | exit 0 22 | fi 23 | 24 | __usage() { 25 | cat << EOF 26 | Usage: $0 27 | 28 | Options: 29 | --plain Disable colors and icons. 30 | --quiet Do not print error messages. 31 | --verbose Display success messages. 32 | --version Display version information. 33 | --help Display this message. 34 | 35 | EOF 36 | exit 0 37 | } 38 | 39 | options="$@" 40 | 41 | # Usage - TODO: iterate of arguments 42 | ## 43 | if echo "$options" | grep "\-h" > /dev/null; then # also matches '--help' 44 | __usage 45 | fi 46 | 47 | # Style 48 | ## 49 | __no_style=false 50 | if echo "$options" | grep "\-\-plain" > /dev/null; then 51 | __no_style=true 52 | options="$(echo "$options" | sed 's/--plain//')" 53 | fi 54 | 55 | # quiet 56 | ## 57 | __quiet=false 58 | if echo "$options" | grep "\-\-quiet" > /dev/null; then 59 | __quiet=true 60 | options="$(echo "$options" | sed 's/--quiet//')" 61 | fi 62 | 63 | # Verbose 64 | ## 65 | __verbose=false 66 | if echo "$options" | grep "\-\-verbose" > /dev/null; then 67 | __verbose=true 68 | options="$(echo "$options" | sed 's/--verbose//')" 69 | fi 70 | 71 | # Files 72 | ## 73 | if ! test "$options"; then __usage; fi 74 | 75 | # Before/After function handling 76 | ## 77 | function __ensure_handlers { 78 | _="$( { type before; } 2>&1 )" 79 | if [ "$?" -ne "0" ]; then function before { true; }; fi 80 | _="$( { type after; } 2>&1 )" 81 | if [ "$?" -ne "0" ]; then function after { true; }; fi 82 | } 83 | 84 | # Progress Variables 85 | __total=0; __passed=0; __failed=0; __failures=""; __successes=""; __current=""; __last="" 86 | ################################################################################ 87 | # Assertions 88 | ################################################################################ 89 | function assert { 90 | local cmd=$1 91 | local msg="[assert] $2" 92 | err="$( { $cmd; } 2>&1 )" 93 | process "$?" "$msg" "$cmd" "$err" 94 | unset err # status is unavailable when err is set to local 95 | } 96 | 97 | function refute { 98 | local cmd=$1 99 | local msg="[refute] $2" 100 | _="$( { $cmd; } 2>&1)" 101 | [ "$?" -ne "0" ] 102 | process "$?" "$msg" "$cmd" "exit status is zero" 103 | } 104 | 105 | function assert_equal { 106 | local one=$1 107 | local two=$2 108 | local msg="[assert_equal] $3" 109 | [ "$one" = "$two" ] 110 | process "$?" "$msg" "" "'$one' does not equal '$two'" 111 | } 112 | 113 | function refute_equal { 114 | local one=$1 115 | local two=$2 116 | local msg="[refute_equal] $3" 117 | [ "$one" != "$two" ] 118 | process "$?" "$msg" "" "'$one' equals '$two'" 119 | } 120 | 121 | function assert_numeq { 122 | local one=$1 123 | local two=$2 124 | local msg="[assert_numeq] $3" 125 | [ "$one" -eq "$two" ] 126 | process "$?" "$msg" "" "'$one' does not equal '$two'" 127 | } 128 | 129 | function refute_numeq { 130 | local one=$1 131 | local two=$2 132 | local msg="[refute_numeq] $3" 133 | [ "$one" -ne "$two" ] 134 | process "$?" "$msg" "" "'$one' equals '$two'" 135 | } 136 | 137 | function assert_grep { 138 | local cmd=$1 139 | local inc=$2 140 | local msg="[assert_grep] $3" 141 | out="$( { $cmd; } 2>&1 )" 142 | _="$( { echo "$out" | grep "$inc"; } 2>&1 )" 143 | process "$?" "$msg" "$cmd" "'$out' does not include '$inc'" 144 | unset out 145 | } 146 | 147 | function refute_grep { 148 | local cmd=$1 149 | local inc=$2 150 | local msg="[refute_grep] $3" 151 | out="$( { $cmd; } 2>&1 )" 152 | _="$( { echo "$out" | grep -v "$inc"; } 2>&1 )" 153 | process "$?" "$msg" "$cmd" "'$out' includes '$inc'" 154 | unset out 155 | } 156 | 157 | function assert_file { 158 | local file=$1 159 | local msg="[assert_file] $2" 160 | _="$( { test -f $file; } 2>&1 )" 161 | process "$?" "$msg" "" "file '$file' does not exist" 162 | } 163 | 164 | function refute_file { 165 | local file=$1 166 | local msg="[refute_file] $2" 167 | _="$( { test -f $file; } 2>&1 )" 168 | [ "$?" -ne "0" ] 169 | process "$?" "$msg" "" "file '$file' exists" 170 | } 171 | 172 | function assert_dir { 173 | local dir=$1 174 | local msg="[assert_dir] $2" 175 | _="$( { test -d $dir; } 2>&1 )" 176 | process "$?" "$msg" "" "directory '$dir' does not exist" 177 | } 178 | 179 | function refute_dir { 180 | local dir=$1 181 | local msg="[refute_dir] $2" 182 | _="$( { test -d $dir; } 2>&1 )" 183 | [ "$?" -ne "0" ] 184 | process "$?" "$msg" "" "directory '$dir' exists" 185 | } 186 | 187 | ################################################################################ 188 | # Utils 189 | ################################################################################ 190 | __red="" 191 | __green="" 192 | __yellow="" 193 | __blue="" 194 | __reset="" 195 | __check="." 196 | __x="x" 197 | 198 | if ! $__no_style; then 199 | __red="\033[31m" 200 | __green="\033[32m" 201 | __yellow="\033[33m" 202 | __blue="\033[34m" 203 | __reset="\033[39m" 204 | __check="${__green}\xE2\x9C\x93${__reset}" 205 | __x="${__red}\xE2\x9C\x98${__reset}" 206 | fi 207 | 208 | function process { 209 | local status=$1 210 | local msg=$2 211 | local cmd=$3 212 | local err=$4 213 | if [ "$status" -eq "0" ]; then 214 | __do_pass "$msg" 215 | else 216 | __do_fail "$msg" "$cmd" "$err" 217 | fi 218 | } 219 | 220 | function __do_pass { 221 | local msg=$1 222 | __total=$(expr $__total + 1) 223 | __passed=$(expr $__passed + 1) 224 | if $__verbose; then 225 | echo -e "$__total. ${__green}$msg passed${__reset}" 226 | else 227 | echo -ne $__check 228 | fi 229 | } 230 | 231 | function __do_fail { 232 | local msg=$1 233 | local cmd=$2 234 | local err=$3 235 | __total=$(expr $__total + 1) 236 | __failed=$(expr $__failed + 1) 237 | 238 | if $__verbose; then 239 | echo -e "$__total. ${__red}$msg failed${__reset}" 240 | else 241 | echo -ne $__x 242 | fi 243 | 244 | if [ "$__last" != "$__current" ]; then 245 | __failures+="\n$__current\n" 246 | __last=$__current 247 | fi 248 | 249 | __failures+="${__red}$__total. $msg${__reset}\n" 250 | if test "$err" && ! $__quiet; then 251 | if test "$cmd"; then 252 | __failures+="${__yellow} '$cmd' failed with:\n${__reset}" 253 | fi 254 | __failures+="${__yellow} $err\n\n${__reset}" 255 | fi 256 | } 257 | 258 | function __failures { 259 | if [ "$__failed" -ne 0 ] && ! $__quiet; then 260 | echo -e "\n\nFailures:\n--------------------------------------------------------------------------------\n$__failures" 261 | else 262 | echo " " 263 | fi 264 | } 265 | 266 | function __finish { 267 | __failures 268 | if $__verbose; then echo "--------------------------------------------------------------------------------"; fi 269 | if $__quiet; then echo " "; fi 270 | echo -e "${__yellow}\nTotal: $(expr $__passed + $__failed) ${__green}Passed: $__passed ${__red}Failed: $__failed ${__blue}Duration: ${SECONDS} Seconds${__reset}\n" 271 | } 272 | 273 | function __reset { 274 | unset before 275 | unset after 276 | } 277 | 278 | function __shunt { 279 | __ensure_handlers 280 | before 281 | run_tests 282 | after 283 | } 284 | 285 | ################################################################################ 286 | # Make is so. 287 | ################################################################################ 288 | 289 | echo "$(basename -- $0) $@" 290 | if $__verbose; then echo "================================================================================"; fi 291 | echo " " 292 | 293 | # In an edge case, a test changes directory. It needs to be changed 294 | # back after the test. 295 | ####### 296 | here="$(pwd)" 297 | 298 | for __current in $options; do 299 | __reset 300 | source $__current 301 | if $__verbose; then echo -ne "\n$__current\n--------------------------------------------------------------------------------\n"; fi 302 | __shunt 303 | cd $here 304 | done 305 | 306 | __finish 307 | exit $__failed 308 | 309 | # vim: ft=sh: 310 | -------------------------------------------------------------------------------- /test/failures.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function run_tests { 4 | assert "grep foo asdf" "assertion to fail" 5 | refute "grep foo ./foo.sh" "assertion to fail" 6 | 7 | assert_equal "true" "false" "assertion to fail" 8 | refute_equal "true" "true" "assertion to fail" 9 | 10 | assert_numeq "1" "2" "assertion to fail" 11 | refute_numeq "1" "1" "assertion to fail" 12 | 13 | assert_grep "echo foobarbah" "asdf" "assertion to fail" 14 | refute_grep "echo foobarbah" "bar" "assertion to fail" 15 | 16 | assert_file "asdf" "assertion to fail" 17 | refute_file "./CLIunit.sh" "assertion to fail" 18 | 19 | assert_dir "asdf" "assertion to fail" 20 | refute_dir "./test" "assertion to fail" 21 | } 22 | -------------------------------------------------------------------------------- /test/testOne.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Setup 4 | ## 5 | touch /tmp/shunt.file 6 | mkdir -p /tmp/shunt.dir 7 | 8 | # Test Examples 9 | ## 10 | 11 | tmp_file=/tmp/shunt.file 12 | tmp_dir=/tmp/shunt.dir 13 | function before { 14 | touch $tmp_file 15 | mkdir -p $tmp_dir 16 | } 17 | 18 | function after { 19 | echo -e "\n\nIf you see this, after worked." 20 | rm -rf $tmp_file $tmp_dir 21 | } 22 | 23 | function run_tests { 24 | assert "true" "should assert truth" 25 | refute "false" "should refute truth" 26 | 27 | assert_equal "true" "true" "should assert equality" 28 | refute_equal "true" "false" "should refute equality" 29 | 30 | assert_numeq "1111" "1111" "should assert numerical equality" 31 | refute_numeq "1111" "1112" "should refute numerical equality" 32 | 33 | assert_grep "echo 'foo bar'" "foo bar" "should assert via grep" 34 | refute_grep "echo foobar" "notfoobar" "should refute via grep" 35 | 36 | assert_file "/tmp/shunt.file" "should assert file existence" 37 | refute_file "/tmp/shunt.bad" "should refute file existence" 38 | 39 | assert_dir "/tmp/shunt.dir" "should assert directory existence" 40 | refute_dir "/tmp/shunt.bad" "should refute directory existence" 41 | 42 | # test before 43 | sleep 0.5 # showing Duration > 0 44 | assert_file "$tmp_file" "before or assert_file didn't work" 45 | assert "cat missing.file" "should fail, to show failure output" 46 | } 47 | 48 | # vim: ft=sh: 49 | -------------------------------------------------------------------------------- /test/testTwo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Setup 4 | ## 5 | touch /tmp/shunt.file 6 | mkdir -p /tmp/shunt.dir 7 | 8 | # Test Examples 9 | ## 10 | 11 | tmp_file=/tmp/shunt.file 12 | tmp_dir=/tmp/shunt.dir 13 | function before { 14 | touch $tmp_file 15 | mkdir -p $tmp_dir 16 | } 17 | 18 | function run_tests { 19 | 20 | assert "true" "should assert truth" 21 | refute "false" "should refute truth" 22 | 23 | assert_equal "true" "true" "should assert equality" 24 | refute_equal "true" "false" "should refute equality" 25 | 26 | assert_numeq "1111" "1111" "should assert numerical equality" 27 | refute_numeq "1111" "1112" "should refute numerical equality" 28 | 29 | assert_grep "echo foobar" "foobar" "should assert via grep" 30 | refute_grep "echo foobar" "notfoobar" "should refute via grep" 31 | 32 | assert_file "/tmp/shunt.file" "should assert file existence" 33 | refute_file "/tmp/shunt.bad" "should refute file existence" 34 | 35 | assert_dir "/tmp/shunt.dir" "should assert directory existence" 36 | refute_dir "/tmp/shunt.bad" "should refute directory existence" 37 | 38 | # test before 39 | sleep 1 40 | assert_file "$tmp_file" "before or assert_file didn't work" 41 | 42 | assert "cat missing.file" "should fail, to show failure output" 43 | } 44 | 45 | # vim: ft=sh: 46 | --------------------------------------------------------------------------------