diff options
author | Ori Bernstein <ori@eigenstate.org> | 2014-05-27 17:40:25 -0400 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2015-08-24 22:10:06 -0700 |
commit | a3087100fa88b5d6a420d20d6fa5808d63696170 (patch) | |
tree | eeb13c579e2fcbe73ea10c7700ca8b01be6a9ffa | |
parent | 62a0866a13cb0e7d0f982b1681be85ae1040f8c1 (diff) | |
download | mc-a3087100fa88b5d6a420d20d6fa5808d63696170.tar.gz |
Add test.
It's broken for anything but zero length messages.
-rw-r--r-- | libcryptohash/test/data/md5-test-expected | 1 | ||||
-rw-r--r-- | libcryptohash/test/md5-test.myr | 28 | ||||
-rwxr-xr-x | libcryptohash/test/runtest.sh | 124 | ||||
-rw-r--r-- | libcryptohash/test/tests | 23 |
4 files changed, 176 insertions, 0 deletions
diff --git a/libcryptohash/test/data/md5-test-expected b/libcryptohash/test/data/md5-test-expected new file mode 100644 index 0000000..df9edc4 --- /dev/null +++ b/libcryptohash/test/data/md5-test-expected @@ -0,0 +1 @@ +d41d8cd98f00b204e9800998ecf8427e diff --git a/libcryptohash/test/md5-test.myr b/libcryptohash/test/md5-test.myr new file mode 100644 index 0000000..88fb630 --- /dev/null +++ b/libcryptohash/test/md5-test.myr @@ -0,0 +1,28 @@ +use std +use cryptohash + +const main = { + /* zero hash */ + /* + print(cryptohash.md5("")) + */ + /* arbitrary text */ + print(cryptohash.md5("hello")) + /* + /* 64 byte block */ + print(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) + /* tail spanning */ + print(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")) + */ +} + +const print = {b + for x in b + if (x <= 0xf) + std.put("0%xb", x) + else + std.put("%xb", x) + ;; + ;; + std.put("\n") +} diff --git a/libcryptohash/test/runtest.sh b/libcryptohash/test/runtest.sh new file mode 100755 index 0000000..95f548f --- /dev/null +++ b/libcryptohash/test/runtest.sh @@ -0,0 +1,124 @@ +#!/bin/bash +NFAILURES=0 +NPASSES=0 + +function build { + rm -f $1 $1.o $1.s $1.use + myrbuild $FLAGS -b $1 $1.myr $EXTRA_SRC +} + +function pass { + PASSED="$PASSED $1" + NPASSED=$[$NPASSED + 1] +} + +function fail { + echo "FAIL: $1" + FAILED="$FAILED $1" + NFAILED=$[$NFAILED + 1] +} + +function expectstatus { + ./$1 $3 + if [ $? -eq $2 ]; then + pass $1 + return + else + fail $1 + fi +} + +function expectprint { + if [ "`./$1 $3`" != "$2" ]; then + fail $1 + else + pass $1 + fi +} + + +function expectcompare { + if [ x"" != x"$TMPDIR" ]; then + t=$TMPDIR/myrtest-$1-$RANDOM + else + t=/tmp/myrtest-$1-$RANDOM + fi + ./$1 $3 > $t + if cmp $t data/$1-expected; then + pass $1 + else + fail $1 + fi + rm -f $t +} + +function expectfcompare { + ./$1 $3 + if cmp data/$1-expected $2; then + pass $1 + else + fail $1 + fi +} + +function shouldskip { + if [ -z $ARGS ]; then + return 1 + fi + + for i in $ARGS; do + if [ $i = $1 ]; then + return 1 + fi + done + return 0 +} + + +# Should build and run +function B { + if shouldskip $1; then + return + fi + + test="$1"; shift + type="$1"; shift + res="$1"; shift + if [ $# > 0 ]; then + args="$1"; shift + fi + build $test + case $type in + "E") expectstatus "$test" "$res" "$input";; + "P") expectprint "$test" "$res" "$input";; + "C") expectcompare "$test" "$res" "$input";; + "F") expectfcompare "$test" "$res" "$args";; + esac +} + +# Should fail +function F { + if shouldskip $1; then + return + fi + (build $1) > /dev/null + if [ $? -eq '1' ]; then + pass $1 + else + fail $1 + fi +} + +# Should generate a usefile +function U { + return +} + +source tests + +echo "PASSED ($NPASSED): $PASSED" +if [ -z "$NFAILED" ]; then + echo "SUCCESS" +else + echo "FAILURES ($NFAILED): $FAILED" +fi diff --git a/libcryptohash/test/tests b/libcryptohash/test/tests new file mode 100644 index 0000000..7e4d0ea --- /dev/null +++ b/libcryptohash/test/tests @@ -0,0 +1,23 @@ +FLAGS=-I../ +mkdir -p tmpout +# Format: +# [B|F] testname [E|P] result +# [B|F]: Compiler outcome. +# B: Expect that this test will build. +# F: Expect that this test will not build. +# testname: Test case +# The test that will run. We will try to +# compile 'testname.myr' to 'testname', +# and then execute it, verifying the result +# [E|P|C]: Result type +# E tells us that the result is an exit status +# P tells us that the result is on stdout, +# and should be compared to the value on the +# line +# C tells us that the result is on stdout, +# and should be compared to the contents of +# the file passed on the line. +# result: Result value +# What we compare with. This should be self- +# evident. +B md5-test C |