lpr/test.sh

137 lines
2.2 KiB
Bash
Raw Normal View History

2012-08-17 06:01:01 -04:00
#!/bin/sh
assert()
{
local name=$1
local sub=$2
if [[ -z "$sub" ]]
then
return 1
fi
local OK="\\033[1;32m"
local NOK="\\033[1;31m"
local RAZ="\\033[0;39m"
2012-08-17 06:23:36 -04:00
cols=15
2012-08-17 06:01:01 -04:00
if [[ "$PS1" == *$sub* ]]
then
2012-08-17 06:23:36 -04:00
printf "\e${OK}%-${cols}s %-${cols}s\n${RAZ}" "$name" "OK"
2012-08-17 06:01:01 -04:00
else
2012-08-17 06:23:36 -04:00
printf "\e${NOK}%-${cols}s %-${cols}s\n${RAZ}" "$name" "$sub"
2012-08-17 06:01:01 -04:00
fi
}
#####################
# REDEFINE COMMANDS #
#####################
command()
{
echo "fake command $@" 1>&2
echo "/bin/fake"
}
uname()
{
echo "fake uname $@" 1>&2
echo Linux
}
nproc()
{
2012-08-17 06:23:36 -04:00
echo "fake nproc $@" 1>&2
2012-08-17 06:01:01 -04:00
echo 2
}
# battery
acpi()
{
echo "fake acpi $@" 1>&2
echo 'Battery 0: Discharging, 55%, 01:39:34 remaining'
}
git()
{
echo "fake git $@" 1>&2
case $1 in
"rev-parse" )
echo ".git";;
"branch" )
echo "* fake_test";;
"diff" )
2012-08-17 09:00:23 -04:00
echo "2 1 fake_file"
return 1;;
2012-08-17 06:01:01 -04:00
"status" )
echo "# Untracked";;
"rev-list" )
2012-08-17 09:00:23 -04:00
echo 111;;
2012-08-17 06:01:01 -04:00
esac
}
# global variables
export http_proxy="fake"
##########################
# Call the liquid prompt #
##########################
# As if we were in an interactive shell
export PS1="fake prompt \$"
# load functions
source ./liquidprompt
# Force liquid prompt function redefinition
_lp_cpu_load()
{
echo "fake _lp_cpu_load $@" 1>&2
2012-08-17 06:23:36 -04:00
echo "0.64"
2012-08-17 06:01:01 -04:00
}
2012-08-17 06:29:13 -04:00
################
# ADHOC CONFIG #
################
export LP_BATTERY_THRESHOLD=60
export LP_LOAD_THRESHOLD=1
export LP_MARK_PROXY="proxy"
export LP_MARK_BATTERY="BATT"
export LP_MARK_LOAD="LOAD"
export LP_MARK_UNTRACKED="untracked"
export LP_MARK_GIT="gitmark"
2012-08-17 06:01:01 -04:00
# Force erroneous command
fake_error
# Force set prompt
_lp_set_prompt
#########
# TESTS #
#########
echo -e "$PS1"
2012-08-17 06:23:36 -04:00
assert "Battery Mark" BATT
assert "Battery Level" 55%
assert "Load Mark" LOAD
assert "Load Level" 32%
2012-08-17 06:01:01 -04:00
assert User "[\\\u"
assert Perms :
assert Path $(pwd | sed -e "s|$HOME|~|")
assert Proxy proxy
assert Error 127
2012-08-17 06:23:36 -04:00
# echo GIT
assert "GIT Branch" fake_test
2012-08-17 09:00:23 -04:00
assert "GIT Changes" "+2/-1"
2012-08-17 06:23:36 -04:00
assert "GIT Commits" 111
assert "GIT Untrack" untracked
assert "GIT Mark" gitmark