diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestUtil.java b/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestUtil.java index 6fc24ca8a9b..e3b273cb34a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestUtil.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestUtil.java @@ -17,9 +17,7 @@ package org.jetbrains.kotlin.codegen; import com.google.common.base.Function; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.intellij.openapi.util.SystemInfo; import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -111,14 +109,6 @@ public class CodegenTestUtil { return null; } - public static void assertIsCurrentTime(long returnValue) { - long currentTime = System.currentTimeMillis(); - long diff = Math.abs(returnValue - currentTime); - long toleratedDifference = SystemInfo.isWindows ? 15 : 1; - assertTrue("Difference with current time: " + diff + " (this test is a bad one: it may fail even if the generated code is correct)", - diff <= toleratedDifference); - } - @NotNull public static File compileJava(@NotNull String filename, @NotNull String... additionalClasspath) { return compileJava(Collections.singletonList(filename), additionalClasspath); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/PackageGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/PackageGenTest.java index ce54741490c..8502f3609f9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/PackageGenTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/PackageGenTest.java @@ -26,8 +26,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.jetbrains.kotlin.codegen.CodegenTestUtil.assertIsCurrentTime; - public class PackageGenTest extends CodegenTestCase { @Override @@ -60,8 +58,13 @@ public class PackageGenTest extends CodegenTestCase { public void testCurrentTime() throws Exception { loadText("fun f() : Long { return System.currentTimeMillis(); }"); Method main = generateFunction(); - long returnValue = (Long) main.invoke(null); - assertIsCurrentTime(returnValue); + long actual = (Long) main.invoke(null); + long expected = System.currentTimeMillis(); + long diff = Math.abs(actual - expected); + assertTrue( + "Difference with current time: " + diff + " (this test is a bad one: it may fail even if the generated code is correct)", + diff <= 100 + ); } public void testIdentityHashCode() throws Exception { diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/PrimitiveTypesTest.java index fa3fa8fc369..33e48efecfa 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/PrimitiveTypesTest.java @@ -158,13 +158,11 @@ public class PrimitiveTypesTest extends CodegenTestCase { } public void testCastOnStack() throws Exception { - loadText("fun foo(): Double = System.currentTimeMillis().toDouble()"); + loadText("fun foo(l: Long): Double = l.toDouble()"); Class mainClass = generatePackagePartClass(); - Method main = mainClass.getDeclaredMethod("foo"); - double currentTimeMillis = (double) System.currentTimeMillis(); - double result = (Double) main.invoke(null); - double delta = Math.abs(currentTimeMillis - result); - assertTrue(delta <= 1.0); + Method main = mainClass.getDeclaredMethod("foo", long.class); + double result = (Double) main.invoke(null, 42L); + assertTrue(Math.abs(42L - result) <= 1e-9); } public void testNeg() throws Exception { diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/PropertyGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/PropertyGenTest.java index 33560155b15..7f7d75e71ef 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/PropertyGenTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/PropertyGenTest.java @@ -23,7 +23,8 @@ import org.jetbrains.org.objectweb.asm.Opcodes; import java.lang.reflect.*; -import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*; +import static org.jetbrains.kotlin.codegen.CodegenTestUtil.findDeclaredMethodByName; +import static org.jetbrains.kotlin.codegen.CodegenTestUtil.findDeclaredMethodByNameOrNull; public class PropertyGenTest extends CodegenTestCase { @Override @@ -90,9 +91,9 @@ public class PropertyGenTest extends CodegenTestCase { } public void testFieldGetter() throws Exception { - loadText("val now: Long get() = System.currentTimeMillis(); fun foo() = now"); + loadText("val now: Long get() = 42L; fun foo() = now"); Method method = generateFunction("foo"); - assertIsCurrentTime((Long) method.invoke(null)); + assertEquals(Long.valueOf(42), method.invoke(null)); } public void testFieldSetter() throws Exception { @@ -131,13 +132,6 @@ public class PropertyGenTest extends CodegenTestCase { assertEquals(610, getFoo.invoke(instance)); } - public void testInitializersForTopLevelProperties() throws Exception { - loadText("val x = System.currentTimeMillis()"); - Method method = generateFunction("getX"); - method.setAccessible(true); - assertIsCurrentTime((Long) method.invoke(null)); - } - public void testPropertyReceiverOnStack() throws Exception { loadFile(); Class aClass = generateClass("Evaluator");