[m-rev.] Fixes for test output

Ralph Becket rafe at csse.unimelb.edu.au
Tue Aug 21 15:03:02 AEST 2007


Estimated hours taken: 4 (mostly testing)
Branches: main

library/list.m:
	Improve the pretty-printer formatting of lists by preventing
	the output of ellipsis when all items in the list have been
	printed.

library/pretty_printer.m:
	Some term names output by the debugger are module qualified.
	Prevent the default term formatting code from quoting names
	that contain '.'s unless they also contain other characters
	requiring quoting.

tests/debugger/browse_pretty.exp:
tests/debugger/browser_test.exp:
tests/debugger/declarative/change_search.exp:
	Updated to reflect output of new pretty printer.

tests/debugger/browser_test.exp3:
	Added a new possible output (for new pretty printer).


Index: library/list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.167
diff -u -r1.167 list.m
--- library/list.m	15 Aug 2007 06:03:55 -0000	1.167
+++ library/list.m	20 Aug 2007 02:09:58 -0000
@@ -2587,11 +2587,15 @@
 list_to_doc_2([]) = str("").
 
 list_to_doc_2([X | Xs]) =
-    docs([
-        format_arg(format(X)),
-        ( if Xs = [] then str("") else group([str(", "), nl]) ),
-        format_susp((func) = list_to_doc_2(Xs))
-    ]).
+    ( if Xs = [] then
+        format_arg(format(X))
+      else
+        docs([
+            format_arg(format(X)),
+            group([str(", "), nl]),
+            format_susp((func) = list_to_doc_2(Xs))
+        ])
+    ).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: library/pretty_printer.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/pretty_printer.m,v
retrieving revision 1.3
diff -u -r1.3 pretty_printer.m
--- library/pretty_printer.m	15 Aug 2007 06:03:55 -0000	1.3
+++ library/pretty_printer.m	21 Aug 2007 01:20:10 -0000
@@ -686,7 +686,7 @@
 expand_format_term(Name, Args, Doc, !Limit, CurrentPri) :-
     decrement_limit(!Limit),
     ( if Args = [] then
-        Doc0 = str(term_io.quoted_atom(Name))
+        Doc0 = str(quote_name_if_needed(Name))
       else if limit_overrun(!.Limit) then
         Doc0 = ellipsis
       else if expand_format_op(Name, Args, CurrentPri, OpDoc) then
@@ -697,7 +697,7 @@
         ])
       else
         Doc0 = docs([
-            str(term_io.quoted_atom(Name)),
+            str(quote_name_if_needed(Name)),
             str("("), indent([format_list(Args, str(", "))]), str(")")
         ])
     ),
@@ -705,6 +705,19 @@
 
 %-----------------------------------------------------------------------------%
 
+    % Add quotes and escape characters to a functor name if needed.
+    % We casually assume that full stop characters ('.') are module
+    % qualifiers and don't warrant quoting.
+    %
+:- func quote_name_if_needed(string) = string.
+
+quote_name_if_needed(Name0) = Name :-
+    Parts0 = string.split_at_char(('.'), Name0),
+    Parts = list.map(term_io.quoted_atom, Parts0),
+    Name = string.join_list(".", Parts).
+
+%-----------------------------------------------------------------------------%
+
 :- pred expand_format_susp(((func) = doc)::in, doc::out,
         formatting_limit::in, formatting_limit::out) is det.
 
Index: tests/debugger/browse_pretty.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/browse_pretty.exp,v
retrieving revision 1.14
diff -u -r1.14 browse_pretty.exp
--- tests/debugger/browse_pretty.exp	4 Apr 2006 07:37:16 -0000	1.14
+++ tests/debugger/browse_pretty.exp	21 Aug 2007 03:58:00 -0000
@@ -7,7 +7,7 @@
        Data (arg 1)           	big(big(big(small, [|]/2, small), [1, ...], small), [1, 2, 3], big(big/3, [|]/2, small))
 mdb> browse 1
 browser> format pretty
-browser> depth 10
+browser> depth 20
 browser> ls
 big(big(big(small, [1], small), [1, 2], small), [1, 2, 3], 
   big(big(small, [1, 2, 3, 4], big(small, [1, 2, 3, 4, 5], small)), 
@@ -19,8 +19,7 @@
 browser> width 30
 browser> ls
 big(
-  big(
-    big(small, [1], small), 
+  big(big(small, [1], small), 
     [1, 2], small), 
   [1, 2, 3], 
   big(
@@ -28,7 +27,8 @@
       big(small, 
         [1, 2, 3, 4, 5], 
         small)), 
-    [1, 2, 3, 4, 5, 6], small))
+    [1, 2, 3, 4, 5, 6], 
+    small))
 browser> width 10
 browser> ls
 big(
@@ -37,37 +37,30 @@
       small, 
       [1], 
       small), 
-    [1, 2], 
+    [1, 
+     2], 
     small), 
   [1, 2, 
    3], 
   big(
     big(
       small, 
-      [
-       1, 
+      [1, 
        2, 
        3, 
        4], 
       big(
         small, 
-        [
-         1, 
+        [1, 
          2, 
          3, 
          4, 
          5], 
-        small)), 
-    [1, 
-     2, 
-     3, 
-     4, 
-     5, 6], 
-    small))
+        ...
 browser> width 79
 browser> depth 3
 browser> ls
-big(big(big(...), ...), [1, ...], ...)
+big(big(..., ...), [..., ...], ...)
 browser> format raw_pretty
 browser> lines 4
 browser> width 40
Index: tests/debugger/browser_test.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/browser_test.exp,v
retrieving revision 1.28
diff -u -r1.28 browser_test.exp
--- tests/debugger/browser_test.exp	19 Jan 2007 04:42:47 -0000	1.28
+++ tests/debugger/browser_test.exp	20 Aug 2007 01:30:29 -0000
@@ -1,4 +1,10 @@
       E1:     C1 CALL pred browser_test.main/2-0 (det) browser_test.m:16
+Goal path printing is now on.
+Registering debuggable procedures... done.
+There is one debuggable module, with 7 procedures.
+mdb: there is no such procedure.
+mdb: xml_browser_cmd: usage error -- type `help xml_browser_cmd' for help.
+Trusting the Mercury standard library
 mdb> echo on
 Command echo enabled.
 mdb> register --quiet
@@ -15,7 +21,10 @@
 mdb> format raw_pretty
 mdb> print *
        Data (arg 1)           	
-big(big(big(small, 1, small), 2, small), 3, big(big(small, 4, big/3), 6, small))
+big(
+  big(big(small, 1, small), 2, small), 
+  3, 
+  big(big(small, 4, big(small, 5, small)), 6, small))
 mdb> format -A verbose
 mdb> print *
        Data (arg 1)           	
@@ -24,6 +33,14 @@
 | 1-big
 | | 1-small
 | | 2-1
+| | 3-small
+| 2-2
+| 3-small
+2-3
+3-big
+  1-big/3
+  2-6
+  3-small
 
 mdb> browse 1; ls; quit
 big(
@@ -32,10 +49,11 @@
   big(big(small, 4, big(small, 5, small)), 6, small))
 mdb> format -AP flat
 mdb> print -f 1
-       Data (arg 1)           	big(big(big(small, 1, small), 2, small), 3, big(big(small, 4, big/3), 6, small))
+       Data (arg 1)           	big(big(big(small, 1, small), 2, small), 3, big(big/3, 6, small))
 mdb> print -p 1
        Data (arg 1)           	
-big(big(big(...), ...), 3, ...)
+big(big(big(small, 1, small), 2, small), 3, 
+  big(big(small, 4, big(small, 5, small)), 6, small))
 mdb> print -v 1
        Data (arg 1)           	
 big
@@ -48,10 +66,7 @@
 | 3-small
 2-3
 3-big
-  1-big
-  | 1-small
-  | 2-4
-  | 3-big/3
+  1-big/3
   2-6
   3-small
 
@@ -251,7 +266,11 @@
 mdb> finish
       E7:     C4 EXIT func browser_test.a_func/1-0 (det) browser_test.m:112 (browser_test.m:31)
 mdb> print -p
-a_func(big(big(...), ...)) = big(big(...), ...)
+a_func(
+  big(big(big(small, 1, small), 2, small), 3, 
+    big(big(small, 4, big(small, 5, small)), 6, small))) = big(
+  big(big(small, 1, small), 2, small), 3, 
+  big(big(small, 4, big(small, 5, small)), 6, small))
 mdb> print -r
 a_func(
   big(
@@ -266,24 +285,15 @@
 a_func
 1-big
 | 1-big
-| | 1-big/3
+| | 1-big
+| | | 1-small
+| | | 2-1
+| | | 3-small
 | | 2-2
 | | 3-small
 | 2-3
-| 3-big
-|   1-big/3
-|   2-6
-|   3-small
-2-big
-  1-big
-  | 1-big/3
-  | 2-2
-  | 3-small
-  2-3
-  3-big
-    1-big/3
-    2-6
-    3-small
+| 3-big/3
+2-big/3
 
 mdb> print -f
 a_func(big(big(big/3, 2, small), 3, big(big/3, 6, small))) = big(big(big/3, 2, small), 3, big(big/3, 6, small))
Index: tests/debugger/browser_test.exp3
===================================================================
RCS file: tests/debugger/browser_test.exp3
diff -N tests/debugger/browser_test.exp3
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/debugger/browser_test.exp3	21 Aug 2007 04:08:01 -0000
@@ -0,0 +1,291 @@
+      E1:     C1 CALL pred browser_test.main/2-0 (det) browser_test.m:16
+mdb> echo on
+Command echo enabled.
+mdb> register --quiet
+mdb> list_context_lines 10
+mdb> break big_data
+ 0: + stop  interface pred browser_test.big_data/1-0 (det)
+mdb> continue
+      E2:     C2 CALL pred browser_test.big_data/1-0 (det) browser_test.m:37 (browser_test.m:20)
+mdb> finish
+      E3:     C2 EXIT pred browser_test.big_data/1-0 (det) browser_test.m:37 (browser_test.m:20)
+mdb> delete *
+ 0: E stop  interface pred browser_test.big_data/1-0 (det)
+mdb> dump 1 browser_test.save.1
+mdb> format raw_pretty
+mdb> print *
+       Data (arg 1)           	
+big(big(big(small, 1, small), 2, small), 3, big(big(small, 4, big/3), 6, small))
+mdb> format -A verbose
+mdb> print *
+       Data (arg 1)           	
+big
+1-big
+| 1-big
+| | 1-small
+| | 2-1
+
+mdb> browse 1; ls; quit
+big(
+  big(big(small, 1, small), 2, small), 
+  3, 
+  big(big(small, 4, big(small, 5, small)), 6, small))
+mdb> format -AP flat
+mdb> print -f 1
+       Data (arg 1)           	big(big(big(small, 1, small), 2, small), 3, big(big(small, 4, big/3), 6, small))
+mdb> print -p 1
+       Data (arg 1)           	
+big(big(..., ...), 3, ...)
+mdb> print -v 1
+       Data (arg 1)           	
+big
+1-big
+| 1-big
+| | 1-small
+| | 2-1
+| | 3-small
+| 2-2
+| 3-small
+2-3
+3-big
+  1-big
+  | 1-small
+  | 2-4
+  | 3-big/3
+  2-6
+  3-small
+
+mdb> print -r 1
+       Data (arg 1)           	
+big(
+  big(big(small, 1, small), 2, small), 
+  3, 
+  big(big(small, 4, big(small, 5, small)), 6, small))
+mdb> print --xyzzy 1
+print: unrecognized option `--xyzzy'
+mdb: print: usage error -- type `help print' for help.
+mdb> browse 1; print; quit
+big(
+  big(big(small, 1, small), 2, small), 
+  3, 
+  big(big(small, 4, big(small, 5, small)), 6, small))
+mdb> browse -f 1; ls; quit
+big(big(big(small, 1, small), 2, small), 3, big(big(small, 4, big(small, 5, small)), 6, small))
+mdb> browse Data
+browser> ls
+big(
+  big(big(small, 1, small), 2, small), 
+  3, 
+  big(big(small, 4, big(small, 5, small)), 6, small))
+browser> cd /1
+browser> ls
+big(big(small, 1, small), 2, small)
+browser> cd /1/2
+browser> ls
+2
+browser> cd /3
+browser> ls
+big(big(small, 4, big(small, 5, small)), 6, small)
+browser> cd 1/3/2
+browser> ls
+5
+browser> cd
+browser> ls
+big(
+  big(big(small, 1, small), 2, small), 
+  3, 
+  big(big(small, 4, big(small, 5, small)), 6, small))
+browser> cdr 100 2
+error: in subdir 2: there is no subterm 2
+browser> cdr 3 1
+browser> ls
+small
+browser> cdr 3 ../1/..
+browser> ls
+big(
+  big(big(small, 1, small), 2, small), 
+  3, 
+  big(big(small, 4, big(small, 5, small)), 6, small))
+browser> quit
+mdb> xml_tmp_filename './browser_test.xml.out'
+mdb> xml_browser_cmd 'cat ./browser_test.xml.out'
+mdb> browse --xml 1
+Saving term to XML file...
+Launching XML browser (this may take some time) ...
+<?xml version="1.0"?>
+<big functor="big" type="browser_test.big" arity="3">
+	<big functor="big" type="browser_test.big" arity="3">
+		<big functor="big" type="browser_test.big" arity="3">
+			<small functor="small" type="browser_test.big" arity="0" />
+			<Int type="int">1</Int>
+			<small functor="small" type="browser_test.big" arity="0" />
+		</big>
+		<Int type="int">2</Int>
+		<small functor="small" type="browser_test.big" arity="0" />
+	</big>
+	<Int type="int">3</Int>
+	<big functor="big" type="browser_test.big" arity="3">
+		<big functor="big" type="browser_test.big" arity="3">
+			<small functor="small" type="browser_test.big" arity="0" />
+			<Int type="int">4</Int>
+			<big functor="big" type="browser_test.big" arity="3">
+				<small functor="small" type="browser_test.big" arity="0" />
+				<Int type="int">5</Int>
+				<small functor="small" type="browser_test.big" arity="0" />
+			</big>
+		</big>
+		<Int type="int">6</Int>
+		<small functor="small" type="browser_test.big" arity="0" />
+	</big>
+</big>
+mdb> browse -x Data
+Saving term to XML file...
+Launching XML browser (this may take some time) ...
+<?xml version="1.0"?>
+<big functor="big" type="browser_test.big" arity="3">
+	<big functor="big" type="browser_test.big" arity="3">
+		<big functor="big" type="browser_test.big" arity="3">
+			<small functor="small" type="browser_test.big" arity="0" />
+			<Int type="int">1</Int>
+			<small functor="small" type="browser_test.big" arity="0" />
+		</big>
+		<Int type="int">2</Int>
+		<small functor="small" type="browser_test.big" arity="0" />
+	</big>
+	<Int type="int">3</Int>
+	<big functor="big" type="browser_test.big" arity="3">
+		<big functor="big" type="browser_test.big" arity="3">
+			<small functor="small" type="browser_test.big" arity="0" />
+			<Int type="int">4</Int>
+			<big functor="big" type="browser_test.big" arity="3">
+				<small functor="small" type="browser_test.big" arity="0" />
+				<Int type="int">5</Int>
+				<small functor="small" type="browser_test.big" arity="0" />
+			</big>
+		</big>
+		<Int type="int">6</Int>
+		<small functor="small" type="browser_test.big" arity="0" />
+	</big>
+</big>
+mdb> format_param -A -f depth 1
+mdb> print *
+       Data (arg 1)           	big(big/3, 3, big/3)
+mdb> print Data/1
+       Data (arg 1)^1         	big(big(small, 1, small), 2, small)
+mdb> format_param -f depth 3
+mdb> print 1
+       Data (arg 1)           	big(big(big(small, 1, small), 2, small), 3, big(big(small, 4, big/3), 6, small))
+mdb> print Data/1/2
+       Data (arg 1)/1/2       	2
+mdb> print 1^1^2^3
+mdb: the path 3 does not exist in variable 1.
+mdb> retry
+      E2:     C2 CALL pred browser_test.big_data/1-0 (det) browser_test.m:37 (browser_test.m:20)
+mdb> break list_data
+ 0: + stop  interface pred browser_test.list_data/1-0 (det)
+mdb> continue
+big(big(big(small, 1, small), 2, small), 3, big(big(small, 4, big(small, 5, small)), 6, small)).
+      E4:     C3 CALL pred browser_test.list_data/1-0 (det) browser_test.m:66 (browser_test.m:23)
+mdb> finish
+      E5:     C3 EXIT pred browser_test.list_data/1-0 (det) browser_test.m:66 (browser_test.m:23)
+mdb> dump Data browser_test.save.2
+mdb> break a_func
+ 1: + stop  interface func browser_test.a_func/1-0 (det)
+mdb> continue
+seq(1, [big(big(small, 1, small), 2, small), small, big(small, 4, big(small, 5, small))], 5).
+browser_test.save.1:
+big(
+ big(
+  big(
+   small,
+   1,
+   small
+  ),
+  2,
+  small
+ ),
+ 3,
+ big(
+  big(
+   small,
+   4,
+   big(
+    small,
+    5,
+    small
+   )
+  ),
+  6,
+  small
+ )
+)
+
+browser_test.save.2:
+seq(
+ 1,
+ [
+  big(
+   big(
+    small,
+    1,
+    small
+   ),
+   2,
+   small
+  ),
+  small,
+  big(
+   small,
+   4,
+   big(
+    small,
+    5,
+    small
+   )
+  )
+ ],
+ 5
+)
+
+      E6:     C4 CALL func browser_test.a_func/1-0 (det) browser_test.m:112 (browser_test.m:31)
+mdb> finish
+      E7:     C4 EXIT func browser_test.a_func/1-0 (det) browser_test.m:112 (browser_test.m:31)
+mdb> print -p
+a_func(big(..., ...)) = big(..., ...)
+mdb> print -r
+a_func(
+  big(
+    big(big(small, 1, small), 2, small), 
+    3, 
+    big(big(small, 4, big(small, 5, small)), 6, small)))
+ = big(
+    big(big(small, 1, small), 2, small), 
+    3, 
+    big(big(small, 4, big(small, 5, small)), 6, small))
+mdb> print -v
+a_func
+1-big
+| 1-big
+| | 1-big/3
+| | 2-2
+| | 3-small
+| 2-3
+| 3-big
+|   1-big/3
+|   2-6
+|   3-small
+2-big
+  1-big
+  | 1-big/3
+  | 2-2
+  | 3-small
+  2-3
+  3-big
+    1-big/3
+    2-6
+    3-small
+
+mdb> print -f
+a_func(big(big(big/3, 2, small), 3, big(big/3, 6, small))) = big(big(big/3, 2, small), 3, big(big/3, 6, small))
+mdb> continue
+big(big(big(small, 1, small), 2, small), 3, big(big(small, 4, big(small, 5, small)), 6, small))
Index: tests/debugger/declarative/change_search.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/change_search.exp,v
retrieving revision 1.3
diff -u -r1.3 change_search.exp
--- tests/debugger/declarative/change_search.exp	4 Apr 2006 07:37:23 -0000	1.3
+++ tests/debugger/declarative/change_search.exp	20 Aug 2007 01:33:39 -0000
@@ -11,21 +11,21 @@
 mdb> format pretty
 mdb> format_param depth 10
 mdb> dd
-mylast([1, 2, 3, 4, 5, 6, 7, 8, ...], no)
+mylast([1, 2, 3, 4, ..., ...], no)
 Valid? info
 Context of current question : change_search.m:20 (change_search.m:14)
 Search mode                 : top down                               
 The current question was chosen because this is the node where the `dd'
 command was issued.
 dd> no
-mylast([2, 3, 4, 5, 6, 7, 8, 9, ...], no)
+mylast([2, 3, 4, 5, ..., ...], no)
 Valid? info
 Context of current question : change_search.m:20 (change_search.m:22)
 Search mode                 : top down                               
 The current question was chosen because this is the next node in the
 top-down search.
 dd> mode dq
-mylast([501, 502, 503, 504, 505, 506, 507, 508, ...], no)
+mylast([501, 502, 503, 504, ..., ...], no)
 Valid? info
 Context of current question   : change_search.m:20 (change_search.m:22)
 Search mode                   : divide and query                       
@@ -34,7 +34,7 @@
 The current question was chosen because this node divides the suspect
 area into two regions of 2,000 and 2,000 events each.
 dd> no
-mylast([751, 752, 753, 754, 755, 756, 757, 758, ...], no)
+mylast([751, 752, 753, 754, ..., ...], no)
 Valid? info
 Context of current question   : change_search.m:20 (change_search.m:22)
 Search mode                   : divide and query                       
@@ -50,9 +50,9 @@
 mdb> retry 750
       E2:     C2 CALL pred change_search.mylast/2-0 (det)
 mdb> p
-mylast([1, 2, 3, 4, 5, 6, 7, 8, ...], _)
+mylast([1, 2, 3, 4, ..., ...], '_')
 mdb> dd -r
-mylast([751, 752, 753, 754, 755, 756, 757, 758, ...], no)
+mylast([751, 752, 753, 754, ..., ...], no)
 Valid? browse 2
 browser> mark
 mylast([1000], no)
@@ -77,16 +77,16 @@
 the unification inside the predicate change_search.mylast/2
 (change_search.m:21). The path to the subterm in the atom is 2.
 dd> mode binary
-mylast([875, 876, 877, 878, 879, 880, 881, 882, ...], no)
+mylast([875, 876, 877, 878, ..., ...], no)
 Valid? mode top_down
-mylast([752, 753, 754, 755, 756, 757, 758, 759, ...], no)
+mylast([752, 753, 754, 755, ..., ...], no)
 Valid? undo
-mylast([875, 876, 877, 878, 879, 880, 881, 882, ...], no)
+mylast([875, 876, 877, 878, ..., ...], no)
 Valid? undo
 dd> mode divide_and_query
-mylast([876, 877, 878, 879, 880, 881, 882, 883, ...], no)
+mylast([876, 877, 878, 879, ..., ...], no)
 Valid? n
-mylast([939, 940, 941, 942, 943, 944, 945, 946, ...], no)
+mylast([939, 940, 941, 942, ..., ...], no)
 Valid? q
 Diagnosis aborted.
       E5:     C4 EXIT pred change_search.mylast/2-0 (det)
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list