diff --git a/tests/teavm-tests.iml b/tests/teavm-tests.iml
index ee1b398d9..874da67d8 100644
--- a/tests/teavm-tests.iml
+++ b/tests/teavm-tests.iml
@@ -30,5 +30,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/ExceptionHelper.java b/tools/core/src/main/java/org/teavm/tooling/testing/ExceptionHelper.java
deleted file mode 100644
index 1977a6c7b..000000000
--- a/tools/core/src/main/java/org/teavm/tooling/testing/ExceptionHelper.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2014 Alexey Andreev.
- *
- * Licensed 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.
- */
-package org.teavm.tooling.testing;
-
-/**
- *
- * @author Alexey Andreev
- */
-final class ExceptionHelper {
- private ExceptionHelper() {
- }
-
- public static String showException(Throwable e) {
- return e.getMessage();
- }
-}
diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TeaVMTestTool.java b/tools/core/src/main/java/org/teavm/tooling/testing/TeaVMTestTool.java
deleted file mode 100644
index 2f45a4431..000000000
--- a/tools/core/src/main/java/org/teavm/tooling/testing/TeaVMTestTool.java
+++ /dev/null
@@ -1,516 +0,0 @@
-/*
- * Copyright 2014 Alexey Andreev.
- *
- * Licensed 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.
- */
-package org.teavm.tooling.testing;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.commons.io.IOUtils;
-import org.teavm.common.FiniteExecutor;
-import org.teavm.common.SimpleFiniteExecutor;
-import org.teavm.common.ThreadPoolFiniteExecutor;
-import org.teavm.debugging.information.DebugInformation;
-import org.teavm.debugging.information.DebugInformationBuilder;
-import org.teavm.javascript.EmptyRegularMethodNodeCache;
-import org.teavm.javascript.InMemoryRegularMethodNodeCache;
-import org.teavm.javascript.MethodNodeCache;
-import org.teavm.model.ClassHolder;
-import org.teavm.model.ClassHolderSource;
-import org.teavm.model.ClassHolderTransformer;
-import org.teavm.model.CopyClassHolderSource;
-import org.teavm.model.InMemoryProgramCache;
-import org.teavm.model.MethodHolder;
-import org.teavm.model.MethodReference;
-import org.teavm.model.PreOptimizingClassHolderSource;
-import org.teavm.model.ProgramCache;
-import org.teavm.parsing.ClasspathClassHolderSource;
-import org.teavm.testing.JUnitTestAdapter;
-import org.teavm.testing.TestAdapter;
-import org.teavm.tooling.BaseTeaVMTool;
-import org.teavm.tooling.EmptyTeaVMToolLog;
-import org.teavm.tooling.TeaVMProblemRenderer;
-import org.teavm.tooling.TeaVMToolException;
-import org.teavm.tooling.TeaVMToolLog;
-import org.teavm.tooling.sources.SourceFileProvider;
-import org.teavm.tooling.sources.SourceFilesCopier;
-import org.teavm.vm.DirectoryBuildTarget;
-import org.teavm.vm.TeaVM;
-import org.teavm.vm.TeaVMBuilder;
-
-/**
- *
- * @author Alexey Andreev
- */
-public class TeaVMTestTool implements BaseTeaVMTool {
- private File outputDir = new File(".");
- private boolean minifying = true;
- private int numThreads = 1;
- private TestAdapter adapter = new JUnitTestAdapter();
- private List transformers = new ArrayList<>();
- private List additionalScripts = new ArrayList<>();
- private List additionalScriptLocalPaths = new ArrayList<>();
- private Properties properties = new Properties();
- private List testClasses = new ArrayList<>();
- private ClassLoader classLoader = TeaVMTestTool.class.getClassLoader();
- private TeaVMToolLog log = new EmptyTeaVMToolLog();
- private boolean debugInformationGenerated;
- private boolean sourceMapsFileGenerated;
- private boolean sourceFilesCopied;
- private boolean incremental;
- private List sourceFileProviders = new ArrayList<>();
- private MethodNodeCache astCache;
- private ProgramCache programCache;
- private SourceFilesCopier sourceFilesCopier;
- private List testPlan = new ArrayList<>();
- private int fileIndexGenerator;
- private long startTime;
- private int testCount;
- private AtomicInteger testsBuilt = new AtomicInteger();
-
- public File getOutputDir() {
- return outputDir;
- }
-
- @Override
- public void setTargetDirectory(File outputDir) {
- this.outputDir = outputDir;
- }
-
- public boolean isMinifying() {
- return minifying;
- }
-
- @Override
- public void setMinifying(boolean minifying) {
- this.minifying = minifying;
- }
-
- public int getNumThreads() {
- return numThreads;
- }
-
- public void setNumThreads(int numThreads) {
- this.numThreads = numThreads;
- }
-
- public TestAdapter getAdapter() {
- return adapter;
- }
-
- public void setAdapter(TestAdapter adapter) {
- this.adapter = adapter;
- }
-
- @Override
- public List getTransformers() {
- return transformers;
- }
-
- public List getAdditionalScripts() {
- return additionalScripts;
- }
-
- @Override
- public Properties getProperties() {
- return properties;
- }
-
- public List getTestClasses() {
- return testClasses;
- }
-
- public ClassLoader getClassLoader() {
- return classLoader;
- }
-
- @Override
- public void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
- }
-
- public TeaVMToolLog getLog() {
- return log;
- }
-
- @Override
- public void setLog(TeaVMToolLog log) {
- this.log = log;
- }
-
- public boolean isIncremental() {
- return incremental;
- }
-
- @Override
- public void setIncremental(boolean incremental) {
- this.incremental = incremental;
- }
-
- public boolean isDebugInformationGenerated() {
- return debugInformationGenerated;
- }
-
- @Override
- public void setDebugInformationGenerated(boolean debugInformationGenerated) {
- this.debugInformationGenerated = debugInformationGenerated;
- }
-
- public boolean isSourceMapsFileGenerated() {
- return sourceMapsFileGenerated;
- }
-
- @Override
- public void setSourceMapsFileGenerated(boolean sourceMapsFileGenerated) {
- this.sourceMapsFileGenerated = sourceMapsFileGenerated;
- }
-
- public boolean isSourceFilesCopied() {
- return sourceFilesCopied;
- }
-
- @Override
- public void setSourceFilesCopied(boolean sourceFilesCopied) {
- this.sourceFilesCopied = sourceFilesCopied;
- }
-
- @Override
- public void addSourceFileProvider(SourceFileProvider sourceFileProvider) {
- sourceFileProviders.add(sourceFileProvider);
- }
-
- public TestPlan generate() throws TeaVMToolException {
- testsBuilt.set(0);
- Runnable finalizer = null;
- try {
- new File(outputDir, "tests").mkdirs();
- new File(outputDir, "res").mkdirs();
- resourceToFile("org/teavm/javascript/runtime.js", "res/runtime.js");
- String prefix = "org/teavm/tooling/test";
- resourceToFile(prefix + "/res/junit-support.js", "res/junit-support.js");
- resourceToFile(prefix + "/res/junit-client.js", "res/junit-client.js");
- resourceToFile(prefix + "/res/junit.css", "res/junit.css");
- resourceToFile(prefix + "/res/class_obj.png", "res/class_obj.png");
- resourceToFile(prefix + "/res/control-000-small.png", "res/control-000-small.png");
- resourceToFile(prefix + "/res/methpub_obj.png", "res/methpub_obj.png");
- resourceToFile(prefix + "/res/package_obj.png", "res/package_obj.png");
- resourceToFile(prefix + "/res/tick-small-red.png", "res/tick-small-red.png");
- resourceToFile(prefix + "/res/tick-small.png", "res/tick-small.png");
- resourceToFile(prefix + "/res/toggle-small-expand.png", "res/toggle-small-expand.png");
- resourceToFile(prefix + "/res/toggle-small.png", "res/toggle-small.png");
- resourceToFile(prefix + "/junit.html", "junit.html");
- resourceToFile(prefix + "/junit-client.html", "junit-client.html");
- ClassHolderSource classSource = new ClasspathClassHolderSource(classLoader);
- if (incremental) {
- classSource = new PreOptimizingClassHolderSource(classSource);
- }
-
- List groups = new ArrayList<>();
- for (String testClass : testClasses) {
- ClassHolder classHolder = classSource.get(testClass);
- if (classHolder == null) {
- throw new TeaVMToolException("Could not find class " + testClass);
- }
- TestGroup group = findTests(classHolder);
- if (group != null) {
- groups.add(group);
- }
- }
-
- includeAdditionalScripts(classLoader);
- astCache = new EmptyRegularMethodNodeCache();
- if (incremental) {
- astCache = new InMemoryRegularMethodNodeCache();
- programCache = new InMemoryProgramCache();
- }
- writeMetadata();
-
- FiniteExecutor executor = new SimpleFiniteExecutor();
- if (numThreads != 1) {
- int threads = numThreads != 0 ? numThreads : Runtime.getRuntime().availableProcessors();
- ThreadPoolFiniteExecutor threadedExecutor = new ThreadPoolFiniteExecutor(threads);
- finalizer = threadedExecutor::stop;
- executor = threadedExecutor;
- }
- startTime = System.currentTimeMillis();
- int methodsGenerated = writeMethods(executor, classSource);
-
- if (sourceFilesCopied) {
- sourceFilesCopier.copy(new File(new File(outputDir, "tests"), "src"));
- }
- long timeSpent = System.currentTimeMillis() - startTime;
- log.info("Test files successfully generated for " + methodsGenerated + " method(s) in "
- + (timeSpent / 1000.0) + " seconds.");
-
- return new TestPlan("res/runtime.js", groups);
- } catch (IOException e) {
- throw new TeaVMToolException("IO error occured generating JavaScript files", e);
- } finally {
- if (finalizer != null) {
- finalizer.run();
- }
- }
- }
-
- private void writeMetadata() throws IOException {
- File allTestsFile = new File(outputDir, "tests/all.js");
- try (Writer allTestsWriter = new OutputStreamWriter(new FileOutputStream(allTestsFile), "UTF-8")) {
- allTestsWriter.write("prepare = function() {\n");
- allTestsWriter.write(" return new JUnitServer(document.body).readTests([");
- boolean first = true;
- for (TestClassBuilder testClass : testPlan) {
- if (!first) {
- allTestsWriter.append(",");
- }
- first = false;
- allTestsWriter.append("\n { name : \"").append(testClass.getClassName())
- .append("\", methods : [");
- boolean firstMethod = true;
- for (TestMethodBuilder testMethod : testClass.getMethods()) {
- String scriptName = testMethod.getFileName();
- if (!firstMethod) {
- allTestsWriter.append(",");
- }
- firstMethod = false;
- allTestsWriter.append("\n { name : \"" + testMethod.getMethod().getName()
- + "\", script : \"" + scriptName + "\", expected : [");
- boolean firstException = true;
- for (String exception : testMethod.getExpectedExceptions()) {
- if (!firstException) {
- allTestsWriter.append(", ");
- }
- firstException = false;
- allTestsWriter.append("\"" + exception + "\"");
- }
- allTestsWriter.append("], additionalScripts : [");
- for (int i = 0; i < additionalScriptLocalPaths.size(); ++i) {
- if (i > 0) {
- allTestsWriter.append(", ");
- }
- escapeString(additionalScriptLocalPaths.get(i), allTestsWriter);
- }
- allTestsWriter.append("] }");
- }
- allTestsWriter.append("] }");
- }
- allTestsWriter.write("], function() {}); }");
- }
- }
-
- private int writeMethods(FiniteExecutor executor, ClassHolderSource classSource) {
- int methodsGenerated = 0;
- log.info("Generating test files");
- sourceFilesCopier = new SourceFilesCopier(sourceFileProviders);
- sourceFilesCopier.setLog(log);
- for (TestClassBuilder testClass : testPlan) {
- for (TestMethodBuilder testMethod : testClass.getMethods()) {
- executor.execute(() -> {
- log.debug("Building test for " + testMethod.getMethod());
- try {
- decompileClassesForTest(classLoader, new CopyClassHolderSource(classSource),
- testMethod);
- } catch (IOException e) {
- log.error("Error generating JavaScript", e);
- }
- });
- ++methodsGenerated;
- }
- }
- executor.complete();
- return methodsGenerated;
- }
-
- private void resourceToFile(String resource, String fileName) throws IOException {
- try (InputStream input = TeaVMTestTool.class.getClassLoader().getResourceAsStream(resource)) {
- try (OutputStream output = new FileOutputStream(new File(outputDir, fileName))) {
- IOUtils.copy(input, output);
- }
- }
- }
-
- private TestGroup findTests(ClassHolder cls) {
- List cases = new ArrayList<>();
- TestClassBuilder testClass = new TestClassBuilder(cls.getName());
- for (MethodHolder method : cls.getMethods()) {
- if (adapter.acceptMethod(method)) {
- MethodReference ref = new MethodReference(cls.getName(), method.getDescriptor());
- String fileName = "tests/" + fileIndexGenerator++ + ".js";
-
- List exceptions = new ArrayList<>();
- for (String exception : adapter.getExpectedExceptions(method)) {
- exceptions.add(exception);
- }
-
- String runner = adapter.getRunner(method).getName();
-
- TestMethodBuilder testMethod = new TestMethodBuilder(ref, fileName, exceptions, runner);
- testClass.getMethods().add(testMethod);
-
- String debugTable = debugInformationGenerated ? testMethod.getFileName() + ".teavmdbg" : null;
- cases.add(new TestCase(ref.toString(), testMethod.getFileName(), debugTable,
- testMethod.getExpectedExceptions(), runner));
- ++testCount;
- }
- }
- if (!testClass.getMethods().isEmpty()) {
- testPlan.add(testClass);
- return new TestGroup(cls.getName(), cases);
- } else {
- return null;
- }
- }
-
- private void includeAdditionalScripts(ClassLoader classLoader) throws TeaVMToolException {
- if (additionalScripts == null) {
- return;
- }
- for (String script : additionalScripts) {
- String simpleName = script.substring(script.lastIndexOf('/') + 1);
- additionalScriptLocalPaths.add("tests/" + simpleName);
- if (classLoader.getResource(script) == null) {
- throw new TeaVMToolException("Additional script " + script + " was not found");
- }
- File file = new File(outputDir, "tests/" + simpleName);
- try (InputStream in = classLoader.getResourceAsStream(script)) {
- if (!file.exists()) {
- file.createNewFile();
- }
- try (OutputStream out = new FileOutputStream(file)) {
- IOUtils.copy(in, out);
- }
- } catch (IOException e) {
- throw new TeaVMToolException("Error copying additional script " + script, e);
- }
- }
- }
-
- private void decompileClassesForTest(ClassLoader classLoader, ClassHolderSource classSource,
- TestMethodBuilder testMethod) throws IOException {
- String targetName = testMethod.getFileName();
- TeaVM vm = new TeaVMBuilder()
- .setClassLoader(classLoader)
- .setClassSource(classSource)
- .build();
- vm.setIncremental(incremental);
- vm.setAstCache(astCache);
- vm.setProgramCache(programCache);
- vm.setProperties(properties);
- vm.setMinifying(minifying);
- vm.installPlugins();
- new TestExceptionPlugin().install(vm);
- new TestEntryPointTransformer(testMethod.getRunner(), testMethod.getMethod()).install(vm);
- for (ClassHolderTransformer transformer : transformers) {
- vm.add(transformer);
- }
-
- File file = new File(outputDir, testMethod.getFileName());
- DebugInformationBuilder debugInfoBuilder = sourceMapsFileGenerated || debugInformationGenerated
- ? new DebugInformationBuilder() : null;
- MethodReference methodRef = testMethod.getMethod();
- try (Writer innerWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) {
- MethodReference exceptionMsg = new MethodReference(ExceptionHelper.class, "showException",
- Throwable.class, String.class);
- vm.entryPoint("runTest", new MethodReference(TestEntryPoint.class, "run", void.class)).async();
- vm.entryPoint("extractException", exceptionMsg);
- vm.setDebugEmitter(debugInfoBuilder);
- vm.build(innerWriter, new DirectoryBuildTarget(outputDir));
- innerWriter.append("\n");
- innerWriter.append("\nJUnitClient.run();");
- if (sourceMapsFileGenerated) {
- String sourceMapsFileName = targetName.substring(targetName.lastIndexOf('/') + 1) + ".map";
- innerWriter.append("\n//# sourceMappingURL=").append(sourceMapsFileName);
- }
- if (!vm.getProblemProvider().getProblems().isEmpty()) {
- if (vm.getProblemProvider().getSevereProblems().isEmpty()) {
- log.warning("Test built with warnings: " + methodRef);
- TeaVMProblemRenderer.describeProblems(vm, log);
- } else {
- log.warning("Test built with errors: " + methodRef);
- TeaVMProblemRenderer.describeProblems(vm, log);
- }
- }
- }
-
- if (debugInformationGenerated) {
- DebugInformation debugInfo = debugInfoBuilder.getDebugInformation();
- File debugTableFile = new File(outputDir, targetName + ".teavmdbg");
- try (OutputStream debugInfoOut = new FileOutputStream(debugTableFile)) {
- debugInfo.write(debugInfoOut);
- }
- }
-
- if (sourceMapsFileGenerated) {
- DebugInformation debugInfo = debugInfoBuilder.getDebugInformation();
- String sourceMapsFileName = targetName + ".map";
- try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(
- new File(outputDir, sourceMapsFileName)), "UTF-8")) {
- debugInfo.writeAsSourceMaps(sourceMapsOut, "src", targetName);
- }
- }
- if (sourceFilesCopied && vm.getWrittenClasses() != null) {
- sourceFilesCopier.addClasses(vm.getWrittenClasses());
- }
-
- incrementCounter();
- }
-
- private void incrementCounter() {
- int count = testsBuilt.incrementAndGet();
- if (count % 10 != 0) {
- return;
- }
-
- long timeSpent = System.currentTimeMillis() - startTime;
-
- getLog().info(count + " of " + testCount + " tests built in " + (timeSpent / 1000.0) + " seconds ("
- + String.format("%.2f", (double) count / timeSpent * 1000.0) + " tests per second avg.)");
- }
-
- private void escapeString(String string, Writer writer) throws IOException {
- writer.append('\"');
- for (int i = 0; i < string.length(); ++i) {
- char c = string.charAt(i);
- switch (c) {
- case '"':
- writer.append("\\\"");
- break;
- case '\\':
- writer.append("\\\\");
- break;
- case '\n':
- writer.append("\\n");
- break;
- case '\r':
- writer.append("\\r");
- break;
- case '\t':
- writer.append("\\t");
- break;
- default:
- writer.append(c);
- break;
- }
- }
- writer.append('\"');
- }
-}
diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TestCase.java b/tools/core/src/main/java/org/teavm/tooling/testing/TestCase.java
deleted file mode 100644
index 825b46752..000000000
--- a/tools/core/src/main/java/org/teavm/tooling/testing/TestCase.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2015 Alexey Andreev.
- *
- * Licensed 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.
- */
-package org.teavm.tooling.testing;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- *
- * @author Alexey Andreev
- */
-public class TestCase {
- private String testMethod;
- private String testScript;
- private String debugTable;
- private List expectedExceptions = new ArrayList<>();
- private String runner;
-
- @JsonCreator
- public TestCase(
- @JsonProperty("testMethod") String testMethod,
- @JsonProperty("script") String testScript,
- @JsonProperty("debugTable") String debugTable,
- @JsonProperty("expectedExceptions") List expectedExceptions,
- @JsonProperty("runner") String runner) {
- this.testMethod = testMethod;
- this.testScript = testScript;
- this.debugTable = debugTable;
- this.expectedExceptions = Collections.unmodifiableList(new ArrayList<>(expectedExceptions));
- this.runner = runner;
- }
-
- @JsonGetter
- public String getTestMethod() {
- return testMethod;
- }
-
- @JsonGetter("script")
- public String getTestScript() {
- return testScript;
- }
-
- @JsonGetter
- public String getDebugTable() {
- return debugTable;
- }
-
- @JsonGetter
- public List getExpectedExceptions() {
- return expectedExceptions;
- }
-
- @JsonGetter
- public String getRunner() {
- return runner;
- }
-}
diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TestClassBuilder.java b/tools/core/src/main/java/org/teavm/tooling/testing/TestClassBuilder.java
deleted file mode 100644
index d50e2b264..000000000
--- a/tools/core/src/main/java/org/teavm/tooling/testing/TestClassBuilder.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2015 Alexey Andreev.
- *
- * Licensed 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.
- */
-package org.teavm.tooling.testing;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- *
- * @author Alexey Andreev
- */
-class TestClassBuilder {
- private String className;
- private List methods = new ArrayList<>();
-
- public TestClassBuilder(String className) {
- this.className = className;
- }
-
- public String getClassName() {
- return className;
- }
-
- public List getMethods() {
- return methods;
- }
-}
diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPoint.java b/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPoint.java
deleted file mode 100644
index 5208d78ab..000000000
--- a/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPoint.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2015 Alexey Andreev.
- *
- * Licensed 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.
- */
-package org.teavm.tooling.testing;
-
-import org.teavm.testing.TestRunner;
-
-/**
- *
- * @author Alexey Andreev
- */
-final class TestEntryPoint {
- private static Object testCase;
-
- private TestEntryPoint() {
- }
-
- public static void run() throws Throwable {
- createRunner().run(() -> launchTest());
- }
-
- private static native TestRunner createRunner();
-
- private static native void launchTest();
-}
diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPointTransformer.java b/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPointTransformer.java
deleted file mode 100644
index 914c60844..000000000
--- a/tools/core/src/main/java/org/teavm/tooling/testing/TestEntryPointTransformer.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2015 Alexey Andreev.
- *
- * Licensed 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.
- */
-package org.teavm.tooling.testing;
-
-import org.teavm.diagnostics.Diagnostics;
-import org.teavm.model.ClassHolder;
-import org.teavm.model.ClassHolderTransformer;
-import org.teavm.model.ClassReaderSource;
-import org.teavm.model.ElementModifier;
-import org.teavm.model.MethodHolder;
-import org.teavm.model.MethodReference;
-import org.teavm.model.Program;
-import org.teavm.model.ValueType;
-import org.teavm.model.emit.ProgramEmitter;
-import org.teavm.model.emit.ValueEmitter;
-import org.teavm.vm.spi.TeaVMHost;
-import org.teavm.vm.spi.TeaVMPlugin;
-
-/**
- *
- * @author Alexey Andreev
- */
-class TestEntryPointTransformer implements ClassHolderTransformer, TeaVMPlugin {
- private String runnerClassName;
- private MethodReference testMethod;
-
- public TestEntryPointTransformer(String runnerClassName, MethodReference testMethod) {
- this.runnerClassName = runnerClassName;
- this.testMethod = testMethod;
- }
-
- @Override
- public void install(TeaVMHost host) {
- host.add(this);
- }
-
- @Override
- public void transformClass(ClassHolder cls, ClassReaderSource innerSource, Diagnostics diagnostics) {
- if (cls.getName().equals(TestEntryPoint.class.getName())) {
- for (MethodHolder method : cls.getMethods()) {
- if (method.getName().equals("createRunner")) {
- method.setProgram(generateRunnerProgram(method, innerSource));
- method.getModifiers().remove(ElementModifier.NATIVE);
- } else if (method.getName().equals("launchTest")) {
- method.setProgram(generateLaunchProgram(method, innerSource));
- method.getModifiers().remove(ElementModifier.NATIVE);
- }
- }
- }
- }
-
- private Program generateRunnerProgram(MethodHolder method, ClassReaderSource innerSource) {
- ProgramEmitter pe = ProgramEmitter.create(method, innerSource);
- pe.construct(runnerClassName).returnValue();
- return pe.getProgram();
- }
-
- private Program generateLaunchProgram(MethodHolder method, ClassReaderSource innerSource) {
- ProgramEmitter pe = ProgramEmitter.create(method, innerSource);
- ValueEmitter testCaseVar = pe.getField(TestEntryPoint.class, "testCase", Object.class);
- pe.when(testCaseVar.isNull())
- .thenDo(() -> {
- pe.setField(TestEntryPoint.class, "testCase",
- pe.construct(testMethod.getClassName()).cast(Object.class));
- });
- pe.getField(TestEntryPoint.class, "testCase", Object.class)
- .cast(ValueType.object(testMethod.getClassName()))
- .invokeSpecial(testMethod);
- pe.exit();
- return pe.getProgram();
- }
-}
diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TestExceptionDependency.java b/tools/core/src/main/java/org/teavm/tooling/testing/TestExceptionDependency.java
deleted file mode 100644
index e388e80f6..000000000
--- a/tools/core/src/main/java/org/teavm/tooling/testing/TestExceptionDependency.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2014 Alexey Andreev.
- *
- * Licensed 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.
- */
-package org.teavm.tooling.testing;
-
-import org.teavm.dependency.AbstractDependencyListener;
-import org.teavm.dependency.DependencyAgent;
-import org.teavm.dependency.DependencyNode;
-import org.teavm.dependency.MethodDependency;
-import org.teavm.model.CallLocation;
-import org.teavm.model.ClassReader;
-import org.teavm.model.ClassReaderSource;
-import org.teavm.model.MethodReference;
-
-/**
- *
- * @author Alexey Andreev
- */
-class TestExceptionDependency extends AbstractDependencyListener {
- private MethodReference getMessageRef = new MethodReference(ExceptionHelper.class, "showException",
- Throwable.class, String.class);
- private DependencyNode allClasses;
-
- @Override
- public void started(DependencyAgent agent) {
- allClasses = agent.createNode();
- }
-
- @Override
- public void classReached(DependencyAgent agent, String className, CallLocation location) {
- if (isException(agent.getClassSource(), className)) {
- allClasses.propagate(agent.getType(className));
- }
- }
-
- private boolean isException(ClassReaderSource classSource, String className) {
- while (className != null) {
- if (className.equals("java.lang.Throwable")) {
- return true;
- }
- ClassReader cls = classSource.get(className);
- if (cls == null) {
- return false;
- }
- className = cls.getParent();
- }
- return false;
- }
-
- @Override
- public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
- if (method.getReference().equals(getMessageRef)) {
- allClasses.connect(method.getVariable(1));
- }
- }
-}
diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TestExceptionPlugin.java b/tools/core/src/main/java/org/teavm/tooling/testing/TestExceptionPlugin.java
deleted file mode 100644
index 19a2c04a1..000000000
--- a/tools/core/src/main/java/org/teavm/tooling/testing/TestExceptionPlugin.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2014 Alexey Andreev.
- *
- * Licensed 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.
- */
-package org.teavm.tooling.testing;
-
-import org.teavm.vm.spi.TeaVMHost;
-import org.teavm.vm.spi.TeaVMPlugin;
-
-/**
- *
- * @author Alexey Andreev
- */
-class TestExceptionPlugin implements TeaVMPlugin {
- @Override
- public void install(TeaVMHost host) {
- host.add(new TestExceptionDependency());
- }
-}
diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TestGroup.java b/tools/core/src/main/java/org/teavm/tooling/testing/TestGroup.java
deleted file mode 100644
index 4ab9d5cbb..000000000
--- a/tools/core/src/main/java/org/teavm/tooling/testing/TestGroup.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2015 Alexey Andreev.
- *
- * Licensed 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.
- */
-package org.teavm.tooling.testing;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- *
- * @author Alexey Andreev
- */
-public class TestGroup {
- private String className;
- private List testCases;
-
- @JsonCreator
- public TestGroup(@JsonProperty("className") String className,
- @JsonProperty("testCases") List testCases) {
- this.className = className;
- this.testCases = Collections.unmodifiableList(new ArrayList<>(testCases));
- }
-
- @JsonGetter("className")
- public String getClassName() {
- return className;
- }
-
- @JsonGetter("testCases")
- public List getTestCases() {
- return testCases;
- }
-}
diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TestMethodBuilder.java b/tools/core/src/main/java/org/teavm/tooling/testing/TestMethodBuilder.java
deleted file mode 100644
index 9f81a41f6..000000000
--- a/tools/core/src/main/java/org/teavm/tooling/testing/TestMethodBuilder.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2015 Alexey Andreev.
- *
- * Licensed 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.
- */
-package org.teavm.tooling.testing;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import org.teavm.model.MethodReference;
-
-/**
- *
- * @author Alexey Andreev
- */
-class TestMethodBuilder {
- private MethodReference method;
- private String fileName;
- private List expectedExceptions = new ArrayList<>();
- private String runner;
-
- public TestMethodBuilder(MethodReference method, String fileName, List expectedExceptions,
- String runner) {
- this.method = method;
- this.fileName = fileName;
- this.expectedExceptions = Collections.unmodifiableList(new ArrayList<>(expectedExceptions));
- this.runner = runner;
- }
-
- public MethodReference getMethod() {
- return method;
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public List getExpectedExceptions() {
- return expectedExceptions;
- }
-
- public String getRunner() {
- return runner;
- }
-}
diff --git a/tools/core/src/main/java/org/teavm/tooling/testing/TestPlan.java b/tools/core/src/main/java/org/teavm/tooling/testing/TestPlan.java
deleted file mode 100644
index 32ce4b364..000000000
--- a/tools/core/src/main/java/org/teavm/tooling/testing/TestPlan.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2015 Alexey Andreev.
- *
- * Licensed 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.
- */
-package org.teavm.tooling.testing;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- *
- * @author Alexey Andreev
- */
-public class TestPlan {
- private String runtimeScript;
- private List groups = new ArrayList<>();
-
- @JsonCreator
- public TestPlan(
- @JsonProperty("runtimeScript") String runtimeScript,
- @JsonProperty("groups") List groups) {
- this.runtimeScript = runtimeScript;
- this.groups = Collections.unmodifiableList(new ArrayList<>(groups));
- }
-
- @JsonGetter
- public String getRuntimeScript() {
- return runtimeScript;
- }
-
- @JsonGetter
- public List getGroups() {
- return groups;
- }
-}
diff --git a/tools/junit/pom.xml b/tools/junit/pom.xml
index d4959089d..e22e24331 100644
--- a/tools/junit/pom.xml
+++ b/tools/junit/pom.xml
@@ -38,6 +38,23 @@
teavm-tooling
${project.version}
+
+ org.seleniumhq.selenium
+ selenium-java
+
+
+ org.seleniumhq.selenium
+ selenium-remote-driver
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
+
+ net.sourceforge.htmlunit
+ htmlunit
+ 2.18
+
diff --git a/tools/maven/plugin/src/main/java/org/teavm/maven/HtmlUnitRunStrategy.java b/tools/junit/src/main/java/org/teavm/junit/HtmlUnitRunStrategy.java
similarity index 81%
rename from tools/maven/plugin/src/main/java/org/teavm/maven/HtmlUnitRunStrategy.java
rename to tools/junit/src/main/java/org/teavm/junit/HtmlUnitRunStrategy.java
index 0b7b24a57..7265ff1d3 100644
--- a/tools/maven/plugin/src/main/java/org/teavm/maven/HtmlUnitRunStrategy.java
+++ b/tools/junit/src/main/java/org/teavm/junit/HtmlUnitRunStrategy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Alexey Andreev.
+ * Copyright 2016 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.teavm.maven;
+package org.teavm.junit;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
@@ -28,20 +28,8 @@ import java.util.concurrent.TimeUnit;
import net.sourceforge.htmlunit.corejs.javascript.Function;
import net.sourceforge.htmlunit.corejs.javascript.NativeJavaObject;
import org.apache.commons.io.IOUtils;
-import org.apache.maven.plugin.logging.Log;
-import org.teavm.tooling.testing.TestCase;
-/**
- *
- * @author Alexey Andreev
- */
public class HtmlUnitRunStrategy implements TestRunStrategy {
- private File directory;
-
- public HtmlUnitRunStrategy(File directory) {
- this.directory = directory;
- }
-
@Override
public void beforeThread() {
}
@@ -51,10 +39,10 @@ public class HtmlUnitRunStrategy implements TestRunStrategy {
}
@Override
- public String runTest(Log log, String runtimeScript, TestCase testCase) throws IOException {
+ public String runTest(TestRun run) throws IOException {
try (WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
HtmlPage page = webClient.getPage("about:blank");
- page.executeJavaScript(readFile(new File(directory, runtimeScript)));
+ page.executeJavaScript(readFile(new File(run.getBaseDirectory(), "runtime.js")));
AsyncResult asyncResult = new AsyncResult();
Function function = (Function) page.executeJavaScript(readResource("teavm-htmlunit-adapter.js"))
@@ -62,7 +50,7 @@ public class HtmlUnitRunStrategy implements TestRunStrategy {
Object[] args = new Object[] { new NativeJavaObject(function, asyncResult, AsyncResult.class) };
page.executeJavaScriptFunctionIfPossible(function, function, args, page);
- page.executeJavaScript(readFile(new File(directory, testCase.getTestScript())));
+ page.executeJavaScript(readFile(new File(run.getBaseDirectory(), "test.js")));
page.cleanUp();
for (WebWindow window : webClient.getWebWindows()) {
window.getJobManager().removeAllJobs();
@@ -78,7 +66,7 @@ public class HtmlUnitRunStrategy implements TestRunStrategy {
}
private String readResource(String resourceName) throws IOException {
- try (InputStream input = BuildJavascriptTestMojo.class.getClassLoader().getResourceAsStream(resourceName)) {
+ try (InputStream input = HtmlUnitRunStrategy.class.getClassLoader().getResourceAsStream(resourceName)) {
if (input == null) {
return "";
}
diff --git a/tools/maven/plugin/src/main/java/org/teavm/maven/SeleniumRunStrategy.java b/tools/junit/src/main/java/org/teavm/junit/SeleniumRunStrategy.java
similarity index 76%
rename from tools/maven/plugin/src/main/java/org/teavm/maven/SeleniumRunStrategy.java
rename to tools/junit/src/main/java/org/teavm/junit/SeleniumRunStrategy.java
index fdaeac6ed..6c3f7d8cb 100644
--- a/tools/maven/plugin/src/main/java/org/teavm/maven/SeleniumRunStrategy.java
+++ b/tools/junit/src/main/java/org/teavm/junit/SeleniumRunStrategy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Alexey Andreev.
+ * Copyright 2016 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.teavm.maven;
+package org.teavm.junit;
import java.io.File;
import java.io.FileInputStream;
@@ -23,27 +23,18 @@ import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
-import org.apache.maven.plugin.logging.Log;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
-import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
-import org.teavm.tooling.testing.TestCase;
-/**
- *
- * @author Alexey Andreev
- */
public class SeleniumRunStrategy implements TestRunStrategy {
private URL url;
- private File directory;
private ThreadLocal webDriver = new ThreadLocal<>();
private ThreadLocal commandsSent = new ThreadLocal<>();
- public SeleniumRunStrategy(URL url, File directory) {
+ public SeleniumRunStrategy(URL url) {
this.url = url;
- this.directory = directory;
}
@Override
@@ -61,7 +52,7 @@ public class SeleniumRunStrategy implements TestRunStrategy {
}
@Override
- public String runTest(Log log, String runtimeScript, TestCase testCase) throws IOException {
+ public String runTest(TestRun run) throws IOException {
commandsSent.set(commandsSent.get() + 1);
if (commandsSent.get().equals(20)) {
commandsSent.set(0);
@@ -75,16 +66,16 @@ public class SeleniumRunStrategy implements TestRunStrategy {
try {
return (String) js.executeAsyncScript(
readResource("teavm-selenium.js"),
- readFile(new File(directory, runtimeScript)),
- readFile(new File(directory, testCase.getTestScript())),
+ readFile(new File(run.getBaseDirectory(), "runtime.js")),
+ readFile(new File(run.getBaseDirectory(), "test.js")),
readResource("teavm-selenium-adapter.js"));
- } catch (WebDriverException e) {
- log.error("Error occured running test " + testCase.getTestMethod(), e);
+ } catch (Throwable e) {
+ run.getCallback().error(e);
@SuppressWarnings("unchecked")
List