Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 125 lines (106 sloc) 3.75 KB
#!/bin/bash -e
#
# Simple test of some of bashism's functionality, hopefully this will be extended one day.
# For debug and color output example, use "-dc"
# ~trevorj 041312
#
#BASHISM_MINIMAL=0
#declare -x -r BASHISM_COLORS=0
BASHISM_OUTPUT=output/output
. ./bashism
header() { echo -e "\n>>" Begin "$*"; }
footer() { echo -e "<<" End "$*\n"; }
subheader() { echo -e "\n===>>" Begin "$*"; }
subfooter() { echo -e "===<<" End "$*\n"; }
block_normal() {
e "About to start local hooks"
$b.hooks.run init
e "Hello, this is an info message"
warn "Hello, this is a warn message"
warning "Hello, this is a warning message"
error "This is an error message"
debug "This is a debug message"
echo -n "test"
echo "A word \"test\" is prefixing this message without a newline."
echo "ifconfig start"
ifconfig
echo "ifconfig end"
e "test info test test test"
e "this is a test"
error "Testing error"
e "Testing spark"
spark 1 50 33 4 1 2 4 5 99 4 65 15 19 78 44
e "Testing VARP"
e "- Setting testkey=testval"
$b.pset "testkey=testval"
e "- Getting testkey via \$ret"
$b.pget 'testkey'
[[ "${ret[0]}" == "testval" ]] || death "Got bad ret=${ret[0]}"
e "-- ret=${ret[0]}"
e "- Getting testkey via var=key"
$b.pget 'testget=testkey'
[[ "$testget" == "testval" ]] || death "Got bad testget=$testget"
e "-- testget=$testget"
e "Testing getkwargs"
function getkwargs_example() {
echo eval "$($b.getkwargs "$@")"
eval "$($b.getkwargs "$@")"
# Print structure of args and kwargs
declare -p args kwargs
# Positional
echo "First positional argument is \"${args[0]}\""
echo "Second positional argument is \"${args[1]}\""
# Keyword
local k= v=
for k in "${!kwargs[@]}"; do
v="${kwargs[$k]}"
echo "Keyword argument \"$k\"=\"$v\""
done
}
getkwargs_example omg=yes=yes2 arg0 arg1 munch=faces=whatsits
getkwargs_example "omg=yes=yes2 arg0" "arg1 munch=faces=whatsits"
getkwargs_example "omg=yes=yes2 arg0" "arg1 munch=faces=whatsits"
getkwargs_example "omg=yes=yes2 arg0" "arg1 munch=faces=whatsits"
e "Testing template"
what="The skipping %fox% went down the %horrid% road."
e "- Before: \"$what\""
e "- Template: fox=\"cat\" horrid=\"creepy\" none=\"should_not_appear\""
eval "$($b.template "$what" fox="cat" horrid="creepy" none="should_not_appear")"
e "- After: \"$ret\""
death "To this block (or true)" || true
}
block_output() {
for OUTPUT in output/{output,logger{,:syslog}}; do
subheader "$OUTPUT"
(
unset "${!__BASHISM@}" "BASHISM_OUTPUT"
#[[ "${OUTPUT#*:}" != "syslog" ]] || BASHISM_SYSLOG=0
BASHISM_OUTPUT="${OUTPUT#*:}"
. ./bashism
e "This was written using $BASHISM_OUTPUT"
debug "Debug with $BASHISM_OUTPUT"
error "Error with $BASHISM_OUTPUT"
echo "This is an echo using $BASHISM_OUTPUT"
subheader "$OUTPUT recursive"
(
BASHISM_OUTPUT="output/logger"
. ./bashism
e "WTF"
e "This was written using output/logger"
debug "Debug with output/logger"
warn "Warn with $BASHISM_OUTPUT"
warning "Warning with $BASHISM_OUTPUT"
error "Error with output/logger"
echo "This is an echo using output/logger"
)
subfooter "$OUTPUT recursive"
)
subfooter "$OUTPUT"
done
}
for i in block_normal block_output; do
for j in header '' footer; do
[[ -z "$j" ]] || j+=" "
$j"$i"
done
done