shithub: mc

Download patch

ref: ce3eb5eb8ae1d77e50e114ee39213d473a610690
parent: 7c5a1bde6ba49b0b9dbc3980084546efc1a42ae7
author: Ori Bernstein <[email protected]>
date: Tue Dec 17 19:29:53 EST 2013

Add first tests.

--- /dev/null
+++ b/test/Makefile
@@ -1,0 +1,20 @@
+# don't build anything for 'all'
+all: 
+	$(MAKE) -C ..
+
+check:
+	./runtest.sh
+
+.PHONY: %
+%:
+	./runtest.sh $@
+
+.PHONY: clean
+clean:
+	rm -f testmatch.use testmatch.o
+	@for i in `awk '/^[A-Z]/{print $$2}' tests`; do \
+	    echo rm -f $$i; \
+	    rm -f $$i; \
+	done
+
+install:
--- /dev/null
+++ b/test/bio-create.myr
@@ -1,0 +1,13 @@
+use std
+use bio
+
+const main = {
+	var f
+
+	std.mkdir("tmpout", 0o755);
+	match bio.create("tmpout/test-create", bio.Wr, 0o777)
+	| `std.Some bio:	f = bio
+	| `std.None:	std.fatal(1, "Failed to open file\n")
+	;;
+	bio.close(f)
+}
--- /dev/null
+++ b/test/bio-read.myr
@@ -1,0 +1,28 @@
+use std
+use bio
+
+const main = {
+	var f
+	/* Must be bigger than a bio buffer (ie, > 64k) */
+	var buf : byte[64*1024]
+
+	match bio.open("data/datafile", bio.Rd)
+	| `std.Some bio:	f = bio
+	| `std.None:	std.fatal(1, "Unable to open data file")
+	;;
+	
+	/* read a 4 byte chunk */
+	bio.read(f, buf[:4])
+	std.write(1, buf[:4])
+	std.write(1, "\n")
+
+	/* read the next 32 bytes */
+	bio.read(f, buf[:32])
+	std.write(1, buf[:32])
+	std.write(1, "\n")
+
+	/* read a 64k chunk */
+	bio.read(f, buf[:])
+	std.write(1, buf[:])
+	std.write(1, "\n")
+}
--- /dev/null
+++ b/test/data/bio-read-expected
@@ -1,0 +1,3 @@
+0123
+45678901234567890123456789012345
+678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
\ No newline at end of file
--- /dev/null
+++ b/test/runtest.sh
@@ -1,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
--- /dev/null
+++ b/test/tests
@@ -1,0 +1,30 @@
+FLAGS=-I../
+# 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 bio-create    F	tmpout/test-create
+B bio-read	C
+#B bio-write	F	tmpout/test-write
+#B bio-endianwr	F	tmpout/test-endianwr
+#B bio-endianrd	C
+#B bio-unit	C
+#B bio-peek	C
+#B bio-delim	C
+#B bio-fmt	C