Last active
December 19, 2017 20:54
-
-
Save jb55/8db763fdae9e24c9d6c769c12f2c698b to your computer and use it in GitHub Desktop.
Simple functional testing with bash
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
1..4 | |
ok 1 - scalar division | |
ok 2 - scalar multiplication | |
not ok 3 - multiply 1 BTC to the smallest unit | |
# | |
# got '0 msat', expected '1 msat' | |
# | |
ok 4 - lots of msats |
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
#!/usr/bin/env bash | |
n=1 | |
c=$(wc -l < tests.csv) | |
fail=0 | |
printf "1..%d\n" "$c" | |
while IFS=, read -r description args input expected | |
do | |
output=$(../bcalc $args <<<"$input") | |
if [ "$description" == "" ] || [ "$output" != "$expected" ]; then | |
printf "not ok %d - %s\n" "$n" "$description" | |
printf "#\n# got '%s', expected '%s'\n#\n" "$output" "$expected" | |
fail=1 | |
else | |
printf "ok %d - %s\n" "$n" "$description" | |
fi | |
n=$((n + 1)) | |
done < tests.csv | |
exit $fail |
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
scalar division | --btc -p | 1 BTC / 10 | 0.1 BTC | |
---|---|---|---|---|
scalar multiplication | --btc | 10 * 1 BTC | 10 | |
multiply 1 BTC to the smallest unit | -pm | 1 BTC * 0.00000000001 | 1 msat | |
lots of msats | -B | 1 msat * 100000000000 | 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made this for https://github.com/jb55/bcalc