shUnit2 is a xUnit based unit test framework for Bourne based shell scripts.
Questions tagged [shunit2]
9 questions
35
votes
3 answers
Using Travis CI for testing on UNIX shell scripts
Background:
I have been using Travis CI for my PHP projects and I really like how they give you a link to a picture that shows the status of the current build of your project.
I am currently making a lot of tools using UNIX shell scripting and would…

Dodzi Dzakuma
- 1,406
- 2
- 21
- 39
3
votes
1 answer
Unit testing bash scripts that redirect file output in shUnit2
I am using shUnit2 to do unit testing in Bash shell scripts.
I have code like this:
cat > /etc/somefile <

Alex Harvey
- 14,494
- 5
- 61
- 97
3
votes
1 answer
Travis-CI and Shell scripts
I use shunit2 to perform some unit tests on a shell script.
To be able to access the script's functions I source it
. script_file.sh --source-only
And in the script I have everything encapsulated in a function but for
if [ "${1}" !=…

Matteo
- 14,696
- 9
- 68
- 106
3
votes
2 answers
Test a "exit process command" in bash script by using shUnit2
According to a trick from this question is-there-a-way-to-write-a-bash-function-which-aborts-the-whole-execution...
My example code (example.sh):
trap "exit 0" TERM
top_pid=$$
evalInput(){
cmd=$1
if [[ $cmd =~ ^\ *exit\ *$ ]]; then
…

fronthem
- 4,011
- 8
- 34
- 55
1
vote
1 answer
Regex-enabled Linux Find Command Not Returning
Being someone who is new to bash scripting, I decided to try and unit test my current project from the start. Currently I have a problem with a single line of code. with it I'm trying to search the directory output_json for the files that match a…

Leviathan_the_Great
- 429
- 1
- 5
- 14
1
vote
2 answers
Stubbing file tests in shUnit2
I am using shUnit2 to do unit testing in Bash shell scripts.
I have code like this:
if [ ! -x /usr/local/rvm/bin/rvm ]; then
...
fi
etc
I want to write unit tests to test this code, but to do that I need to stub out the behaviour of Bash file…

Alex Harvey
- 14,494
- 5
- 61
- 97
1
vote
1 answer
Unit testing a bash script calling mount partition
I have a bash script that calls linux mount.
I want to unit test that script. I'm currently using shunit2.
One thing that I tried was to create a file mount and tried to use this one to respond 0 or -1 or +1 depending on what I wanted to test.
It…

vianna77
- 495
- 1
- 7
- 17
1
vote
3 answers
(foo; echo $?) echoing empty string for functions that return >0 w/ set -e
I'm trying to unit test some bash scripts. One of my functions returns 1 as a false value, which I can use in if tests like
foo() {
return 0
}
if foo; then
echo "Passed"
fi
This is really handy for writing clean code.
However when trying to…

Michael Allen
- 5,712
- 3
- 38
- 63
0
votes
1 answer
Command `builtin` used before `[` commands in all if statements
I see this throughout shunit2, which aims for maximum portability across old Bourne-style shell scripts (see source here):
# Determine if `builtin` command exists.
__SHUNIT_BUILTIN='builtin'
# shellcheck disable=2039
if ! ("${__SHUNIT_BUILTIN}" echo…

adam.hendry
- 4,458
- 5
- 24
- 51