mirror of
https://github.com/fsquillace/junest.git
synced 2026-07-20 01:45:32 +00:00
Add tests for util.sh #12
This commit is contained in:
parent
8982cb5a24
commit
3a51433f0b
2 changed files with 66 additions and 1 deletions
|
|
@ -17,7 +17,9 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
echoerr() { echo "$@" 1>&2; }
|
||||
function echoerr(){
|
||||
echo "$@" 1>&2
|
||||
}
|
||||
function die(){
|
||||
# $@: msg (mandatory) - str: Message to print
|
||||
error $@
|
||||
|
|
|
|||
63
tests/util.sh
Normal file
63
tests/util.sh
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
source "$(dirname $0)/../lib/util.sh"
|
||||
|
||||
function is_equal(){
|
||||
[ "$1" == "$2" ] || return 1 && return 0
|
||||
}
|
||||
|
||||
function test_echoerr(){
|
||||
local actual=$(echoerr "Test" 2>&1)
|
||||
is_equal "$actual" "Test" || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
function test_error(){
|
||||
local actual=$(error "Test" 2>&1)
|
||||
local expected=$(echo -e "\033[1;31mTest\033[0m")
|
||||
is_equal "$actual" "$expected" || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
function test_warn(){
|
||||
local actual=$(warn "Test" 2>&1)
|
||||
local expected=$(echo -e "\033[1;33mTest\033[0m")
|
||||
is_equal "$actual" "$expected" || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
function test_info(){
|
||||
local actual=$(info "Test")
|
||||
local expected=$(echo -e "\033[1;37mTest\033[0m")
|
||||
is_equal "$actual" "$expected" || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
function test_die(){
|
||||
local actual=$(die "Test" 2>&1)
|
||||
local expected=$(echo -e "\033[1;31mTest\033[0m")
|
||||
is_equal "$actual" "$expected" || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
function test_ask(){
|
||||
echo "Y" | ask "Test" &> /dev/null
|
||||
is_equal $? 0 || return 1
|
||||
echo "y" | ask "Test" &> /dev/null
|
||||
is_equal $? 0 || return 1
|
||||
echo "N" | ask "Test" &> /dev/null
|
||||
is_equal $? 1 || return 1
|
||||
echo "n" | ask "Test" &> /dev/null
|
||||
is_equal $? 1 || return 1
|
||||
echo -e "\n" | ask "Test" &> /dev/null
|
||||
is_equal $? 0 || return 1
|
||||
echo -e "\n" | ask "Test" "N" &> /dev/null
|
||||
is_equal $? 1 || return 1
|
||||
echo -e "asdf\n\n" | ask "Test" "N" &> /dev/null
|
||||
is_equal $? 1 || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
for func in $(declare -F | grep test_ | awk '{print $3}' | xargs)
|
||||
do
|
||||
$func && echo -e "${func}...\033[1;32mOK\033[0m" || echo -e "${func}...\033[1;31mFAIL\033[0m"
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue