1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
[](https://travis-ci.org/progrhyme/shove)
# shove
A test tool for shell scripts with [TAP](https://testanything.org/) outputs.
The name **"shove"** comes from _"shell"_ and
_"[prove](http://perldoc.perl.org/prove.html)"_ of Perl.
### Table of Contents
* [Screenshots](#screenshots)
* [Supported Shells](#supported-shells)
* [Install](#install)
* [Usage](#usage)
* [Options](#options)
* [How to write test codes](#how-to-write-test-codes)
* [Basics](#basics)
* [Grouping](#grouping)
* [Authors](#authors)
* [License](#license)
# Screenshots
Pass:
<div align="center">
<img src="https://raw.githubusercontent.com/progrhyme/shove/resource/image/screenshot-pass_01.png" alt="shove-screenshot-pass_01">
</div>
Fail:
<div align="center">
<img src="https://raw.githubusercontent.com/progrhyme/shove/resource/image/screenshot-fail_01.png" alt="shove-screenshot-fail_01">
</div>
# Supported Shells
- _sh, bash, dash, ksh, zsh_
_ash_ is not tested, but hopefully supposed to work with **shove**.
No plan to support _(t)csh_ or _fish_ because they are not POSIX compatible.
# Install
Just clone this repository or get tarballs from [releases](https://github.com/progrhyme/shove/releases) page.
```
# example snippet to install `shove`
mkdir ~/src
git clone https://github.com/progrhyme/shove.git ~/src/shove
alias shove="$HOME/src/shove/bin/shove"
shove -V
```
You can make a symlink of `bin/shove` in your favorite path;
i.e. `/usr/local/bin/` or `$HOME/bin/` or any path.
Or you can make an alias command like the snippet above.
NOTE:
Do not change the directory structure because `bin/shove` assumes
its libraries exists in `../lib/` directory.
# Usage
```sh
shove TARGETS [OPTIONS]
shove t/foo.t
shove t/foo.t t/bar.t -s /bin/bash -v
shove -r t/ -v
# help
shove -h|--help
# version
shove -V|--version
```
## Options
* `-s|--shell SHELL` : SHELL to execute tests. Default is `$SHELL`.
* `-v|--verbose` : verbose output.
* `-r|--recursive DIRECTORY` : Search test script files with extension `.t`
under the directory
# How to write test codes
Many test functions get hints from
[Test::More](http://perldoc.perl.org/Test/More.html) of Perl.
There are some example test codes in [example](example) directory.
## Basics
```sh
t_diag "Test for your shell scripts" # Log message visible on the test
t_pass # Always Pass
t_fail # Always Fail
t_ok $exp "exp is true" # [ $exp ]
t_ng $exp "exp is false" # [ ! $exp ]
t_present $str "str is present" # [ -n "$str" ]
t_blank $str "str is blank" # [ -z "$str" ]
t_exist $path "path exists" # [ -e "$path" ]
t_file $path "path is file" # [ -f "$path" ]
t_directory $path "path is directory" # [ -d "$path" ]
t_symlink $path "path is symlink" # [ -L "$path" ]
t_is $a $b "a is b" # [ "$a" = "$b" ]
t_isnt $a $b "a isn't b" # [ "$a" != "$b" ]
t_eq $x $y "x == y" # [ $x -eq $y ]
t_ne $x $y "x != y" # [ $x -ne $y ]
t_gt $x $y "x > y" # [ $x -gt $y ]
t_ge $x $y "x >= y" # [ $x -ge $y ]
t_lt $x $y "x < y" # [ $x -lt $y ]
t_le $x $y "x <= y" # [ $x -le $y ]
t_success $cmd "cmd succeeds" # $cmd; [ $? -eq 0 ]
t_error $cmd "cmd fails" # $cmd; [ $? -ne 0 ]
```
## Grouping
This feature works like `subtest` of
[Test::More](http://perldoc.perl.org/Test/More.html).
New special syntax is introduced in v0.8.1:
```sh
t_ok $ok
t::group "level1 group" ({
t_diag "Comment for level1 tests"
t_ok $lv1_ok
t::group "level2 group" ({
t_diag "Comment for level2 tests"
t_ok $lv2_ok
t_is $lv2_a $lv2_b
})
})
```
These codes are the same as following codes:
```sh
t_ok $ok
(
t_substart "level1 group"
t_diag "Comment for level1 tests"
t_ok $lv1_ok
(
t_substart "level2 group"
t_diag "Comment for level2 tests"
t_ok $lv2_ok
t_is $lv2_a $lv2_b
t_subclose
)
t_subend "level2 group"
t_subclose
)
t_subend "level1 group"
```
Tests in group are run in subshell.
So you can run them in different context from main tests context.
If you want test groups A and B not affect to each other, you have to put them in
different groups.
**CAUTION:**
- **The old grouping syntax `T_SUB (( ... ))` will be unsupported in the future
release.**
# Authors
IKEDA Kiyoshi <progrhyme@gmail.com>
# License
The MIT License (MIT)
Copyright (c) 2016-2020 IKEDA Kiyoshi
|