diff: add interactive query test cases

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Mar 26 09:23:56 AEDT 1999


Estimated hours taken: 3

Add some test cases to test interactive queries.

tests/debugger/queens.inp:
	Add tests of interactive queries.

tests/debugger/queens.exp:
	Update to reflect the new output for this test case.

tests/debugger/Mmakefile:
	Add dependency of queens.out on queens.ints.
	This is needed in order for us to use interactive queries.

tests/debugger/queens.m:
	Export qperm/2, for use in interactive queries.

browser/interactive_query.m:
	Flush MDB_stdout after printing the prompt, so things work
	properly with I/O redirections.

trace/mercury_trace_internal.c:
	Fix an off-by-one error detected by the above tests.

Index: browser/interactive_query.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/interactive_query.m,v
retrieving revision 1.1
diff -u -r1.1 interactive_query.m
--- interactive_query.m	1999/03/05 12:52:11	1.1
+++ interactive_query.m	1999/03/25 21:49:09
@@ -37,6 +37,7 @@
 query(QueryType, Imports, Options, MDB_Stdin, MDB_Stdout) -->
 	% write_import_list(Imports),
 	print(MDB_Stdout, query_prompt(QueryType)),
+	io__flush_output(MDB_Stdout),
 	io__set_input_stream(MDB_Stdin, OldStdin),
 	term_io__read_term(Result),
 	io__set_input_stream(OldStdin, _),
Index: tests/debugger/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/Mmakefile,v
retrieving revision 1.17
diff -u -r1.17 Mmakefile
--- Mmakefile	1999/03/20 06:49:43	1.17
+++ Mmakefile	1999/03/25 22:16:03
@@ -70,8 +70,36 @@
 	$(MDB) ./multi_parameter < multi_parameter.inp \
 		> multi_parameter.out 2>&1
 
-queens.out: queens queens.inp
-	$(MDB) ./queens < queens.inp > queens.out 2>&1
+# Note that queens.out.orig depends on $(queens.ints) because queens.inp
+# contains interactive queries that require queens.ints to have been built.
+queens.out.orig: queens queens.inp $(queens.ints)
+	$(MDB) ./queens < queens.inp > queens.out.orig 2>&1
+
+# We pipe the output through sed to remove some spurious warnings that
+# `ld' issues.
+# XXX we should fix the spurious warnings about unresolved symbols.
+# (The spurious warnings about exception handling are due to a flaw
+# in the Digital Unix 3.2 linker, so that one is DEC's problem.)
+queens.out: queens.out.orig
+	cat queens.out.orig | \
+		sed \
+		    -e '/\/usr\/bin\/ld:$$/N' \
+		    -e 's/\/usr\/bin\/ld:.//' \
+		    -e '/Warning: Linking some objects which contain exception information sections$$/N' \
+		    -e 's/Warning: Linking some objects which contain exception information sections.//' \
+		    -e '/	and some which do not. This may cause fatal runtime exception handling$$/N' \
+		    -e 's/	and some which do not. This may cause fatal runtime exception handling.//' \
+		    -e '/	problems (last obj encountered without exceptions was .*)\.$$/N' \
+		    -e 's/	problems (last obj encountered without exceptions was .*)\..//' \
+		    -e '/Warning: Unresolved:$$/N' \
+		    -e 's/Warning: Unresolved:.//' \
+		    -e '/<predicate .main.\/2 mode 0>$$/N' \
+		    -e 's/<predicate .main.\/2 mode 0>.//' \
+		    -e '/<predicate .queens:qperm.\/2 mode 0>$$/N' \
+		    -e 's/<predicate .queens:qperm.\/2 mode 0>.//' \
+		    -e '/__start$$/N' \
+		    -e 's/__start.//' \
+		    > queens.out
 
 # We ignore the result of this action because
 # the exit status of grep is not useful in this case
Index: tests/debugger/queens.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/queens.inp,v
retrieving revision 1.5
diff -u -r1.5 queens.inp
--- queens.inp	1998/11/13 08:40:45	1.5
+++ queens.inp	1999/03/25 21:31:59
@@ -38,7 +38,35 @@
 stack
 stack -d
 print *
-
+#
+# Test interactive queries.
+#
+mmc_options --use-subdirs
+mmc_options
+query queens list
+append(X, Y, ['a', 'b', 'c']).
+qperm([1,2,3], List).
+qperm([1,2,3], List), List = [2 | _].
+qperm([1,2,3], List), List = [4 | _].
+qperm([1,2,"foo"], List).
+qperm(List, [1]).
+quit. cc_query queens list
+append(X, Y, ['a', 'b', 'c']).
+qperm([1,2,3], List).
+qperm([1,2,3], List), List = [2 | _].
+qperm([1,2,3], List), List = [4 | _].
+quit. io_query queens list
+main.
+if { append(X, Y, ['a', 'b', 'c']) } then
+	print("X = "), print(X), 
+	print(", Y = "), print(Y), nl
+else
+	print("No solution\n").
+if { qperm([1,2,3], List) } then print(List), nl else [].
+if { qperm([1,2,3], List), List = [2 | _] } then print(List), nl else { true }.
+if { qperm([1,2,3], List), List = [4 | _] } then print(List), nl
+else print("No solution, as expected."), io__nl.
+quit.
 retry
 print *
 finish -a
Index: tests/debugger/queens.m
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/queens.m,v
retrieving revision 1.1
diff -u -r1.1 queens.m
--- queens.m	1998/04/08 11:35:25	1.1
+++ queens.m	1999/03/25 19:30:29
@@ -2,11 +2,15 @@
 
 :- interface.
 
-:- import_module io.
+:- import_module io, list.
 
 :- pred main(io__state, io__state).
 :- mode main(di, uo) is cc_multi.
 
+	% exported for use with interactive queries in the debugger
+:- pred qperm(list(T), list(T)).
+:- mode qperm(in, out) is nondet.
+
 :- implementation.
 
 :- import_module list, int.
@@ -23,9 +27,6 @@
 
 :- pred queen(list(int), list(int)).
 :- mode queen(in, out) is nondet.
-
-:- pred qperm(list(T), list(T)).
-:- mode qperm(in, out) is nondet.
 
 :- pred qdelete(T, list(T), list(T)).
 :- mode qdelete(out, in, out) is nondet.
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.34
diff -u -r1.34 mercury_trace_internal.c
--- mercury_trace_internal.c	1999/03/25 10:42:53	1.34
+++ mercury_trace_internal.c	1999/03/25 19:36:40
@@ -1033,6 +1033,7 @@
 		for (i = 1; i < word_count; i++) {
 			len += strlen(words[i]) + 1;
 		}
+		len++;
 		MR_mmc_options = realloc(MR_mmc_options, len);
 
 		/* copy the arguments to MR_mmc_options */
Index: tests/debugger/queens.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/queens.exp,v
retrieving revision 1.6
diff -u -r1.6 queens.exp
--- queens.exp	1998/11/13 08:40:44	1.6
+++ queens.exp	1999/03/25 22:17:47
@@ -97,6 +97,124 @@
    5       1       1    1 pred queens:main/2-0 (cc_multi)
 mdb> print *
        HeadVar__1           		[4, 5]
+mdb> #
+Unknown command `#'. Give the command `help' for help.
+mdb> # Test interactive queries.
+Unknown command `#'. Give the command `help' for help.
+mdb> #
+Unknown command `#'. Give the command `help' for help.
+mdb> mmc_options
+mdb> mmc_options --use-subdirs
+mdb> query queens list
+?- <stdin>:026: Inferred :- pred query((list:list(character)), (list:list(character))).
+<stdin>:026: Inferred :- mode query(out, out) is multi.
+X = [], Y = ['a', 'b', 'c'], true ;
+X = ['a'], Y = ['b', 'c'], true ;
+X = ['a', 'b'], Y = ['c'], true ;
+X = ['a', 'b', 'c'], Y = [], true ;
+fail.
+No (more) solutions.
+?- <stdin>:026: Inferred :- pred query((list:list(int))).
+<stdin>:026: Inferred :- mode query(out) is nondet.
+List = [1, 2, 3], true ;
+List = [1, 3, 2], true ;
+List = [2, 1, 3], true ;
+List = [2, 3, 1], true ;
+List = [3, 1, 2], true ;
+List = [3, 2, 1], true ;
+fail.
+No (more) solutions.
+?- <stdin>:012: In clause for predicate `query:run/2':
+<stdin>:012:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:014: In clause for predicate `query:run/2':
+<stdin>:014:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:012: In clause for predicate `query:run/2':
+<stdin>:012:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:015: In clause for predicate `query:run/2':
+<stdin>:015:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:026: In clause for predicate `query:query/2':
+<stdin>:026:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:001: In clause for predicate `query:query/2':
+<stdin>:001:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:026: Inferred :- pred query((list:list(int)), (list:list(int))).
+<stdin>:026: Inferred :- mode query(out, out) is nondet.
+List = [2, 1, 3], _2 = [1, 3], true ;
+List = [2, 3, 1], _2 = [3, 1], true ;
+fail.
+No (more) solutions.
+?- <stdin>:012: In clause for predicate `query:run/2':
+<stdin>:012:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:014: In clause for predicate `query:run/2':
+<stdin>:014:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:012: In clause for predicate `query:run/2':
+<stdin>:012:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:015: In clause for predicate `query:run/2':
+<stdin>:015:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:026: In clause for predicate `query:query/2':
+<stdin>:026:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:001: In clause for predicate `query:query/2':
+<stdin>:001:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:026: Inferred :- pred query((list:list(int)), (list:list(int))).
+<stdin>:026: Inferred :- mode query(out, out) is nondet.
+fail.
+No (more) solutions.
+?- <stdin>:001: In clause for predicate `query:query/1':
+<stdin>:001:   in argument 1 of call to predicate `qperm/2':
+<stdin>:001:   in argument 2 of functor `./2':
+<stdin>:001:   in argument 2 of functor `./2':
+<stdin>:001:   in argument 1 of functor `./2':
+<stdin>:001:   type error in unification of argument
+<stdin>:001:   and constant `"foo"'.
+<stdin>:001:   argument has type `int',
+<stdin>:001:   constant `"foo"' has type `string'.
+For more information, try recompiling with `-E'.
+Compilation error(s) occurred.
+?- <stdin>:026: Inferred :- pred query((list:list(int))).
+<stdin>:001: In clause for `query(out(not_reached))':
+<stdin>:001:   in argument 1 of call to predicate `queens:qperm/2':
+<stdin>:001:   mode error: variable `List' has instantiatedness `free',
+<stdin>:001:   expected instantiatedness was `ground'.
+<stdin>:026: Inferred :- mode query(out(free)).
+For more information, try recompiling with `-E'.
+Compilation error(s) occurred.
+?- 
+mdb>  cc_query queens list
+?- <stdin>:017: Inferred :- pred query((list:list(character)), (list:list(character))).
+<stdin>:017: Inferred :- mode query(out, out) is multi.
+X = [], Y = ['a', 'b', 'c'], true.
+?- <stdin>:017: Inferred :- pred query((list:list(int))).
+<stdin>:017: Inferred :- mode query(out) is nondet.
+List = [1, 2, 3], true.
+?- <stdin>:011: In clause for predicate `query:run/2':
+<stdin>:011:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:012: In clause for predicate `query:run/2':
+<stdin>:012:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:017: In clause for predicate `query:query/2':
+<stdin>:017:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:001: In clause for predicate `query:query/2':
+<stdin>:001:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:017: Inferred :- pred query((list:list(int)), (list:list(int))).
+<stdin>:017: Inferred :- mode query(out, out) is nondet.
+List = [2, 1, 3], _2 = [1, 3], true.
+?- <stdin>:011: In clause for predicate `query:run/2':
+<stdin>:011:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:012: In clause for predicate `query:run/2':
+<stdin>:012:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:017: In clause for predicate `query:query/2':
+<stdin>:017:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:001: In clause for predicate `query:query/2':
+<stdin>:001:   warning: variable `_2' occurs more than once in this scope.
+<stdin>:017: Inferred :- pred query((list:list(int)), (list:list(int))).
+<stdin>:017: Inferred :- mode query(out, out) is nondet.
+No solution.
+?- 
+mdb>  io_query queens list
+run <-- [1, 3, 5, 2, 4]
+run <-- X = [], Y = ['a', 'b', 'c']
+run <-- [1, 2, 3]
+run <-- [2, 1, 3]
+run <-- No solution, as expected.
+run <-- 
 mdb> 
       21:     10  6 SWTC pred queens:qperm/2-0 (nondet) s1;
 mdb> retry

-- 
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.



More information about the developers mailing list