public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Simplify log interface; escape cntrl chars; update expunit.
@ 2007-12-18 17:00 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2007-12-18 17:00 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  c0ff11aa28f8188570d8b4654c2b9c61f9c9be8d (commit)
      from  136df9efaf15a78aaa2ccb91cec7480017574611 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit c0ff11aa28f8188570d8b4654c2b9c61f9c9be8d
Author: Andrew Cagney <cagney@redhat.com>
Date:   Tue Dec 18 11:59:24 2007 -0500

    Simplify log interface; escape cntrl chars; update expunit.
    
    frysk-sys/frysk/expunit/ChangeLog
    2007-12-18  cagney  <cagney@redhat.com>
    
    	* TestEquals.java (testToString()): New.
    	* Equals.java (toString()): Return an escaped string.
    	* TestRegex.java (testToString()): New.
    	* Regex.java (toString()): Return an escaped string.
    	* Match.java (escape(String)): New.
    	* Expect.java (expectMilliseconds(long,Match[]): Use Log.log(Object,String,Object,String,int).
    
    frysk-sys/frysk/rsl/ChangeLog
    2007-12-18  cagney  <cagney@redhat.com>
    
    	* Log.java (suffix()): Rename prefix.
    	(print(Object)): Inspect the object's type.
    	(print(Throwable[])): Delete.
    	(print(Throwable)): Delete.
    	(dump(Throwable)): New.
    	(dump(Object)): New.
    	(dump(Object,int)): New.
    	(print(Object[])): Delete.
    	(print(String[])): Delete.
    	(log(Object,String,Throwable)): Delete.
    	(log(Object,String,Throwable[])): Delete.
    	(log(Object,String,Object[])): Delete.
    	(log(Object,String,long,String,Object[])): Delete.
    	(log(Object,String,Object,String,int)): New.
    	(log(Object,String,Object,String,Object,String,Object[])): Delete.
    	(log(Object,String,Object,String,Object,String,Object)): New.
    	(log(Object,String,String[])): Delete.

-----------------------------------------------------------------------

Summary of changes:
 frysk-sys/frysk/expunit/ChangeLog       |    9 ++
 frysk-sys/frysk/expunit/Equals.java     |    2 +-
 frysk-sys/frysk/expunit/Expect.java     |    9 +-
 frysk-sys/frysk/expunit/Match.java      |   11 ++
 frysk-sys/frysk/expunit/Regex.java      |    8 +-
 frysk-sys/frysk/expunit/TestEquals.java |    5 +
 frysk-sys/frysk/expunit/TestRegex.java  |    5 +
 frysk-sys/frysk/rsl/ChangeLog           |   20 ++++
 frysk-sys/frysk/rsl/Log.java            |  188 +++++++++++++------------------
 9 files changed, 139 insertions(+), 118 deletions(-)

First 500 lines of diff:
diff --git a/frysk-sys/frysk/expunit/ChangeLog b/frysk-sys/frysk/expunit/ChangeLog
index da96d7d..2a1f8be 100644
--- a/frysk-sys/frysk/expunit/ChangeLog
+++ b/frysk-sys/frysk/expunit/ChangeLog
@@ -1,3 +1,12 @@
+2007-12-18  cagney  <cagney@redhat.com>
+
+	* TestEquals.java (testToString()): New.
+	* Equals.java (toString()): Return an escaped string.
+	* TestRegex.java (testToString()): New.
+	* Regex.java (toString()): Return an escaped string. 
+	* Match.java (escape(String)): New.
+	* Expect.java (expectMilliseconds(long,Match[]): Use Log.log(Object,String,Object,String,int).
+
 2007-12-17  cagney  <cagney@redhat.com>
 
 	* Expect.java: Use frysk.rsl.Log.
diff --git a/frysk-sys/frysk/expunit/Equals.java b/frysk-sys/frysk/expunit/Equals.java
index f59bd31..d90c49b 100644
--- a/frysk-sys/frysk/expunit/Equals.java
+++ b/frysk-sys/frysk/expunit/Equals.java
@@ -56,7 +56,7 @@ public class Equals
      */
     public String toString ()
     {
-	return s;
+	return escape(s);
     }
     protected int groupCount ()
     {
diff --git a/frysk-sys/frysk/expunit/Expect.java b/frysk-sys/frysk/expunit/Expect.java
index eeed7ec..4195d48 100644
--- a/frysk-sys/frysk/expunit/Expect.java
+++ b/frysk-sys/frysk/expunit/Expect.java
@@ -192,18 +192,17 @@ public class Expect
      */
     void expectMilliseconds(long timeoutMilliseconds, Match[] matches) {
 	final long endTime = (System.currentTimeMillis() + timeoutMilliseconds);
-	fine.log(this, "expect timeout", timeoutMilliseconds, "match", matches);
+	fine.log(this, "expect", matches, "timeout [milliseconds]", (int)timeoutMilliseconds);
 	while (true) {
 	    if (matches != null) {
 		for (int i = 0; i < matches.length; i++) {
 		    Match p = matches[i];
 		    if (p != null) {
-			finest.log(this, "find", (Object) p, "in",
-				(Object) output);
+			finest.log(this, "find", p, "in", (Object) output);
 			if (p.find(output)) {
-			    fine.log(this, "match", (Object) p.group());
+			    fine.log(this, "match", (Object) p.group(), "with", p);
 			    p.execute();
-			    // Remove everying up to and including what
+			    // Remove everything up to and including what
 			    // matched.
 			    if (p.end() >= 0)
 				output = output.substring(p.end());
diff --git a/frysk-sys/frysk/expunit/Match.java b/frysk-sys/frysk/expunit/Match.java
index c0eef04..8e24262 100644
--- a/frysk-sys/frysk/expunit/Match.java
+++ b/frysk-sys/frysk/expunit/Match.java
@@ -46,6 +46,17 @@ package frysk.expunit;
 public abstract class Match
 {
     /**
+     * Escape any characters in S so it looks something like a quoted-string seen in java.
+     * @param s the unescaped string
+     * @return the escaped string
+     */
+    public static String escape(String s) {
+	return s.replaceAll("\r", "\\\\r")
+		.replaceAll("\n", "\\\\n")
+		.replaceAll("\t", "\\\\t")
+		.replaceAll("\f", "\\\\f");
+    }
+    /**
      * Find the pattern in the output, normally this is an unanchored
      * match.
      */
diff --git a/frysk-sys/frysk/expunit/Regex.java b/frysk-sys/frysk/expunit/Regex.java
index 084b28d..197a05e 100644
--- a/frysk-sys/frysk/expunit/Regex.java
+++ b/frysk-sys/frysk/expunit/Regex.java
@@ -57,13 +57,11 @@ public class Regex
     /**
      * String representing this object - the patter it matches.
      */
-    public String toString ()
-    {
-	return pattern.pattern ();
+    public String toString() {
+	return escape(pattern.pattern());
     }
     /**
-     * Find the pattern in the output, normally this is an unanchored
-     * match.
+     * Find the pattern in the output, normally this is an unanchored match.
      */
     private Matcher matcher;
     boolean find (String output)
diff --git a/frysk-sys/frysk/expunit/TestEquals.java b/frysk-sys/frysk/expunit/TestEquals.java
index e63350d..74780b1 100644
--- a/frysk-sys/frysk/expunit/TestEquals.java
+++ b/frysk-sys/frysk/expunit/TestEquals.java
@@ -98,4 +98,9 @@ public class TestEquals
 		}
 	    });
     }
+    
+    public void testToString() {
+	Match m = new Equals("\r\n\t\f\"\'");
+	assertEquals("toString", "\\r\\n\\t\\f\"\'", m.toString());
+    }
 }
diff --git a/frysk-sys/frysk/expunit/TestRegex.java b/frysk-sys/frysk/expunit/TestRegex.java
index 65e600d..ba277bf 100644
--- a/frysk-sys/frysk/expunit/TestRegex.java
+++ b/frysk-sys/frysk/expunit/TestRegex.java
@@ -111,4 +111,9 @@ public class TestRegex
 		}
 	    });
     }
+    
+    public void testToString() {
+	Match m = new Regex("\r\n\t\f\"\'");
+	assertEquals("toString", "\\r\\n\\t\\f\"\'", m.toString());
+    }
 }
diff --git a/frysk-sys/frysk/rsl/ChangeLog b/frysk-sys/frysk/rsl/ChangeLog
index 201f560..55f7ec3 100644
--- a/frysk-sys/frysk/rsl/ChangeLog
+++ b/frysk-sys/frysk/rsl/ChangeLog
@@ -1,3 +1,23 @@
+2007-12-18  cagney  <cagney@redhat.com>
+
+	* Log.java (suffix()): Rename prefix. 
+	(print(Object)): Inspect the object's type.
+	(print(Throwable[])): Delete.
+	(print(Throwable)): Delete.
+	(dump(Throwable)): New.
+	(dump(Object)): New.
+	(dump(Object,int)): New.
+	(print(Object[])): Delete.
+	(print(String[])): Delete.
+	(log(Object,String,Throwable)): Delete.
+	(log(Object,String,Throwable[])): Delete.
+	(log(Object,String,Object[])): Delete.
+	(log(Object,String,long,String,Object[])): Delete.
+	(log(Object,String,Object,String,int)): New.
+	(log(Object,String,Object,String,Object,String,Object[])): Delete.
+	(log(Object,String,Object,String,Object,String,Object)): New.
+	(log(Object,String,String[])): Delete.
+
 2007-12-17  cagney  <cagney@redhat.com>
 
 	* Log.java (log(...)): Rename message(...).
diff --git a/frysk-sys/frysk/rsl/Log.java b/frysk-sys/frysk/rsl/Log.java
index 9336d90..b8d87f3 100644
--- a/frysk-sys/frysk/rsl/Log.java
+++ b/frysk-sys/frysk/rsl/Log.java
@@ -42,6 +42,7 @@ package frysk.rsl;
 import java.io.PrintStream;
 import java.util.List;
 import java.text.MessageFormat;
+import java.lang.reflect.Array;
 
 /**
  * Generate log information when enabled.
@@ -155,11 +156,69 @@ public final class Log {
 	out.print("]:");
     }
 
-    private void postfix() {
+    private void suffix() {
 	out.println();
 	out.flush();
     }
-
+  
+    /**
+     * Throwables get their message printed; along with any root
+     * causes.
+     */
+    private void dump(Throwable t) {
+	out.print("<<exception");
+	Throwable cause = t;
+	do {
+	    out.print(":");
+	    out.print(t.getMessage());
+	    cause = cause.getCause();
+	} while (cause != null);
+	out.print(">>");
+    }
+    private void dump(String s) {
+	out.print("\"");
+	out.print(s
+		.replaceAll("\"", "\\\\\"")
+		.replaceAll("\'", "\\\\\'")
+		.replaceAll("\r", "\\\\r")
+		.replaceAll("\n", "\\\\n")
+		.replaceAll("\t", "\\\\t")
+		.replaceAll("\f", "\\\\f"));
+	out.print("\"");
+    }
+    /**
+     * Dump the array object's i'th element
+     * @param o the array object
+     * @param i the array index
+     */
+    private void dump(Object o, int i) {
+	// for moment assume the array contains Objects; dump recursively.
+	dump(Array.get(o, i));
+    }
+    /**
+     * Dump an arbitrary object.
+     * @param o the object to dump
+     */
+    private void dump(Object o) {
+	if (o.getClass().isArray()) {
+	    out.print("[");
+	    for (int i = 0; i < Array.getLength(o); i++) {
+		if (i > 0)
+		    out.print(",");
+		dump(o, i);
+	    }
+	    out.print("]");
+	} else if (o instanceof Throwable)
+	    dump((Throwable) o);
+	else if (o instanceof String)
+	    dump((String)o);
+	else {
+	    out.print("<<");
+	    out.print(o.toString());
+	    out.print(">>");
+	}
+    }
+    
     /**
      * Integers are printed in decimal.
      */
@@ -200,57 +259,12 @@ public final class Log {
 	out.print(" ");
 	out.print(s);
     }
-    private void print(String[] a) {
-	out.print(" [");
-	for (int i = 0; i < a.length; i++) {
-	    if (i > 0)
-		out.print(",");
-	    out.print(a[i]);
-	}
-	out.print("]");
-    }
     /**
-     * Objects are wrapped in "[" and "]".
+     * Use poorly implemented reflection to dump Objectss.
      */
     private void print(Object o) {
-	out.print(" <<");
-	out.print(o.toString());
-	out.print(">>");
-    }
-    private void print(Object[] a) {
-	out.print(" [");
-	for (int i = 0; i < a.length; i++) {
-	    if (i > 0)
-		out.print(",");
-	    out.print("<<");
-	    out.print(a[i].toString());
-	    out.print(">>");
-	}
-	out.print("]");
-    }
-    /**
-     * Throwables get their message printed; along with any root
-     * causes.
-     */
-    private void print(Throwable t) {
-	out.print(" exception");
-	Throwable cause = t;
-	do {
-	    out.print(":");
-	    out.print(t.getMessage());
-	    cause = cause.getCause();
-	} while (cause != null);
-    }
-    private void print(Throwable[] t) {
-	out.print(" exception");
-	for (int i = 0; i < t.length; i++) {
-	    Throwable cause = t[i];
-	    do {
-		out.print(":");
-		out.print(cause.getMessage());
-		cause = cause.getCause();
-	    } while (cause != null);
-	}
+	out.print(" ");
+	dump(o);
     }
     
     /**
@@ -261,7 +275,7 @@ public final class Log {
 	    return;
 	prefix();
 	print(MessageFormat.format(msg, o));
-	postfix();
+	suffix();
     }
     /**
      * For compatibility with existing loggers.
@@ -271,7 +285,7 @@ public final class Log {
 	    return;
 	prefix();
 	print(MessageFormat.format(msg, new Object[] { o }));
-	postfix();
+	suffix();
     }
 
     // Add at will and on demand.
@@ -280,14 +294,14 @@ public final class Log {
 	    return;
 	prefix();
 	print(p1);
-	postfix();
+	suffix();
     }
     
     public void log(Object self, String p1) {
 	if (!logging)
 	    return;
 	print(p1);
-	postfix();
+	suffix();
     }
 
     // Add at will and on demand.
@@ -297,7 +311,7 @@ public final class Log {
 	prefix(self);
 	print(p1);
 	print(p2);
-	postfix();
+	suffix();
     }
 
     // Add at will and on demand.
@@ -307,7 +321,7 @@ public final class Log {
 	prefix(self);
 	print(p1);
 	print(p2);
-	postfix();
+	suffix();
     }
 
     // Add at will and on demand.
@@ -317,7 +331,7 @@ public final class Log {
 	prefix(self);
 	print(p1);
 	print(p2);
-	postfix();
+	suffix();
     }
 
     // Add at will and on demand.
@@ -327,7 +341,7 @@ public final class Log {
 	prefix(self);
 	print(p1);
 	print(p2);
-	postfix();
+	suffix();
     }
 
     // Add at will and on demand.
@@ -337,7 +351,7 @@ public final class Log {
 	prefix(self);
 	print(p1);
 	print(p2);
-	postfix();
+	suffix();
     }
 
     // Add at will and on demand.
@@ -347,50 +361,10 @@ public final class Log {
 	prefix(self);
 	print(p1);
 	print(p2);
-	postfix();
-    }
-
-    // Add at will and on demand.
-    public void log(Object self, String p1, String[] p2) {
-	if (!logging)
-	    return;
-	prefix(self);
-	print(p1);
-	print(p2);
-	postfix();
-    }
-
-    // Add at will and on demand.
-    public void log(Object self, String p1, Object[] p2) {
-	if (!logging)
-	    return;
-	prefix(self);
-	print(p1);
-	print(p2);
-	postfix();
-    }
-
-    // Add at will and on demand.
-    public void log(Object self, String p1, Throwable p2) {
-	if (!logging)
-	    return;
-	prefix(self);
-	print(p1);
-	print(p2);
-	postfix();
+	suffix();
     }
 
-    // Add at will and on demand.
-    public void log(Object self, String p1, Throwable[] p2) {
-	if (!logging)
-	    return;
-	prefix(self);
-	print(p1);
-	print(p2);
-	postfix();
-    }
-
-    public void log(Object self, String p1, long p2, String p3, Object[] p4) {
+    public void log(Object self, String p1, Object p2, String p3, Object p4) {
 	if (!logging)
 	    return;
 	prefix(self);
@@ -398,9 +372,10 @@ public final class Log {
 	print(p2);
 	print(p3);
 	print(p4);
-	postfix();
+	suffix();
     }
-    public void log(Object self, String p1, Object p2, String p3, Object p4) {
+    
+    public void log(Object self, String p1, Object p2, String p3, int p4) {
 	if (!logging)
 	    return;
 	prefix(self);
@@ -408,11 +383,10 @@ public final class Log {
 	print(p2);
 	print(p3);
 	print(p4);
-	postfix();
+	suffix();
     }
     
-    public void log(Object self, String p1, Object p2, String p3, Object p4,
-	    String p5, String[] p6) {
+    public void log(Object self, String p1, Object p2, String p3, Object p4, String p5, Object p6) {
 	if (!logging)
 	    return;
 	prefix(self);
@@ -422,6 +396,6 @@ public final class Log {
 	print(p4);
 	print(p5);
 	print(p6);
-	postfix();
+	suffix();
     }
 }


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-12-18 17:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-18 17:00 [SCM] master: Simplify log interface; escape cntrl chars; update expunit cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).