Add support of TeaVMProperties annotation

This commit is contained in:
Alexey Andreev 2016-02-27 16:15:52 +03:00
parent 5576275998
commit 4819eee3ef
3 changed files with 21 additions and 2 deletions

View File

@ -4,13 +4,15 @@ import static org.junit.Assert.*;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Currency; import java.util.Currency;
import java.util.Locale; import java.util.Locale;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.teavm.junit.SkipJVM; import org.teavm.junit.SkipJVM;
import org.teavm.junit.TeaVMProperties;
import org.teavm.junit.TeaVMProperty;
import org.teavm.junit.TeaVMTestRunner; import org.teavm.junit.TeaVMTestRunner;
@RunWith(TeaVMTestRunner.class) @RunWith(TeaVMTestRunner.class)
@TeaVMProperties(@TeaVMProperty(key = "java.util.Locale.available", value = "en, en_US, en_GB, ru, ru_RU"))
public class NumberFormatTest { public class NumberFormatTest {
@Test @Test
public void formatsNumber() { public void formatsNumber() {

View File

@ -21,7 +21,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD }) @Target(ElementType.TYPE)
public @interface TeaVMProperties { public @interface TeaVMProperties {
TeaVMProperty[] value(); TeaVMProperty[] value();
} }

View File

@ -32,6 +32,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -352,6 +353,10 @@ public class TeaVMTestRunner extends Runner {
new TestExceptionPlugin().install(vm); new TestExceptionPlugin().install(vm);
new TestEntryPointTransformer(runnerType.getName(), methodHolder.getReference()).install(vm); new TestEntryPointTransformer(runnerType.getName(), methodHolder.getReference()).install(vm);
Properties properties = new Properties();
applyProperties(method.getDeclaringClass(), properties);
vm.setProperties(properties);
try (Writer innerWriter = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) { try (Writer innerWriter = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) {
MethodReference exceptionMsg = new MethodReference(ExceptionHelper.class, "showException", MethodReference exceptionMsg = new MethodReference(ExceptionHelper.class, "showException",
Throwable.class, String.class); Throwable.class, String.class);
@ -367,6 +372,18 @@ public class TeaVMTestRunner extends Runner {
return result; return result;
} }
private void applyProperties(Class<?> cls, Properties result) {
if (cls.getSuperclass() != null) {
applyProperties(cls.getSuperclass(), result);
}
TeaVMProperties properties = cls.getAnnotation(TeaVMProperties.class);
if (properties != null) {
for (TeaVMProperty property : properties.value()) {
result.setProperty(property.key(), property.value());
}
}
}
private MethodDescriptor getDescriptor(Method method) { private MethodDescriptor getDescriptor(Method method) {
ValueType[] signature = Stream.concat(Arrays.stream(method.getParameterTypes()).map(ValueType::parse), ValueType[] signature = Stream.concat(Arrays.stream(method.getParameterTypes()).map(ValueType::parse),
Stream.of(ValueType.parse(method.getReturnType()))) Stream.of(ValueType.parse(method.getReturnType())))