# HG changeset patch # User Jaroslav Tulach # Date 1458499458 -3600 # Node ID ceb231ab85f675578d3b7ad0a2be6e7dc890d355 # Parent 0267fb5bc8d59ae2b0352d4cbc6e53e5abbff5e3 Executing JUnit test inside of a Java plugin-less browser. diff -r 0267fb5bc8d5 -r ceb231ab85f6 .hgsub --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgsub Sun Mar 20 19:44:18 2016 +0100 @@ -0,0 +1,1 @@ +rt/aot-junit = [git]https://github.com/jtulach/junit.git diff -r 0267fb5bc8d5 -r ceb231ab85f6 .hgsubstate --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgsubstate Sun Mar 20 19:44:18 2016 +0100 @@ -0,0 +1,1 @@ +5621ac14942b5e1a4297ecd68ed7a2e1f9ce7bee rt/aot-junit diff -r 0267fb5bc8d5 -r ceb231ab85f6 rt/aot-nb-test/pom.xml --- a/rt/aot-nb-test/pom.xml Sun Mar 20 19:37:07 2016 +0100 +++ b/rt/aot-nb-test/pom.xml Sun Mar 20 19:44:18 2016 +0100 @@ -48,10 +48,10 @@ org-openide-util-lookup - ${project.groupId} - emul.mini - ${project.version} - test + org.apidesign.junit + junit-osgi + 4.12 + jar diff -r 0267fb5bc8d5 -r ceb231ab85f6 rt/aot-nb-test/src/main/java/org/apidesign/bck2brwsr/aot/junit/RunTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/aot-nb-test/src/main/java/org/apidesign/bck2brwsr/aot/junit/RunTest.java Sun Mar 20 19:44:18 2016 +0100 @@ -0,0 +1,71 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012-2015 Jaroslav Tulach + * + * This program 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, version 2 of the License. + * + * This program 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 this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.aot.junit; + +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; +import junit.framework.AssertionFailedError; +import junit.framework.JUnit4TestAdapter; +import junit.framework.Test; +import junit.framework.TestListener; +import junit.framework.TestResult; +import junit.textui.ResultPrinter; + +public class RunTest extends ResultPrinter { + public static void main(String... args) throws UnsupportedEncodingException { + System.err.println(run()); + } + + public static String run() throws UnsupportedEncodingException { + TestResult tr = new TestResult(); + class L implements TestListener { + StringBuilder sb = new StringBuilder(); + + @Override + public void addError(Test test, Throwable e) { + sb.append(test.toString()).append("\n"); + } + + @Override + public void addFailure(Test test, AssertionFailedError e) { + sb.append(test.toString()).append("\n");; + } + + @Override + public void endTest(Test test) { + sb.append(test.toString()).append("\n");; + } + + @Override + public void startTest(Test test) { + sb.append(test.toString()).append("\n");; + } + } + L listener = new L(); + tr.addListener(listener); + listener.sb.append("Starting the test run\n"); + JUnit4TestAdapter suite = new JUnit4TestAdapter(TestedTest.class); + suite.run(tr); + listener.sb.append("End of test run\n"); + return listener.sb.toString(); + } + + RunTest(PrintStream writer) { + super(writer); + } +} diff -r 0267fb5bc8d5 -r ceb231ab85f6 rt/aot-nb-test/src/main/java/org/apidesign/bck2brwsr/aot/junit/TestedTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/aot-nb-test/src/main/java/org/apidesign/bck2brwsr/aot/junit/TestedTest.java Sun Mar 20 19:44:18 2016 +0100 @@ -0,0 +1,32 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012-2015 Jaroslav Tulach + * + * This program 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, version 2 of the License. + * + * This program 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 this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.aot.junit; + +import org.junit.Test; +import static org.junit.Assert.fail; + +public class TestedTest { + @Test + public void ok() { + } + + @Test + public void error() { + fail("Failing"); + } +} diff -r 0267fb5bc8d5 -r ceb231ab85f6 rt/aot-nb-test/src/test/java/org/apidesign/bck2brwsr/aot/junit/test/JUnitRunTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/aot-nb-test/src/test/java/org/apidesign/bck2brwsr/aot/junit/test/JUnitRunTest.java Sun Mar 20 19:44:18 2016 +0100 @@ -0,0 +1,37 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012-2015 Jaroslav Tulach + * + * This program 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, version 2 of the License. + * + * This program 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 this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.aot.junit.test; + +import org.apidesign.bck2brwsr.aot.junit.RunTest; +import org.apidesign.bck2brwsr.vmtest.Compare; +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.testng.annotations.Factory; + +/** + * + * @author Jaroslav Tulach + */ +public class JUnitRunTest { + @Compare public String runTests() throws Exception { + return RunTest.run(); + } + + @Factory public static Object[] create() { + return VMTest.create(JUnitRunTest.class); + } +} diff -r 0267fb5bc8d5 -r ceb231ab85f6 rt/pom.xml --- a/rt/pom.xml Sun Mar 20 19:37:07 2016 +0100 +++ b/rt/pom.xml Sun Mar 20 19:44:18 2016 +0100 @@ -18,6 +18,7 @@ vm vmtest aot + aot-junit aot-nb-test