[m-dev.] trivial diff: add tests of exceptions+tabling

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jan 26 16:31:58 AEDT 2000


Estimated hours taken: 0.5

tests/hard_coded/exceptions/Mmakefile:
tests/hard_coded/exceptions/test_memo.m:
tests/hard_coded/exceptions/test_memo.exp:
tests/hard_coded/exceptions/test_loop_check.m:
tests/hard_coded/exceptions/test_loop_check.exp:
	Add some test cases to test the combination of
	`pragma memo' / `pragma loop_check' and exceptions.
	I did not enable them, since currently we do not
	yet pass these tests.

Workspace: /d-drive/home/hg/fjh/ws-hg2/mercury
Index: tests/hard_coded/exceptions/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/exceptions/Mmakefile,v
retrieving revision 1.1
diff -u -d -r1.1 Mmakefile
--- tests/hard_coded/exceptions/Mmakefile	1999/08/31 12:57:19	1.1
+++ tests/hard_coded/exceptions/Mmakefile	2000/01/26 05:26:05
@@ -12,6 +12,10 @@
 include ../../Mmake.common
 
 PROGS = test_exceptions.m test_uncaught_exception.m test_exceptions_func.m
+#
+# XXX the following tests are not enabled because we do not pass them yet:
+#	test_memo.m test_loop_check.m
+#       (those two tests test the combination of tabling and exceptions).
 
 depend: $(PROGS:.m=.depend)
 all: $(PROGS:.m=)
Index: tests/hard_coded/exceptions/test_loop_check.exp
===================================================================
RCS file: test_loop_check.exp
diff -N test_loop_check.exp
--- /dev/null	Wed May  6 06:32:27 1998
+++ test_loop_check.exp	Wed Jan 26 16:22:57 2000
@@ -0,0 +1,54 @@
+--- first time ---
+det_throw: exception(univ("det_throw" : string))
+det_succeed: succeeded("det_succeed")
+semidet_throw: exception(univ("semidet_throw" : string))
+semidet_succeed: succeeded("semidet_succeed")
+semidet_fail: failed
+cc_multi_throw: exception(univ("cc_multi_throw" : string))
+cc_multi_succeed: succeeded("cc_multi_succeed")
+cc_nondet_throw: exception(univ("cc_nondet_throw" : string))
+cc_nondet_succeed: succeeded("cc_nondet_succeed")
+cc_nondet_fail: failed
+multi_throw: exception(univ("multi_throw" : string))
+multi_succeed: succeeded(["multi_succeed 1", "multi_succeed 2"])
+multi_succeed_then_throw: exception(univ("multi_succeed_then_throw 3" : string))
+nondet_throw: exception(univ("nondet_throw" : string))
+nondet_succeed: succeeded(["nondet_succeed 1", "nondet_succeed 2"])
+nondet_fail: succeeded([])
+nondet_succeed_then_throw: exception(univ("nondet_succeed_then_throw 3" : string))
+--- second time ---
+det_throw: exception(univ("det_throw" : string))
+det_succeed: succeeded("det_succeed")
+semidet_throw: exception(univ("semidet_throw" : string))
+semidet_succeed: succeeded("semidet_succeed")
+semidet_fail: failed
+cc_multi_throw: exception(univ("cc_multi_throw" : string))
+cc_multi_succeed: succeeded("cc_multi_succeed")
+cc_nondet_throw: exception(univ("cc_nondet_throw" : string))
+cc_nondet_succeed: succeeded("cc_nondet_succeed")
+cc_nondet_fail: failed
+multi_throw: exception(univ("multi_throw" : string))
+multi_succeed: succeeded(["multi_succeed 1", "multi_succeed 2"])
+multi_succeed_then_throw: exception(univ("multi_succeed_then_throw 3" : string))
+nondet_throw: exception(univ("nondet_throw" : string))
+nondet_succeed: succeeded(["nondet_succeed 1", "nondet_succeed 2"])
+nondet_fail: succeeded([])
+nondet_succeed_then_throw: exception(univ("nondet_succeed_then_throw 3" : string))
+--- third time ---
+det_throw: exception(univ("det_throw" : string))
+det_succeed: succeeded("det_succeed")
+semidet_throw: exception(univ("semidet_throw" : string))
+semidet_succeed: succeeded("semidet_succeed")
+semidet_fail: failed
+cc_multi_throw: exception(univ("cc_multi_throw" : string))
+cc_multi_succeed: succeeded("cc_multi_succeed")
+cc_nondet_throw: exception(univ("cc_nondet_throw" : string))
+cc_nondet_succeed: succeeded("cc_nondet_succeed")
+cc_nondet_fail: failed
+multi_throw: exception(univ("multi_throw" : string))
+multi_succeed: succeeded(["multi_succeed 1", "multi_succeed 2"])
+multi_succeed_then_throw: exception(univ("multi_succeed_then_throw 3" : string))
+nondet_throw: exception(univ("nondet_throw" : string))
+nondet_succeed: succeeded(["nondet_succeed 1", "nondet_succeed 2"])
+nondet_fail: succeeded([])
+nondet_succeed_then_throw: exception(univ("nondet_succeed_then_throw 3" : string))
Index: tests/hard_coded/exceptions/test_loop_check.m
===================================================================
RCS file: test_loop_check.m
diff -N test_loop_check.m
--- /dev/null	Wed May  6 06:32:27 1998
+++ test_loop_check.m	Wed Jan 26 16:21:52 2000
@@ -0,0 +1,166 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 1997-1998 The University of Melbourne.
+% This file may only be copied under the terms of the GNU Library General
+% Public License - see the file COPYING.LIB in the Mercury distribution.
+%---------------------------------------------------------------------------%
+
+% File: test_loop_check.m.
+% Main author: fjh.
+
+% Test cases that combine exception handling and `pragma loop_check'.
+
+%-----------------------------------------------------------------------------%
+
+:- module test_loop_check.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is cc_multi.
+
+:- implementation.
+:- import_module std_util.
+:- import_module exception.
+
+% repeat the test several times, so that we test both
+% construction of the tables and use of the tables.
+main -->
+	print("--- first time ---"), nl,
+	test,
+	print("--- second time ---"), nl,
+	test,
+	print("--- third time ---"), nl,
+	test.
+
+:- pred test(io__state::di, io__state::uo) is cc_multi.
+test --> 
+	{ try(det_throw, DetThrowResult) },
+	print("det_throw: "), print(DetThrowResult), nl,
+	{ try(det_succeed, DetSucceedResult) },
+	print("det_succeed: "), print(DetSucceedResult), nl,
+
+	{ try(semidet_throw, SemidetThrowResult) },
+	print("semidet_throw: "), print(SemidetThrowResult), nl,
+
+	{ try(semidet_succeed, SemidetSucceedResult) },
+	print("semidet_succeed: "), print(SemidetSucceedResult), nl,
+
+	{ try(semidet_fail, SemidetFailResult) },
+	print("semidet_fail: "), print(SemidetFailResult), nl,
+
+	{ try(cc_multi_throw, CCMultiThrowResult) },
+	print("cc_multi_throw: "), print(CCMultiThrowResult), nl,
+	{ try(cc_multi_succeed, CCMultiSucceedResult) },
+	print("cc_multi_succeed: "), print(CCMultiSucceedResult), nl,
+
+	{ try(cc_nondet_throw, CCNondetThrowResult) },
+	print("cc_nondet_throw: "), print(CCNondetThrowResult), nl,
+
+	{ try(cc_nondet_succeed, CCNondetSucceedResult) },
+	print("cc_nondet_succeed: "), print(CCNondetSucceedResult), nl,
+
+	{ try(cc_nondet_fail, CCNondetFailResult) },
+	print("cc_nondet_fail: "), print(CCNondetFailResult), nl,
+
+	{ try((pred(R::out) is det :- solutions(multi_throw, R)),
+		MultiThrowResult) },
+	print("multi_throw: "), print(MultiThrowResult), nl,
+	{ try((pred(R::out) is det :- solutions(multi_succeed, R)),
+		MultiSucceedResult) },
+	print("multi_succeed: "), print(MultiSucceedResult), nl,
+	{ try((pred(R::out) is det :-
+			solutions(multi_succeed_then_throw, R)),
+		MultiSucceedThenThrowResult) },
+	print("multi_succeed_then_throw: "),
+	print(MultiSucceedThenThrowResult), nl,
+
+	{ try((pred(R::out) is det :- solutions(nondet_throw, R)),
+		NondetThrowResult) },
+	print("nondet_throw: "), print(NondetThrowResult), nl,
+	{ try((pred(R::out) is det :- solutions(nondet_succeed, R)),
+		NondetSucceedResult) },
+	print("nondet_succeed: "), print(NondetSucceedResult), nl,
+	{ try((pred(R::out) is det :- solutions(nondet_fail, R)),
+		NondetFailResult) },
+	print("nondet_fail: "), print(NondetFailResult), nl,
+	{ try((pred(R::out) is det :-
+			solutions(nondet_succeed_then_throw, R)),
+		NondetSucceedThenThrowResult) },
+	print("nondet_succeed_then_throw: "),
+	print(NondetSucceedThenThrowResult), nl.
+
+:- pred det_throw(string::out) is det.
+:- pragma loop_check(det_throw/1).
+det_throw(_) :- throw("det_throw").
+
+:- pred semidet_throw(string::out) is semidet.
+:- pragma loop_check(semidet_throw/1).
+semidet_throw(_) :- throw("semidet_throw").
+
+:- pred nondet_throw(string::out) is nondet.
+nondet_throw(_) :- throw("nondet_throw").
+
+:- pred multi_throw(string::out) is multi.
+multi_throw(_) :- throw("multi_throw").
+
+:- pred cc_nondet_throw(string::out) is cc_nondet.
+:- pragma loop_check(cc_nondet_throw/1).
+cc_nondet_throw(_) :- throw("cc_nondet_throw").
+
+:- pred cc_multi_throw(string::out) is cc_multi.
+:- pragma loop_check(cc_multi_throw/1).
+cc_multi_throw(_) :- throw("cc_multi_throw").
+
+
+:- pred det_succeed(string::out) is det.
+:- pragma loop_check(det_succeed/1).
+det_succeed("det_succeed").
+
+:- pred semidet_succeed(string::out) is semidet.
+:- pragma loop_check(semidet_succeed/1).
+semidet_succeed("semidet_succeed").
+
+:- pred nondet_succeed(string::out) is nondet.
+nondet_succeed("nondet_succeed 1").
+nondet_succeed("nondet_succeed 2").
+
+:- pred multi_succeed(string::out) is multi.
+multi_succeed("multi_succeed 1").
+multi_succeed("multi_succeed 2").
+
+:- pred cc_nondet_succeed(string::out) is cc_nondet.
+:- pragma loop_check(cc_nondet_succeed/1).
+cc_nondet_succeed("cc_nondet_succeed").
+cc_nondet_succeed("cc_nondet_succeed 2").
+
+:- pred cc_multi_succeed(string::out) is cc_multi.
+:- pragma loop_check(cc_multi_succeed/1).
+cc_multi_succeed("cc_multi_succeed").
+cc_multi_succeed("cc_multi_succeed 2").
+
+
+:- pred semidet_fail(string::out) is semidet.
+:- pragma loop_check(semidet_fail/1).
+semidet_fail("semidet_fail") :- fail.
+
+:- pred nondet_fail(string::out) is nondet.
+nondet_fail("nondet_fail 1") :- fail.
+nondet_fail("nondet_fail 2") :- fail.
+
+:- pred cc_nondet_fail(string::out) is cc_nondet.
+:- pragma loop_check(cc_nondet_fail/1).
+cc_nondet_fail("cc_nondet_fail 1") :- fail.
+cc_nondet_fail("cc_nondet_fail 2") :- fail.
+
+
+:- pred nondet_succeed_then_throw(string::out) is nondet.
+nondet_succeed_then_throw("nondet_succeed_then_throw 1").
+nondet_succeed_then_throw("nondet_succeed_then_throw 2").
+nondet_succeed_then_throw(_) :- throw("nondet_succeed_then_throw 3").
+nondet_succeed_then_throw("nondet_succeed_then_throw 4").
+
+:- pred multi_succeed_then_throw(string::out) is multi.
+multi_succeed_then_throw("multi_succeed_then_throw 1").
+multi_succeed_then_throw("multi_succeed_then_throw 2").
+multi_succeed_then_throw(_) :- throw("multi_succeed_then_throw 3").
+multi_succeed_then_throw("multi_succeed_then_throw 4").
+
Index: tests/hard_coded/exceptions/test_memo.exp
===================================================================
RCS file: test_memo.exp
diff -N test_memo.exp
--- /dev/null	Wed May  6 06:32:27 1998
+++ test_memo.exp	Wed Jan 26 16:22:48 2000
@@ -0,0 +1,54 @@
+--- first time ---
+det_throw: exception(univ("det_throw" : string))
+det_succeed: succeeded("det_succeed")
+semidet_throw: exception(univ("semidet_throw" : string))
+semidet_succeed: succeeded("semidet_succeed")
+semidet_fail: failed
+cc_multi_throw: exception(univ("cc_multi_throw" : string))
+cc_multi_succeed: succeeded("cc_multi_succeed")
+cc_nondet_throw: exception(univ("cc_nondet_throw" : string))
+cc_nondet_succeed: succeeded("cc_nondet_succeed")
+cc_nondet_fail: failed
+multi_throw: exception(univ("multi_throw" : string))
+multi_succeed: succeeded(["multi_succeed 1", "multi_succeed 2"])
+multi_succeed_then_throw: exception(univ("multi_succeed_then_throw 3" : string))
+nondet_throw: exception(univ("nondet_throw" : string))
+nondet_succeed: succeeded(["nondet_succeed 1", "nondet_succeed 2"])
+nondet_fail: succeeded([])
+nondet_succeed_then_throw: exception(univ("nondet_succeed_then_throw 3" : string))
+--- second time ---
+det_throw: exception(univ("det_throw" : string))
+det_succeed: succeeded("det_succeed")
+semidet_throw: exception(univ("semidet_throw" : string))
+semidet_succeed: succeeded("semidet_succeed")
+semidet_fail: failed
+cc_multi_throw: exception(univ("cc_multi_throw" : string))
+cc_multi_succeed: succeeded("cc_multi_succeed")
+cc_nondet_throw: exception(univ("cc_nondet_throw" : string))
+cc_nondet_succeed: succeeded("cc_nondet_succeed")
+cc_nondet_fail: failed
+multi_throw: exception(univ("multi_throw" : string))
+multi_succeed: succeeded(["multi_succeed 1", "multi_succeed 2"])
+multi_succeed_then_throw: exception(univ("multi_succeed_then_throw 3" : string))
+nondet_throw: exception(univ("nondet_throw" : string))
+nondet_succeed: succeeded(["nondet_succeed 1", "nondet_succeed 2"])
+nondet_fail: succeeded([])
+nondet_succeed_then_throw: exception(univ("nondet_succeed_then_throw 3" : string))
+--- third time ---
+det_throw: exception(univ("det_throw" : string))
+det_succeed: succeeded("det_succeed")
+semidet_throw: exception(univ("semidet_throw" : string))
+semidet_succeed: succeeded("semidet_succeed")
+semidet_fail: failed
+cc_multi_throw: exception(univ("cc_multi_throw" : string))
+cc_multi_succeed: succeeded("cc_multi_succeed")
+cc_nondet_throw: exception(univ("cc_nondet_throw" : string))
+cc_nondet_succeed: succeeded("cc_nondet_succeed")
+cc_nondet_fail: failed
+multi_throw: exception(univ("multi_throw" : string))
+multi_succeed: succeeded(["multi_succeed 1", "multi_succeed 2"])
+multi_succeed_then_throw: exception(univ("multi_succeed_then_throw 3" : string))
+nondet_throw: exception(univ("nondet_throw" : string))
+nondet_succeed: succeeded(["nondet_succeed 1", "nondet_succeed 2"])
+nondet_fail: succeeded([])
+nondet_succeed_then_throw: exception(univ("nondet_succeed_then_throw 3" : string))
Index: tests/hard_coded/exceptions/test_memo.m
===================================================================
RCS file: test_memo.m
diff -N test_memo.m
--- /dev/null	Wed May  6 06:32:27 1998
+++ test_memo.m	Wed Jan 26 16:22:17 2000
@@ -0,0 +1,166 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 1997-1998 The University of Melbourne.
+% This file may only be copied under the terms of the GNU Library General
+% Public License - see the file COPYING.LIB in the Mercury distribution.
+%---------------------------------------------------------------------------%
+
+% File: test_memo.m.
+% Main author: fjh.
+
+% Test cases that combine exception handling and `pragma memo'.
+
+%-----------------------------------------------------------------------------%
+
+:- module test_memo.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is cc_multi.
+
+:- implementation.
+:- import_module std_util.
+:- import_module exception.
+
+% repeat the test several times, so that we test both
+% construction of the tables and use of the tables.
+main -->
+        print("--- first time ---"), nl,
+        test,
+        print("--- second time ---"), nl,
+        test,
+        print("--- third time ---"), nl,
+        test.
+
+:- pred test(io__state::di, io__state::uo) is cc_multi.
+test --> 
+	{ try(det_throw, DetThrowResult) },
+	print("det_throw: "), print(DetThrowResult), nl,
+	{ try(det_succeed, DetSucceedResult) },
+	print("det_succeed: "), print(DetSucceedResult), nl,
+
+	{ try(semidet_throw, SemidetThrowResult) },
+	print("semidet_throw: "), print(SemidetThrowResult), nl,
+
+	{ try(semidet_succeed, SemidetSucceedResult) },
+	print("semidet_succeed: "), print(SemidetSucceedResult), nl,
+
+	{ try(semidet_fail, SemidetFailResult) },
+	print("semidet_fail: "), print(SemidetFailResult), nl,
+
+	{ try(cc_multi_throw, CCMultiThrowResult) },
+	print("cc_multi_throw: "), print(CCMultiThrowResult), nl,
+	{ try(cc_multi_succeed, CCMultiSucceedResult) },
+	print("cc_multi_succeed: "), print(CCMultiSucceedResult), nl,
+
+	{ try(cc_nondet_throw, CCNondetThrowResult) },
+	print("cc_nondet_throw: "), print(CCNondetThrowResult), nl,
+
+	{ try(cc_nondet_succeed, CCNondetSucceedResult) },
+	print("cc_nondet_succeed: "), print(CCNondetSucceedResult), nl,
+
+	{ try(cc_nondet_fail, CCNondetFailResult) },
+	print("cc_nondet_fail: "), print(CCNondetFailResult), nl,
+
+	{ try((pred(R::out) is det :- solutions(multi_throw, R)),
+		MultiThrowResult) },
+	print("multi_throw: "), print(MultiThrowResult), nl,
+	{ try((pred(R::out) is det :- solutions(multi_succeed, R)),
+		MultiSucceedResult) },
+	print("multi_succeed: "), print(MultiSucceedResult), nl,
+	{ try((pred(R::out) is det :-
+			solutions(multi_succeed_then_throw, R)),
+		MultiSucceedThenThrowResult) },
+	print("multi_succeed_then_throw: "),
+	print(MultiSucceedThenThrowResult), nl,
+
+	{ try((pred(R::out) is det :- solutions(nondet_throw, R)),
+		NondetThrowResult) },
+	print("nondet_throw: "), print(NondetThrowResult), nl,
+	{ try((pred(R::out) is det :- solutions(nondet_succeed, R)),
+		NondetSucceedResult) },
+	print("nondet_succeed: "), print(NondetSucceedResult), nl,
+	{ try((pred(R::out) is det :- solutions(nondet_fail, R)),
+		NondetFailResult) },
+	print("nondet_fail: "), print(NondetFailResult), nl,
+	{ try((pred(R::out) is det :-
+			solutions(nondet_succeed_then_throw, R)),
+		NondetSucceedThenThrowResult) },
+	print("nondet_succeed_then_throw: "),
+	print(NondetSucceedThenThrowResult), nl.
+
+:- pred det_throw(string::out) is det.
+:- pragma memo(det_throw/1).
+det_throw(_) :- throw("det_throw").
+
+:- pred semidet_throw(string::out) is semidet.
+:- pragma memo(semidet_throw/1).
+semidet_throw(_) :- throw("semidet_throw").
+
+:- pred nondet_throw(string::out) is nondet.
+nondet_throw(_) :- throw("nondet_throw").
+
+:- pred multi_throw(string::out) is multi.
+multi_throw(_) :- throw("multi_throw").
+
+:- pred cc_nondet_throw(string::out) is cc_nondet.
+:- pragma memo(cc_nondet_throw/1).
+cc_nondet_throw(_) :- throw("cc_nondet_throw").
+
+:- pred cc_multi_throw(string::out) is cc_multi.
+:- pragma memo(cc_multi_throw/1).
+cc_multi_throw(_) :- throw("cc_multi_throw").
+
+
+:- pred det_succeed(string::out) is det.
+:- pragma memo(det_succeed/1).
+det_succeed("det_succeed").
+
+:- pred semidet_succeed(string::out) is semidet.
+:- pragma memo(semidet_succeed/1).
+semidet_succeed("semidet_succeed").
+
+:- pred nondet_succeed(string::out) is nondet.
+nondet_succeed("nondet_succeed 1").
+nondet_succeed("nondet_succeed 2").
+
+:- pred multi_succeed(string::out) is multi.
+multi_succeed("multi_succeed 1").
+multi_succeed("multi_succeed 2").
+
+:- pred cc_nondet_succeed(string::out) is cc_nondet.
+:- pragma memo(cc_nondet_succeed/1).
+cc_nondet_succeed("cc_nondet_succeed").
+cc_nondet_succeed("cc_nondet_succeed 2").
+
+:- pred cc_multi_succeed(string::out) is cc_multi.
+:- pragma memo(cc_multi_succeed/1).
+cc_multi_succeed("cc_multi_succeed").
+cc_multi_succeed("cc_multi_succeed 2").
+
+
+:- pred semidet_fail(string::out) is semidet.
+:- pragma memo(semidet_fail/1).
+semidet_fail("semidet_fail") :- fail.
+
+:- pred nondet_fail(string::out) is nondet.
+nondet_fail("nondet_fail 1") :- fail.
+nondet_fail("nondet_fail 2") :- fail.
+
+:- pred cc_nondet_fail(string::out) is cc_nondet.
+:- pragma memo(cc_nondet_fail/1).
+cc_nondet_fail("cc_nondet_fail 1") :- fail.
+cc_nondet_fail("cc_nondet_fail 2") :- fail.
+
+
+:- pred nondet_succeed_then_throw(string::out) is nondet.
+nondet_succeed_then_throw("nondet_succeed_then_throw 1").
+nondet_succeed_then_throw("nondet_succeed_then_throw 2").
+nondet_succeed_then_throw(_) :- throw("nondet_succeed_then_throw 3").
+nondet_succeed_then_throw("nondet_succeed_then_throw 4").
+
+:- pred multi_succeed_then_throw(string::out) is multi.
+multi_succeed_then_throw("multi_succeed_then_throw 1").
+multi_succeed_then_throw("multi_succeed_then_throw 2").
+multi_succeed_then_throw(_) :- throw("multi_succeed_then_throw 3").
+multi_succeed_then_throw("multi_succeed_then_throw 4").
+

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list