Fixes exception with Long.toString method. Fixes incorrect getMessage

invocation from unit test runner.
This commit is contained in:
konsoletyper 2014-06-27 23:03:58 +04:00
parent 87262f2e97
commit b21e1b4dd5
4 changed files with 36 additions and 9 deletions

View File

@ -190,7 +190,7 @@ public class TLong extends TNumber implements TComparable<TLong> {
return toString(i, 2); return toString(i, 2);
} }
public TString toString(long value) { public static TString toString(long value) {
return TString.wrap(new TStringBuilder().append(value).toString()); return TString.wrap(new TStringBuilder().append(value).toString());
} }

View File

@ -0,0 +1,29 @@
/*
* 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;
/**
*
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
final class ExceptionHelper {
private ExceptionHelper() {
}
public static String showException(Throwable e) {
return e.getMessage();
}
}

View File

@ -290,10 +290,9 @@ public class TeaVMTestTool {
} }
File file = new File(outputDir, targetName); File file = new File(outputDir, targetName);
try (Writer innerWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) { try (Writer innerWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) {
MethodReference cons = new MethodReference(methodRef.getClassName(), MethodReference cons = new MethodReference(methodRef.getClassName(), "<init>", ValueType.VOID);
new MethodDescriptor("<init>", ValueType.VOID)); MethodReference exceptionMsg = new MethodReference(ExceptionHelper.class, "showException",
MethodReference exceptionMsg = new MethodReference("java.lang.Throwable", "getMessage", Throwable.class, String.class);
ValueType.object("java.lang.String"));
vm.entryPoint("initInstance", cons); vm.entryPoint("initInstance", cons);
vm.entryPoint("runTest", methodRef).withValue(0, cons.getClassName()); vm.entryPoint("runTest", methodRef).withValue(0, cons.getClassName());
vm.entryPoint("extractException", exceptionMsg); vm.entryPoint("extractException", exceptionMsg);

View File

@ -19,15 +19,14 @@ import org.teavm.dependency.*;
import org.teavm.model.ClassReader; import org.teavm.model.ClassReader;
import org.teavm.model.ClassReaderSource; import org.teavm.model.ClassReaderSource;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
import org.teavm.model.ValueType;
/** /**
* *
* @author Alexey Andreev * @author Alexey Andreev
*/ */
class TestExceptionDependency implements DependencyListener { class TestExceptionDependency implements DependencyListener {
private MethodReference getMessageRef = new MethodReference("java.lang.Throwable", "getMessage", private MethodReference getMessageRef = new MethodReference(ExceptionHelper.class, "showException",
ValueType.object("java.lang.String")); Throwable.class, String.class);
private DependencyNode allClasses; private DependencyNode allClasses;
@Override @Override
@ -59,7 +58,7 @@ class TestExceptionDependency implements DependencyListener {
@Override @Override
public void methodAchieved(DependencyAgent agent, MethodDependency method) { public void methodAchieved(DependencyAgent agent, MethodDependency method) {
if (method.getReference().equals(getMessageRef)) { if (method.getReference().equals(getMessageRef)) {
allClasses.connect(method.getVariable(0)); allClasses.connect(method.getVariable(1));
} }
} }