-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Wrong conversion of some condition instructions with zero comparison from IR to jvm bytecode #167 Wrong conversion of numeric constants from IR to jvm bytecode #166 * Bug with local variables creation #165
- Loading branch information
Showing
3 changed files
with
127 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
jacodb-core/src/test/kotlin/org/jacodb/testing/cfg/ReverseIRTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2022 UnitTestBot contributors (utbot.org) | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.jacodb.testing.cfg | ||
|
||
import org.jacodb.api.ext.findClass | ||
import org.jacodb.testing.WithDB | ||
import org.jacodb.testing.ir.DoubleComparison | ||
import org.jacodb.testing.ir.InvokeMethodWithException | ||
import org.jacodb.testing.ir.WhenExpr | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class ReverseIRTest : BaseInstructionsTest() { | ||
companion object : WithDB() | ||
|
||
@Test | ||
fun comparison() { | ||
val clazz = testAndLoadClass(cp.findClass<DoubleComparison>()) | ||
val m = clazz.declaredMethods.first { it.name == "box" } | ||
assertEquals("OK", m.invoke(null)) | ||
} | ||
|
||
@Test | ||
fun `when`() { | ||
val clazz = testAndLoadClass(cp.findClass<WhenExpr>()) | ||
val m = clazz.declaredMethods.first { it.name == "box" } | ||
assertEquals("OK", m.invoke(null)) | ||
} | ||
|
||
@Test | ||
fun `local vars`() { | ||
val clazz = testAndLoadClass(cp.findClass<InvokeMethodWithException>()) | ||
val m = clazz.declaredMethods.first { it.name == "box" } | ||
assertEquals("OK", m.invoke(null)) | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/ir/ReverseIR.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2022 UnitTestBot contributors (utbot.org) | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.jacodb.testing.ir | ||
|
||
|
||
object DoubleComparison { | ||
|
||
@JvmStatic | ||
fun box(): String { | ||
if ((-0.0 as Comparable<Double>) >= 0.0) return "fail" | ||
return "OK" | ||
} | ||
} | ||
|
||
|
||
object WhenExpr { | ||
|
||
val x = 1 | ||
|
||
@JvmStatic | ||
fun box() = | ||
when (val y = x) { | ||
in 0..2 -> "OK" | ||
else -> "Fail: $y" | ||
} | ||
|
||
} | ||
|
||
object InvokeMethodWithException { | ||
|
||
class A { | ||
fun lol(a: Int): Int { | ||
return 888/a | ||
} | ||
} | ||
|
||
@JvmStatic | ||
fun box():String { | ||
val method = A::class.java.getMethod("lol", Int::class.java) | ||
var failed = false | ||
try { | ||
method.invoke(null, 0) | ||
} | ||
catch(e: Exception) { | ||
failed = true | ||
} | ||
|
||
return if (!failed) "fail" else "OK" | ||
} | ||
|
||
} |