Last active
October 11, 2017 11:36
-
-
Save misebox/3eb0777593b501455303514301c8bac6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
success=true | |
# Echo the line number and result of the last command. | |
verify () { | |
local result=$? | |
local frame=($(caller 0)) | |
local lno=${frame[0]} | |
echo -n "$lno: " | |
if [ $result -eq 0 ]; then | |
echo OK | |
else | |
echo NG | |
success=false | |
fi | |
} | |
# Dummy functions | |
dummy1 () { | |
echo $* | |
} | |
dummy2 () { | |
echo $1 $2 | |
} | |
# Compare the results of two commands passed the same arguments | |
testargs () { | |
local frame=($(caller 0)) | |
local lno=${frame[0]} | |
echo -n "$lno: " | |
# replace dummy1 and dummy2 | |
if [ "`dummy1 $*`" = "`dummy2 $*`" ]; then | |
echo OK | |
return 0 | |
else | |
echo NG | |
return 1 | |
fi | |
} | |
# Test cases | |
echo "========== Verify result ==========" | |
[ $(( 1 + 1 )) -eq 2 ]; verify | |
[ "string" = "string" ]; verify | |
[ "aaa | |
bbb | |
ccc" = "aaa | |
bbb | |
ccc" ]; verify | |
[ "aaa" = "bbb" ]; verify # NG | |
echo "========== Comparison ==========" | |
testargs aaa | |
testargs aaa bbb | |
testargs aaa bbb ccc # NG | |
$success && echo "Done all tests" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment