You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2004/01/20 19:29:40 UTC
cvs commit: jakarta-tapestry/junit build.xml .cvsignore
hlship 2004/01/20 10:29:40
Modified: . status.xml
junit/src/org/apache/tapestry/junit/mock TestMocks.java
junit build.xml .cvsignore
Log:
Change mock unit tests to redirect System.out and System.err to log files.
Revision Changes Path
1.6 +5 -1 jakarta-tapestry/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/status.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- status.xml 20 Jan 2004 02:07:14 -0000 1.5
+++ status.xml 20 Jan 2004 18:29:40 -0000 1.6
@@ -246,6 +246,10 @@
Remove unncessary constructor from test case classes.
</action>
+<action type="update" dev="HLS">
+Changed mock unit tests to redirect System.out and System.err to log files rather than the console.
+</action>
+
</release>
</changes>
1.4 +54 -1 jakarta-tapestry/junit/src/org/apache/tapestry/junit/mock/TestMocks.java
Index: TestMocks.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/junit/src/org/apache/tapestry/junit/mock/TestMocks.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestMocks.java 20 Jan 2004 02:07:14 -0000 1.3
+++ TestMocks.java 20 Jan 2004 18:29:40 -0000 1.4
@@ -55,7 +55,10 @@
package org.apache.tapestry.junit.mock;
+import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -74,8 +77,13 @@
public class TestMocks extends TapestryTestCase
{
+ public static final String LOGS_DIR = "logs";
+
public static final String SCRIPTS_DIR = "mock-scripts";
+ private PrintStream _savedOut;
+ private PrintStream _savedErr;
+
protected void runTest() throws Throwable
{
String path = SCRIPTS_DIR + "/" + getName();
@@ -147,4 +155,49 @@
file.delete();
}
+ /**
+ * Ensures that the log directory exists, then redirects System.out
+ * and System.err to files within the log.
+ */
+ protected void setUp() throws Exception
+ {
+ File outDir = new File(LOGS_DIR);
+
+ if (!outDir.isDirectory())
+ outDir.mkdirs();
+
+ _savedOut = System.out;
+ _savedErr = System.err;
+
+ System.setOut(createPrintStream(outDir, "out"));
+ System.setErr(createPrintStream(outDir, "err"));
+ }
+
+ protected PrintStream createPrintStream(File directory, String extension) throws Exception
+ {
+ String name = getName() + "." + extension;
+
+ File file = new File(directory, name);
+
+ // Open and truncate file.
+
+ FileOutputStream fos = new FileOutputStream(file, false);
+
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
+
+ return new PrintStream(bos, true);
+ }
+
+ /**
+ * Closes System.out and System.err, then restores them to their original values.
+ */
+ protected void tearDown() throws Exception
+ {
+ System.err.close();
+ System.setErr(_savedErr);
+
+ System.out.close();
+ System.setOut(_savedOut);
+
+ }
}
1.34 +3 -1 jakarta-tapestry/junit/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/junit/build.xml,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- build.xml 3 Dec 2003 15:47:24 -0000 1.33
+++ build.xml 20 Jan 2004 18:29:40 -0000 1.34
@@ -72,6 +72,8 @@
</java>
</target>
+ <!-- To run just a single test case, specify -Dtestcase=name -->
+
<target name="junit" depends="compile" description="Run the test suite.">
<junit printsummary="no"
errorProperty="test.failed"
1.4 +1 -0 jakarta-tapestry/junit/.cvsignore
Index: .cvsignore
===================================================================
RCS file: /home/cvs/jakarta-tapestry/junit/.cvsignore,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- .cvsignore 19 Feb 2003 23:33:55 -0000 1.3
+++ .cvsignore 20 Jan 2004 18:29:40 -0000 1.4
@@ -2,3 +2,4 @@
.clover-classes
.clover-db
.private
+logs
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org