/hg/rhino-tests: Added simple test reporting framework.

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Mon Jul 2 02:07:17 PDT 2012


changeset ff6efa8d997f in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=ff6efa8d997f
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Mon Jul 02 11:08:50 2012 +0200

	Added simple test reporting framework.


diffstat:

 ChangeLog                                              |   15 +
 Makefile                                               |   17 +
 src/org/RhinoTests/Reporter/CommandLineParameters.java |  158 ++++++++++
 src/org/RhinoTests/Reporter/FileUtils.java             |  251 +++++++++++++++++
 src/org/RhinoTests/Reporter/GraphPagesGenerator.java   |   58 +++
 src/org/RhinoTests/Reporter/HistoryPagesGenerator.java |   56 +++
 src/org/RhinoTests/Reporter/IndexPageGenerator.java    |  108 +++++++
 src/org/RhinoTests/Reporter/LogPagesGenerator.java     |  170 +++++++++++
 src/org/RhinoTests/Reporter/Reporter.java              |  132 ++++++++
 src/org/RhinoTests/Reporter/StringUtils.java           |   82 +++++
 src/org/RhinoTests/Reporter/TestResult.java            |  101 ++++++
 11 files changed, 1148 insertions(+), 0 deletions(-)

diffs (truncated from 1222 to 500 lines):

diff -r e5efba84dc1c -r ff6efa8d997f ChangeLog
--- a/ChangeLog	Thu Jun 28 16:12:12 2012 +0200
+++ b/ChangeLog	Mon Jul 02 11:08:50 2012 +0200
@@ -1,3 +1,18 @@
+2012-07-02  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* Makefile: Added new files to compile, added new targets
+	to make report.
+	* src/org/RhinoTests/Reporter/CommandLineParameters.java:
+	* src/org/RhinoTests/Reporter/FileUtils.java:
+	* src/org/RhinoTests/Reporter/GraphPagesGenerator.java:
+	* src/org/RhinoTests/Reporter/HistoryPagesGenerator.java:
+	* src/org/RhinoTests/Reporter/IndexPageGenerator.java:
+	* src/org/RhinoTests/Reporter/LogPagesGenerator.java:
+	* src/org/RhinoTests/Reporter/Reporter.java:
+	* src/org/RhinoTests/Reporter/StringUtils.java:
+	* src/org/RhinoTests/Reporter/TestResult.java:
+	Simple reporting framework. TODO: graph and history generation.
+
 2012-06-28  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/RhinoTests/InvocableTest.java:
diff -r e5efba84dc1c -r ff6efa8d997f Makefile
--- a/Makefile	Thu Jun 28 16:12:12 2012 +0200
+++ b/Makefile	Mon Jul 02 11:08:50 2012 +0200
@@ -47,6 +47,7 @@
 JAVA=java
 TEST_PACKAGE=org/RhinoTests
 TEST_CLASSES_PACKAGE=org/RhinoTests/TestClasses
+REPORTER_PACKAGE=org/RhinoTests/Reporter
 DATE=`date +%Y-%0m-%0d`
 
 TESTS = \
@@ -64,6 +65,15 @@
 
 ALL_CLASSES = \
 	$(BUILD_DIR)/$(TEST_CLASSES_PACKAGE)/TestClass.class \
+	$(BUILD_DIR)/$(REPORTER_PACKAGE)/CommandLineParameters.class \
+	$(BUILD_DIR)/$(REPORTER_PACKAGE)/FileUtils.class \
+	$(BUILD_DIR)/$(REPORTER_PACKAGE)/GraphPagesGenerator.class \
+	$(BUILD_DIR)/$(REPORTER_PACKAGE)/HistoryPagesGenerator.class \
+	$(BUILD_DIR)/$(REPORTER_PACKAGE)/IndexPageGenerator.class \
+	$(BUILD_DIR)/$(REPORTER_PACKAGE)/LogPagesGenerator.class \
+	$(BUILD_DIR)/$(REPORTER_PACKAGE)/StringUtils.class \
+	$(BUILD_DIR)/$(REPORTER_PACKAGE)/TestResult.class \
+	$(BUILD_DIR)/$(REPORTER_PACKAGE)/Reporter.class \
 	$(BUILD_DIR)/$(TEST_PACKAGE)/Constants.class \
 	$(BUILD_DIR)/$(TEST_PACKAGE)/BaseRhinoTest.class \
 	$(BUILD_DIR)/$(TEST_PACKAGE)/BindingsTest.class \
@@ -101,6 +111,10 @@
 	$(JAVA) -cp $(BUILD_DIR) org.RhinoTests.$$tst 2>&1 | tee $(LOGS_DIR)/$(DATE)/$$tst.log ; \
 	done
 
+report:	$(ALL_CLASSES)
+	cp -u $(TEMPLATE_DIR)/style.css $(REPORT_DIR)/style.css
+	$(JAVA) -cp $(BUILD_DIR) org.RhinoTests.Reporter.Reporter -template-dir=$(TEMPLATE_DIR) -log-dir=$(LOGS_DIR) -report-dir=$(REPORT_DIR) -date=$(DATE) -tests="$(TESTS)"
+
 clean:
 	rm -rf $(BUILD_DIR)/org
 	rmdir build
@@ -116,6 +130,9 @@
 $(BUILD_DIR)/$(TEST_PACKAGE)/%.class:	$(SOURCE_DIR)/$(TEST_PACKAGE)/%.java
 	$(JAVAC) -d $(BUILD_DIR) -sourcepath $(SOURCE_DIR)/ $<
 
+$(BUILD_DIR)/$(REPORTER_PACKAGE)/%.class:	$(SOURCE_DIR)/$(REPORTER_PACKAGE)/%.java
+	$(JAVAC) -d $(BUILD_DIR) -sourcepath $(SOURCE_DIR)/ $<
+
 $(BUILD_DIR)/$(TEST_CLASSES_PACKAGE)/%.class:	$(SOURCE_DIR)/$(TEST_CLASSES_PACKAGE)/%.java
 	$(JAVAC) -d $(BUILD_DIR) -sourcepath $(SOURCE_DIR)/ $<
 
diff -r e5efba84dc1c -r ff6efa8d997f src/org/RhinoTests/Reporter/CommandLineParameters.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/RhinoTests/Reporter/CommandLineParameters.java	Mon Jul 02 11:08:50 2012 +0200
@@ -0,0 +1,158 @@
+/*
+  Rhino test framework
+
+   Copyright (C) 2011, 2012  Red Hat
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+
+package org.RhinoTests.Reporter;
+
+
+
+import java.util.Arrays;
+import java.util.Set;
+import java.util.TreeSet;
+
+
+
+/**
+ * 
+ * @author Pavel Tisnovsky
+ */
+public class CommandLineParameters {
+    private static final String PARAM_NAME_TEST_PREFIX = "-tests=";
+    
+    private static final String PARAM_NAME_DATE_PREFIX = "-date=";
+    
+    private static final String PARAM_NAME_REPORT_DIR_PREFIX = "-report-dir=";
+    
+    private static final String PARAM_NAME_LOG_DIR_PREFIX = "-log-dir=";
+    
+    private static final String PARAM_NAME_TEMPLATE_DIR_PREFIX = "-template-dir=";
+    
+    private String templateDir = null;
+    private String logDir = null;
+    private String reportDir = null;
+    private String date = null;
+    private Set<String> tests = new TreeSet<String>();
+
+    public CommandLineParameters(String[] args)
+    {
+        processAllArgs(args);
+        checkAllArgs();
+    }
+
+    private void processAllArgs(String[] args) {
+        for (String arg : args)
+        {
+            if (arg.startsWith(PARAM_NAME_TEMPLATE_DIR_PREFIX)) {
+                this.templateDir = arg.substring(PARAM_NAME_TEMPLATE_DIR_PREFIX.length());
+            }
+            else if (arg.startsWith(PARAM_NAME_LOG_DIR_PREFIX)) {
+                this.logDir = arg.substring(PARAM_NAME_LOG_DIR_PREFIX.length());
+            }
+            else if (arg.startsWith(PARAM_NAME_REPORT_DIR_PREFIX)) {
+                this.reportDir = arg.substring(PARAM_NAME_REPORT_DIR_PREFIX.length());
+            }
+            else if (arg.startsWith(PARAM_NAME_DATE_PREFIX)) {
+                this.date = arg.substring(PARAM_NAME_DATE_PREFIX.length());
+            }
+            else if (arg.startsWith(PARAM_NAME_TEST_PREFIX)) {
+                String testString = arg.substring(PARAM_NAME_TEST_PREFIX.length());
+                String[] testArray = testString.split(" ");
+                this.tests.addAll(Arrays.asList(testArray));
+            }
+        }
+    }
+
+    private void checkAllArgs() {
+        checkTemplateDir();
+        checkLogDir();
+        checkReportDir();
+        checkDate();
+        checkTestSet();
+    }
+
+    private void checkTemplateDir() {
+        if (this.templateDir == null) {
+            throw new RuntimeException("template dir is not set");
+        }
+    }
+
+    private void checkLogDir() {
+        if (this.logDir == null) {
+            throw new RuntimeException("log dir is not set");
+        }
+    }
+
+    private void checkReportDir() {
+        if (this.reportDir == null) {
+            throw new RuntimeException("report dir is not set");
+        }
+    }
+
+    private void checkDate() {
+        if (this.date == null) {
+            throw new RuntimeException("date is not set");
+        }
+    }
+
+    private void checkTestSet() {
+        if (this.tests.isEmpty()) {
+            throw new RuntimeException("test list are not set");
+        }
+    }
+
+    public String getLogDir() {
+        return this.logDir;
+    }
+
+    public String getDate() {
+        return this.date;
+    }
+
+    public String getTemplateDir() {
+        return this.templateDir;
+    }
+
+    public String getReportDir() {
+        return this.reportDir;
+    }
+
+    public Set<String> getTests() {
+        return this.tests;
+    }
+}
diff -r e5efba84dc1c -r ff6efa8d997f src/org/RhinoTests/Reporter/FileUtils.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/RhinoTests/Reporter/FileUtils.java	Mon Jul 02 11:08:50 2012 +0200
@@ -0,0 +1,251 @@
+/*
+  Rhino test framework
+
+   Copyright (C) 2011, 2012  Red Hat
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+
+package org.RhinoTests.Reporter;
+
+
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.util.LinkedList;
+import java.util.List;
+
+
+
+/**
+ * 
+ * @author Pavel Tisnovsky
+ */
+public class FileUtils
+{
+    /**
+     * Default encoding used for all input/output operations.
+     */
+    private static final String DEFAULT_ENCODING = "UTF-8";
+
+    /**
+     * Read content of given text file and return it as list of strings. No
+     * exception is thrown during reading.
+     * 
+     * @param fileName
+     *            name of file to be read
+     * @return list of string containing content of text file
+     */
+    static List<String> readTextFile(String fileName)
+    {
+        BufferedReader reader = null;
+        List<String> out = new LinkedList<String>();
+        try
+        {
+            // try to open file for reading
+            reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), DEFAULT_ENCODING));
+            readAllLinesFromTextFile(reader, out);
+        }
+        catch (FileNotFoundException e)
+        {
+            // might happen - empty list is returned in this case
+            e.printStackTrace();
+        }
+        catch (IOException e)
+        {
+            // might happen - empty list is returned in this case
+            // make sure the list is empty
+            out.clear();
+            e.printStackTrace();
+        }
+        finally
+        {
+            closeBufferedReader(reader);
+        }
+        // return list containing content of text file
+        return out;
+    }
+
+    /**
+     * Write list of string to a file with given name. No exception is thrown
+     * during reading.
+     * 
+     * @param fileName
+     *            name of file to be read
+     * @param lines
+     *            of string containing content of text file
+     */
+    static void writeTextFile(String fileName, List<String> lines)
+    {
+        BufferedWriter fout = null;
+        try
+        {
+            fout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), DEFAULT_ENCODING));
+            // write all lines to a text file
+            writeAllLinesToTextFile(fout, lines);
+        }
+        catch (IOException e)
+        {
+            // might happen - empty list is returned in this case
+            e.printStackTrace();
+        }
+        finally
+        {
+            closeBufferedWriter(fout);
+        }
+    }
+
+    /**
+     * Write list of string to a file with given name. No exception is thrown
+     * during reading.
+     *
+     * @param reportDirectory
+     * @param string
+     * @param lines of string containing content of text file
+     */
+    static void writeTextFile(String reportDirectory, String string, List<String> lines)
+    {
+        writeTextFile(new File(reportDirectory, string), lines);
+    }
+
+    /**
+     * Write list of string to a file with given name. No exception is thrown
+     * during reading.
+     * 
+     * @param file
+     *            representing file name
+     * @param lines
+     *            of string containing content of text file
+     */
+    static void writeTextFile(File file, List<String> lines)
+    {
+        writeTextFile(file.getPath(), lines);
+    }
+
+    /**
+     * Try to close buffered reader.
+     *
+     * @param bufferedReader instance of buffered reader or null
+     */
+    private static void closeBufferedReader(BufferedReader bufferedReader)
+    {
+        // try to close the buffered reader
+        try
+        {
+            // for the easier use, it is possible to call this method with null parameter
+            if (bufferedReader != null)
+            {
+                bufferedReader.close();
+            }
+        }
+        catch (IOException e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Try to close buffered reader.
+     * 
+     * @param bufferedWriter
+     *            instance of buffered writer or null
+     */
+    private static void closeBufferedWriter(BufferedWriter bufferedWriter)
+    {
+        // try to close the buffered writer
+        try
+        {
+            // for the easier use, it is possible to call this method with null parameter
+            if (bufferedWriter != null)
+            {
+                bufferedWriter.close();
+            }
+        }
+        catch (IOException e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Read all lines from text file and add them to a list of strings.
+     * 
+     * @param bufferedReader
+     *            instance of buffered reader
+     * @param lines
+     *            list of string to be filled
+     * @throws IOException
+     *             thrown if an I/O error occurs
+     */
+    private static void readAllLinesFromTextFile(BufferedReader bufferedReader, List<String> lines) throws IOException
+    {
+        String line;
+        // read lines from a text file
+        while ((line = bufferedReader.readLine()) != null)
+        {
+            lines.add(line);
+        }
+    }
+
+    /**
+     * Write content of the list of strings to a file.
+     * 
+     * @param bufferedWriter
+     *            instance of buffered writer
+     * @param lines
+     *            list of string
+     * @throws IOException
+     *             thrown if an I/O error occurs
+     */
+    private static void writeAllLinesToTextFile(BufferedWriter bufferedWriter, List<String> lines) throws IOException
+    {
+        // for all lines
+        for (String line : lines)
+        {
+            bufferedWriter.write(line);
+            // new line character should be added after each string
+            bufferedWriter.write('\n');
+        }
+    }
+
+
+}
diff -r e5efba84dc1c -r ff6efa8d997f src/org/RhinoTests/Reporter/GraphPagesGenerator.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/RhinoTests/Reporter/GraphPagesGenerator.java	Mon Jul 02 11:08:50 2012 +0200
@@ -0,0 +1,58 @@
+/*
+  Rhino test framework
+
+   Copyright (C) 2011, 2012  Red Hat
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by



More information about the distro-pkg-dev mailing list