Revision: 1172
Author:
fafo...@gmail.com
Date: Sun Jan 25 21:46:09 2015 UTC
Log: Using now bash to test IO
https://code.google.com/p/teyjus/source/detail?r=1172
Added:
/branches/ocaml-builtins/source/test/io_tests/README
/branches/ocaml-builtins/source/test/io_tests/close_in/close_in_2.sh
/branches/ocaml-builtins/source/test/io_tests/close_in/close_in_3.sh
/branches/ocaml-builtins/source/test/io_tests/issue60/issue60.sh
/branches/ocaml-builtins/source/test/io_tests/issue60/test.tex
/branches/ocaml-builtins/source/test/io_tests/open_in/open_in_1.sh
/branches/ocaml-builtins/source/test/io_tests/open_in/open_in_2.sh
/branches/ocaml-builtins/source/test/io_tests/open_in/open_in_3.sh
/branches/ocaml-builtins/source/test/io_tests/open_in/open_in_4.sh
/branches/ocaml-builtins/source/test/io_tests/read
/branches/ocaml-builtins/source/test/io_tests/read/read.mod
/branches/ocaml-builtins/source/test/io_tests/read/read.sh
/branches/ocaml-builtins/source/test/io_tests/read/read.sig
/branches/ocaml-builtins/source/test/io_tests/run_all.sh
Deleted:
/branches/ocaml-builtins/source/test/io_tests/close_in/close_in.t
/branches/ocaml-builtins/source/test/io_tests/issue60/another.t
Modified:
/branches/ocaml-builtins/source/test/io_tests/OMakefile
/branches/ocaml-builtins/source/test/io_tests/issue60/another.mod
/branches/ocaml-builtins/source/test/io_tests/issue60/another.sig
/branches/ocaml-builtins/source/test/io_tests/open_in/open_in.mod
/branches/ocaml-builtins/source/test/io_tests/open_in/open_in.sig
/branches/ocaml-builtins/source/test/io_tests/open_in/open_in.t
Replaced:
/branches/ocaml-builtins/source/test/io_tests/close_in/close_in.mod
/branches/ocaml-builtins/source/test/io_tests/close_in/close_in.sig
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/README Sun Jan 25
21:46:09 2015 UTC
@@ -0,0 +1,4 @@
+Perl's Test::More was a bit hard to test stderr thus switched to bash.
+
+There are however some issues: in every directory there must
+be a .mod/.sig file even if this not required.
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/close_in/close_in_2.sh
Sun Jan 25 21:46:09 2015 UTC
@@ -0,0 +1,5 @@
+TESTNAME=`basename $0`
+
+EXPECTED="Error: close_in: Attempting to close an input stream that is
already closed."
+QUERY="open_in \"bar\" X, close_in X, close_in X."
+gives_error_toplevel "$QUERY" "$EXPECTED" "$TESTNAME"
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/close_in/close_in_3.sh
Sun Jan 25 21:46:09 2015 UTC
@@ -0,0 +1,5 @@
+TESTNAME=`basename $0`
+
+EXPECTED="Error: close_in: Expected stream, found unbound variable."
+QUERY="close_in Unbound."
+gives_error_toplevel "$QUERY" "$EXPECTED" "$TESTNAME"
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/issue60/issue60.sh Sun
Jan 25 21:46:09 2015 UTC
@@ -0,0 +1,9 @@
+# Notice that this test for issue 60 is not the same as when we test for
+# closing two times the same file in the close_in test folder since
+# the issue happened when the closing instruction was in file, not at
toplevel.
+
+TESTNAME=`basename $0`
+QUERY="test."
+FILE="another"
+EXPECTED="Error: close_in: Attempting to close an input stream that is
already closed."
+gives_error_file "$QUERY" "$EXPECTED" "$TESTNAME" "$FILE"
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/open_in/open_in_1.sh Sun
Jan 25 21:46:09 2015 UTC
@@ -0,0 +1,5 @@
+TESTNAME=`basename $0`
+
+EXPECTED="X = <stream -- \"bar\">"
+QUERY="open_in \"bar\" X."
+gives_result "$QUERY" "$EXPECTED" "$TESTNAME"
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/open_in/open_in_2.sh Sun
Jan 25 21:46:09 2015 UTC
@@ -0,0 +1,6 @@
+TESTNAME=`basename $0`
+
+EXPECTED="Error: open_in: Cannot open stream from \`foo'."
+# foo does not exist
+QUERY="open_in \"foo\" X."
+gives_error_toplevel "$QUERY" "$EXPECTED" "$TESTNAME"
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/open_in/open_in_3.sh Sun
Jan 25 21:46:09 2015 UTC
@@ -0,0 +1,6 @@
+TESTNAME=`basename $0`
+
+EXPECTED="Error: open_in: The term to be bound is not a variable: <stream
-- \"bar\">"
+# This fails since in the second call, X is already bound
+QUERY="open_in \"bar\" X, open_in \"bar\" X."
+gives_error_toplevel "$QUERY" "$EXPECTED" "$TESTNAME"
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/open_in/open_in_4.sh Sun
Jan 25 21:46:09 2015 UTC
@@ -0,0 +1,5 @@
+TESTNAME=`basename $0`
+
+EXPECTED="Error: open_in: Expected filename, found unbound variable."
+QUERY="open_in Unbound X."
+gives_error_toplevel "$QUERY" "$EXPECTED" "$TESTNAME"
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/read/read.mod Sun Jan 25
21:46:09 2015 UTC
@@ -0,0 +1,1 @@
+module read.
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/read/read.sh Sun Jan 25
21:46:09 2015 UTC
@@ -0,0 +1,5 @@
+TESTNAME=`basename $0`
+INPUT="3."
+QUERY="read X, Y is X + 1."
+EXPECTED="Y = 4"
+gives_result_stdin "$INPUT" "$QUERY" "$EXPECTED" "$TESTNAME"
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/read/read.sig Sun Jan 25
21:46:09 2015 UTC
@@ -0,0 +1,1 @@
+sig read.
=======================================
--- /dev/null
+++ /branches/ocaml-builtins/source/test/io_tests/run_all.sh Sun Jan 25
21:46:09 2015 UTC
@@ -0,0 +1,86 @@
+SH=bash
+export TJSIM=../../../tjsim
+
+
+# Allow to test inputs given from stdin
+function gives_result_stdin {
+ # $1 : input from stdin
+ # $2 : query
+ # $3 : expected result
+ # $4 : name of the test
+ RES=`echo "$1" | "$TJSIM" --solve "$2" | sed -n '5 p'`
+ if [ "$RES" = "$3" ]; then
+ echo "$4" "success"
+ exit 0
+ else
+ RES=`echo "$1" | "$TJSIM" --solve "$2"`
+ echo "$4 failure (the result $3 was expected but got $RES"
+ echo ""
+ exit -1
+ fi
+}
+
+function gives_result {
+ # $1 : query
+ # $2 : expected result
+ # $3 : name of the test
+ RES=`"$TJSIM" --batch --solve "$1" | sed -n '3 p'`
+ if [ "$RES" = "$2" ]; then
+ echo "$3" "success"
+ exit 0
+ else
+ RES=`"$TJSIM" --batch --solve "$1"`
+ echo "$3 failure (the result $2 was expected but got: $RES"
+ echo ""
+ exit -1
+ fi
+}
+
+
+function gives_error_file {
+ # $1 : query
+ # $2 : expected error
+ # $3 : name of the test
+ # $4 : name of the test
+ RES=`"$TJSIM" "$4" --batch --solve "$1" 2>&1 > /dev/null`
+ if [ "$RES" = "$2" ]; then
+ echo "$3" "success"
+ exit 0
+ else
+ echo "$3 failure (the error $2 was expected but got: $RES"
+ echo ""
+ exit -1
+ fi
+}
+
+function gives_error_toplevel {
+ # $1 : query
+ # $2 : expected error
+ # $3 : name of the test
+ RES=`"$TJSIM" --batch --solve "$1" 2>&1 > /dev/null`
+ if [ "$RES" = "$2" ]; then
+ echo "$3" "success"
+ exit 0
+ else
+ echo "$3 failure (the error $2 was expected but got: $RES"
+ echo ""
+ exit -1
+ fi
+}
+
+export -f gives_result_stdin
+export -f gives_result
+export -f gives_error_file
+export -f gives_error_toplevel
+
+
+# We want to run all tests
+for dir in $(ls); do
+ if [ -d $dir ]; then
+ cd $dir
+ for test in $(ls *.sh); do
+ $SH $test
+ done
+ cd ..
+ fi
+done
=======================================
--- /branches/ocaml-builtins/source/test/io_tests/close_in/close_in.t Fri
Jan 16 23:17:15 2015 UTC
+++ /dev/null
@@ -1,49 +0,0 @@
-use lib '../lib';
-use strict;
-use Test::More tests => 3;
-
-my $TJSIM = "../../tjsim";
-my $PATH = "-p close_in/";
-my $MODULE = "close_in";
-my $code;
-my $ans;
-
-############################################
-############################################
-$code = <<'CODE';
-test1 X.
-CODE
-$ans = <<'ANS';
-
-The answer substitution:
-X = <stream -- "open_in/bar">
-
-ANS
-same_answers( `$TJSIM -b $PATH --solve "$code" $MODULE\n`, $ans,"open_in");
-
-############################################
-# In the following test: we should test that we have the following on
stderr:
-#Error: close_in: Attempting to close an input stream that is already
closed.
-############################################
-$code = <<'CODE';
-test2 X.
-CODE
-$ans = <<'ANS';
-
-The answer substitution:
-ANS
-same_answers( `$TJSIM -b $PATH --solve "$code" $MODULE\n`, $ans,"open_in");
-
-############################################
-# In the following test: we should test that we have the following on
stderr:
-#Error: close_in: Expected stream, found unbound variable.
-############################################
-$code = <<'CODE';
-test3.
-CODE
-$ans = <<'ANS';
-
-The answer substitution:
-ANS
-same_answers( `$TJSIM -b $PATH --solve "$code" $MODULE\n`, $ans,"open_in");
-
=======================================
--- /branches/ocaml-builtins/source/test/io_tests/issue60/another.t Fri Jan
16 23:31:18 2015 UTC
+++ /dev/null
@@ -1,21 +0,0 @@
-use lib '../lib';
-use strict;
-use Test::More tests => 1;
-
-my $TJSIM = "../../tjsim";
-my $PATH = "-p issue60/";
-my $MODULE = "another";
-my $code;
-my $ans;
-
-############################################
-############################################
-$code = <<'CODE';
-test X.
-CODE
-$ans = <<'ANS';
-
-The answer substitution:
-
-ANS
-same_answers( `$TJSIM -b $PATH --solve "$code" $MODULE\n`, $ans,"another");
=======================================
--- /branches/ocaml-builtins/source/test/io_tests/OMakefile Fri Jan 16
17:31:53 2015 UTC
+++ /branches/ocaml-builtins/source/test/io_tests/OMakefile Sun Jan 25
21:46:09 2015 UTC
@@ -2,7 +2,7 @@
.PHONY: io-test
io-test: $(TJSIM)
- perl harness
+ bash run_all.sh
.SUBDIRS: $(SUBDIRS)
# The default main file is the name of the test directory
=======================================
--- /branches/ocaml-builtins/source/test/io_tests/issue60/another.mod Fri
Jan 16 23:31:18 2015 UTC
+++ /branches/ocaml-builtins/source/test/io_tests/issue60/another.mod Sun
Jan 25 21:46:09 2015 UTC
@@ -1,3 +1,3 @@
module another.
-test In :- open_in "test.tex" In, close_in In, close_in
+test:- open_in "test.tex" In, close_in In, close_in
In.
=======================================
--- /branches/ocaml-builtins/source/test/io_tests/issue60/another.sig Fri
Jan 16 23:31:18 2015 UTC
+++ /branches/ocaml-builtins/source/test/io_tests/issue60/another.sig Sun
Jan 25 21:46:09 2015 UTC
@@ -1,2 +1,2 @@
sig another.
-type test in_stream -> o.
+type test o.
=======================================
--- /branches/ocaml-builtins/source/test/io_tests/open_in/open_in.mod Fri
Jan 16 23:17:15 2015 UTC
+++ /branches/ocaml-builtins/source/test/io_tests/open_in/open_in.mod Sun
Jan 25 21:46:09 2015 UTC
@@ -1,6 +1,1 @@
module open_in.
-
-test1 X :- open_in "open_in/foo" X.
-test2 X :- open_in "open_in/bar" X.
-test3 X :- open_in "open_in/bar" X ; open_in "open_in/bar" X.
-test4 X :- open_in Unbound X.
=======================================
--- /branches/ocaml-builtins/source/test/io_tests/open_in/open_in.sig Fri
Jan 16 23:17:15 2015 UTC
+++ /branches/ocaml-builtins/source/test/io_tests/open_in/open_in.sig Sun
Jan 25 21:46:09 2015 UTC
@@ -1,6 +1,1 @@
sig open_in.
-
-type test1 in_stream -> o.
-type test2 in_stream -> o.
-type test3 in_stream -> o.
-type test4 in_stream -> o.
=======================================
--- /branches/ocaml-builtins/source/test/io_tests/open_in/open_in.t Fri Jan
16 23:17:15 2015 UTC
+++ /branches/ocaml-builtins/source/test/io_tests/open_in/open_in.t Sun Jan
25 21:46:09 2015 UTC
@@ -8,32 +8,6 @@
my $code;
my $ans;
-############################################
-# In the following test: we should test that we have the following on
stderr:
-# Error: open_in: Cannot open stream from `open_in/foo'.
-############################################
-$code = <<'CODE';
-test1 X.
-CODE
-$ans = <<'ANS';
-
-The answer substitution:
-ANS
-same_answers( `$TJSIM -b $PATH --solve "$code" $MODULE\n`, $ans,"open_in");
-
-############################################
-############################################
-$code = <<'CODE';
-test2 X.
-CODE
-$ans = <<'ANS';
-
-The answer substitution:
-X = <stream -- "open_in/bar">
-
-ANS
-same_answers( `$TJSIM -b $PATH --solve "$code" $MODULE\n`, $ans,"open_in");
-
############################################
############################################
$code = <<'CODE';
=======================================
--- /branches/ocaml-builtins/source/test/io_tests/close_in/close_in.mod Fri
Jan 16 23:17:15 2015 UTC
+++ /branches/ocaml-builtins/source/test/io_tests/close_in/close_in.mod Sun
Jan 25 21:46:09 2015 UTC
@@ -1,8 +1,2 @@
module close_in.
-% Opens and closes a file which exists
-test1 X :- open_in "open_in/bar" X , close_in X.
-% Try to close a file which is already close
-test2 X :- open_in "open_in/bar" X , close_in X, close_in X.
-% Try to close an unbound variable
-test3 :- close_in Unbound.
=======================================
--- /branches/ocaml-builtins/source/test/io_tests/close_in/close_in.sig Fri
Jan 16 23:17:15 2015 UTC
+++ /branches/ocaml-builtins/source/test/io_tests/close_in/close_in.sig Sun
Jan 25 21:46:09 2015 UTC
@@ -1,5 +1,1 @@
sig close_in.
-
-type test1 in_stream -> o.
-type test2 in_stream -> o.
-type test3 o.