felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsav...@apache.org
Subject svn commit: r906437 - in /felix/trunk/sigil: bldcommon/ gogo/ gogo/junit/ gogo/junit/src/ gogo/junit/src/org/ gogo/junit/src/org/apache/ gogo/junit/src/org/apache/felix/ gogo/junit/src/org/apache/felix/sigil/ gogo/junit/src/org/apache/felix/sigil/gogo/...
Date Thu, 04 Feb 2010 10:15:38 GMT
Author: dsavage
Date: Thu Feb  4 10:15:33 2010
New Revision: 906437

URL: http://svn.apache.org/viewvc?rev=906437&view=rev
Log:
add gogo cli for junit testing (FELIX-1358)

Added:
    felix/trunk/sigil/gogo/
    felix/trunk/sigil/gogo/build.xml
    felix/trunk/sigil/gogo/junit/
    felix/trunk/sigil/gogo/junit/.classpath
    felix/trunk/sigil/gogo/junit/.project
    felix/trunk/sigil/gogo/junit/build.xml
    felix/trunk/sigil/gogo/junit/ivy.xml
    felix/trunk/sigil/gogo/junit/sigil.properties
    felix/trunk/sigil/gogo/junit/src/
    felix/trunk/sigil/gogo/junit/src/org/
    felix/trunk/sigil/gogo/junit/src/org/apache/
    felix/trunk/sigil/gogo/junit/src/org/apache/felix/
    felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/
    felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/
    felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/
    felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/Activator.java
    felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/PrintListener.java
    felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/SigilJunit.java
Modified:
    felix/trunk/sigil/bldcommon/ivysettings.xml

Modified: felix/trunk/sigil/bldcommon/ivysettings.xml
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/bldcommon/ivysettings.xml?rev=906437&r1=906436&r2=906437&view=diff
==============================================================================
--- felix/trunk/sigil/bldcommon/ivysettings.xml (original)
+++ felix/trunk/sigil/bldcommon/ivysettings.xml Thu Feb  4 10:15:33 2010
@@ -91,6 +91,7 @@
     <module organisation="org.eclipse2" resolver="eclipse2"/>
     <module organisation="org.apache" name="felix\.sigil.*" matcher="regexp" resolver="default"/>
     <module organisation="org.apache" resolver="apache"/>
+    <module organisation="org.apache.ant" resolver="apache"/>
     <module organisation="biz.aQute" resolver="aQute"/>
     <module organisation="org.codehaus.groovy" resolver="apache" />
   </modules>

Added: felix/trunk/sigil/gogo/build.xml
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/gogo/build.xml?rev=906437&view=auto
==============================================================================
--- felix/trunk/sigil/gogo/build.xml (added)
+++ felix/trunk/sigil/gogo/build.xml Thu Feb  4 10:15:33 2010
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+    http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project name="gogo" default="build-list">
+  <import file="../bldcommon/common.xml"/>
+</project>

Added: felix/trunk/sigil/gogo/junit/.classpath
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/gogo/junit/.classpath?rev=906437&view=auto
==============================================================================
--- felix/trunk/sigil/gogo/junit/.classpath (added)
+++ felix/trunk/sigil/gogo/junit/.classpath Thu Feb  4 10:15:33 2010
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.apache.felix.sigil.classpathContainer"/>
+	<classpathentry kind="lib" path="lib/ant-junit-1.7.1.jar"/>
+	<classpathentry kind="output" path="build/classes"/>
+</classpath>

Added: felix/trunk/sigil/gogo/junit/.project
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/gogo/junit/.project?rev=906437&view=auto
==============================================================================
--- felix/trunk/sigil/gogo/junit/.project (added)
+++ felix/trunk/sigil/gogo/junit/.project Thu Feb  4 10:15:33 2010
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.apache.felix.sigil.gogo.junit</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.apache.felix.sigil.eclipse.core.sigilBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.apache.felix.sigil.sigilnature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: felix/trunk/sigil/gogo/junit/build.xml
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/gogo/junit/build.xml?rev=906437&view=auto
==============================================================================
--- felix/trunk/sigil/gogo/junit/build.xml (added)
+++ felix/trunk/sigil/gogo/junit/build.xml Thu Feb  4 10:15:33 2010
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+    http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project name="gogo.junit" default="build"
+  xmlns:ivy="antlib:org.apache.ivy.ant">
+  <import file="../build.xml"/>
+  <target name="init">
+  	<ivy:retrieve inline="true" organisation="org.apache.ant" module="ant-junit" revision="1.7.1"
transitive="false" />
+  </target>
+</project>

Added: felix/trunk/sigil/gogo/junit/ivy.xml
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/gogo/junit/ivy.xml?rev=906437&view=auto
==============================================================================
--- felix/trunk/sigil/gogo/junit/ivy.xml (added)
+++ felix/trunk/sigil/gogo/junit/ivy.xml Thu Feb  4 10:15:33 2010
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+    http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<ivy-module version="1.0">
+  <info 
+       organisation="org.apache"
+       module="felix.sigil.gogo.junit"
+       status="integration"/>
+  <publications>
+    <artifact name="org.apache.felix.sigil.gogo.junit" />
+  </publications>
+  
+  <dependencies>
+    <dependency org="org.apache" name="ant" rev="1.7.1">
+      <artifact name="ant-junit" type="jar" />
+    </dependency>
+  </dependencies> 
+</ivy-module>

Added: felix/trunk/sigil/gogo/junit/sigil.properties
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/gogo/junit/sigil.properties?rev=906437&view=auto
==============================================================================
--- felix/trunk/sigil/gogo/junit/sigil.properties (added)
+++ felix/trunk/sigil/gogo/junit/sigil.properties Thu Feb  4 10:15:33 2010
@@ -0,0 +1,19 @@
+
+# sigil project file, saved by plugin.
+
+version: 0.0.0
+
+-bundles: \
+	org.apache.felix.sigil.gogo.junit, \
+
+-sourcedirs: \
+	src, \
+
+-imports: \
+	junit.framework;version=4.4.0, \
+	org.apache.commons.cli;version=1.2.0, \
+	org.apache.felix.sigil.junit.server;version=0.9.0, \
+	org.apache.tools.ant;version=1.7.0, \
+	org.osgi.framework;version=1.5.0, \
+
+# end

Added: felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/Activator.java?rev=906437&view=auto
==============================================================================
--- felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/Activator.java (added)
+++ felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/Activator.java Thu
Feb  4 10:15:33 2010
@@ -0,0 +1,17 @@
+package org.apache.felix.sigil.gogo.junit;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator
+{
+
+    public void start( BundleContext ctx ) throws Exception
+    {
+    }
+
+    public void stop( BundleContext ctx ) throws Exception
+    {
+    }
+
+}

Added: felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/PrintListener.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/PrintListener.java?rev=906437&view=auto
==============================================================================
--- felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/PrintListener.java
(added)
+++ felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/PrintListener.java
Thu Feb  4 10:15:33 2010
@@ -0,0 +1,33 @@
+package org.apache.felix.sigil.gogo.junit;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestListener;
+
+public class PrintListener implements TestListener {
+
+    public PrintListener() {
+    }
+
+    public void startTest(Test test) {
+        System.out.println( "Start " + test );
+        System.out.flush();
+    }
+
+    public void endTest(Test test) {
+        System.out.println( "End " + test );
+        System.out.flush();
+    }
+
+
+    public void addError(Test test, Throwable t) {
+        System.out.println( "Error " + test );
+        t.printStackTrace(System.out);
+        System.out.flush();
+    }
+
+    public void addFailure(Test test, AssertionFailedError error) {
+        System.out.println( "Failure " + test + ": " + error.getMessage() );
+        System.out.flush();
+    }
+}

Added: felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/SigilJunit.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/SigilJunit.java?rev=906437&view=auto
==============================================================================
--- felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/SigilJunit.java (added)
+++ felix/trunk/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/SigilJunit.java Thu
Feb  4 10:15:33 2010
@@ -0,0 +1,156 @@
+package org.apache.felix.sigil.gogo.junit;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.regex.Pattern;
+
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.Parser;
+import org.apache.felix.sigil.junit.server.JUnitService;
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
+import org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter;
+
+public class SigilJunit
+{
+    private static final Options OPTIONS;
+    
+    static {
+        OPTIONS = new Options();
+        OPTIONS.addOption("d", "dir", true, "Directory to write ant test results to");
+        OPTIONS.addOption("q", "quiet", false, "Run tests quietly, i.e. don't print steps
to console" );
+    }
+    
+    private JUnitService service;
+
+    public void junit(String[] args) throws IOException, ParseException {
+        Parser p = new GnuParser();
+        CommandLine cmd = p.parse(OPTIONS, args);
+        String[] cargs = cmd.getArgs();
+        if ( cargs.length == 0 ) {
+            for ( String t : service.getTests() ) {
+                System.out.println( "\t" + t );
+                System.out.flush();
+            }
+        }
+        else {
+            boolean quiet = cmd.hasOption( 'q' );
+            String d = cmd.getOptionValue('d');
+            File dir = null;
+            if ( d != null ) {
+                dir = new File(d);
+                dir.mkdirs();
+                System.out.println( "Writing results to " + dir.getAbsolutePath() );
+                System.out.flush();
+            }
+            runTests( cargs, quiet, dir );
+        }
+    }
+    
+    private void runTests(String[] args, boolean quiet, File dir) throws IOException {
+        int count = 0;
+        int failures = 0;
+        int errors = 0;
+        for ( String t : args ) {
+            TestSuite[] tests = findTests( t );
+            if ( tests.length == 0 ) {
+                System.err.println( "No tests found for " + t );
+            }
+            else {
+                for ( TestSuite test : tests ) {
+                    TestResult result = new TestResult();
+                    if ( !quiet ) {
+                        result.addListener( new PrintListener());
+                    }
+                    
+                    JUnitTest antTest = null;
+                    FileOutputStream fout = null;
+                    XMLJUnitResultFormatter formatter = null;
+                    
+                    if ( dir != null ) {
+                        antTest = new JUnitTest(t, false, false, true);
+        
+                        formatter = new XMLJUnitResultFormatter();
+                        formatter.startTestSuite(antTest);
+        
+                        String name = "TEST-" + test.getName() + ".xml";
+                        
+                        File f = new File( dir, name );
+                        fout = new FileOutputStream( f );
+                        formatter.setOutput(fout);
+                        result.addListener(formatter);
+                    }
+                    
+                    test.run(result);
+                    
+                    if ( dir != null ) {
+                        antTest.setCounts(result.runCount(), result.failureCount(), result.errorCount());
+                        formatter.endTestSuite(antTest);
+                        fout.flush();
+                        fout.close();
+                    }
+                    count += result.runCount();
+                    failures += result.failureCount();
+                    errors += result.errorCount();
+                }
+            }
+        }
+        
+        System.out.println( "Ran " + count + " tests. " + failures + " failures " + errors
+ " errors." );
+        System.out.flush();
+    }
+
+    private TestSuite[] findTests(String t) {
+        if ( t.contains("*" ) ) {
+            Pattern p = compile(t);
+            LinkedList<TestSuite> tests = new LinkedList<TestSuite>();
+            for ( String n : service.getTests() ) {
+                if ( p.matcher(n).matches() ) {
+                    tests.add( service.createTest(n) );
+                }
+            }
+            return tests.toArray( new TestSuite[tests.size()] );
+        }
+        else {
+            TestSuite test = service.createTest(t);
+            return test == null ? new TestSuite[0] : new TestSuite[] { test };
+        }
+    }
+
+    public static final Pattern compile(String glob) {
+        char[] chars = glob.toCharArray();
+        if ( chars.length > 0 ) {
+            StringBuilder builder = new StringBuilder(chars.length + 5);
+    
+            builder.append('^');
+            
+            for (char c : chars) {
+                switch ( c ) {
+                case '*':
+                    builder.append(".*");
+                    break;
+                case '.':
+                    builder.append("\\.");
+                    break;
+                case '$':
+                    builder.append( "\\$" );
+                    break;
+                default:
+                    builder.append( c );
+                }
+            }
+    
+            return Pattern.compile(builder.toString());
+        }
+        else {
+            return Pattern.compile(glob);
+        }
+    }    
+}



Mime
View raw message