Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead code when jupiter updates to opentest4j 1.3.0 #506

Open
TWiStErRob opened this issue Jun 1, 2023 · 0 comments
Open

Remove dead code when jupiter updates to opentest4j 1.3.0 #506

TWiStErRob opened this issue Jun 1, 2023 · 0 comments
Labels
a:bug something isn't working as expected in:test test module and project tests
Milestone

Comments

@TWiStErRob
Copy link
Owner

Once opentest4j 1.3.0 is released and jupiter updates its dependency, the following patch will have to be applied: the build will fail because WithRootCauseKtTest.cannot initCause of AssertionFailedError will fail.

Subject: [PATCH] Remove dead code
---
Index: test/internal/build.gradle.kts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/test/internal/build.gradle.kts b/test/internal/build.gradle.kts
--- a/test/internal/build.gradle.kts	(revision 5d7687e245de8ab87426d309f629bfa44de1bc42)
+++ b/test/internal/build.gradle.kts	(date 1685627110287)
@@ -19,6 +19,7 @@
 	api(libs.junit.api)
 	api(libs.junit.params)
 	runtimeOnly(libs.junit.engine)
+	api("org.opentest4j:opentest4j:1.3.0-RC1")
 
 	api(libs.hamcrest)
 
@@ -30,11 +31,3 @@
 
 	api(libs.jfixture.java)
 }
-
-tasks.named<Test>("test") {
-	if (javaVersion.isJava9Compatible) {
-		// TODEL Java 16 vs AssertionFailedError https://github.com/ota4j-team/opentest4j/issues/70
-		// Example test: WithRootCauseKtTest.`registering a task preConfigures, but does not create it`
-		jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
-	}
-}
Index: test/internal/src/test/kotlin/net/twisterrob/test/WithRootCauseKtTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/test/internal/src/test/kotlin/net/twisterrob/test/WithRootCauseKtTest.kt b/test/internal/src/test/kotlin/net/twisterrob/test/WithRootCauseKtTest.kt
--- a/test/internal/src/test/kotlin/net/twisterrob/test/WithRootCauseKtTest.kt	(revision 5d7687e245de8ab87426d309f629bfa44de1bc42)
+++ b/test/internal/src/test/kotlin/net/twisterrob/test/WithRootCauseKtTest.kt	(date 1685627199920)
@@ -70,20 +70,6 @@
 		}
 	}
 
-	/**
-	 * To verify the presence of the problem in
-	 * [ota4j-team/opentest4j#5](https://github.com/ota4j-team/opentest4j/issues/5#issuecomment-940474063).
-	 */
-	@Test
-	fun `cannot initCause of AssertionFailedError`() {
-		val ex = AssertionFailedError()
-		val cause = Throwable()
-
-		assertThrows<IllegalStateException> {
-			ex.initCause(cause)
-		}
-	}
-
 	@Test
 	fun `can add root cause to AssertionFailedError`() {
 		val ex = AssertionFailedError()
Index: test/internal/src/main/kotlin/net/twisterrob/test/withRootCause.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/test/internal/src/main/kotlin/net/twisterrob/test/withRootCause.kt b/test/internal/src/main/kotlin/net/twisterrob/test/withRootCause.kt
--- a/test/internal/src/main/kotlin/net/twisterrob/test/withRootCause.kt	(revision 5d7687e245de8ab87426d309f629bfa44de1bc42)
+++ b/test/internal/src/main/kotlin/net/twisterrob/test/withRootCause.kt	(date 1685626882629)
@@ -1,17 +1,7 @@
 package net.twisterrob.test
 
-import org.opentest4j.AssertionFailedError
-
 fun Throwable.withRootCause(cause: Throwable): Throwable {
 	require(cause !in generateSequence(this) { it.cause })
-	val rootCause = generateSequence(this) { it.cause }.last()
-	if (rootCause is AssertionFailedError) {
-		// Workaround for https://github.com/ota4j-team/opentest4j/issues/5#issuecomment-940474063.
-		// Can't use constructor, because would need to rebuild the whole chain:
-		// AssertionFailedError(rootCause.message, rootCause.expected, rootCause.actual, cause)
-		val causeField = Throwable::class.java.getDeclaredField("cause").apply { isAccessible = true }
-		causeField.set(rootCause, rootCause)
-	}
-	rootCause.initCause(cause)
+	generateSequence(this) { it.cause }.last().initCause(cause)
 	return this
 }
@TWiStErRob TWiStErRob added a:bug something isn't working as expected in:test test module and project tests labels Jun 1, 2023
@TWiStErRob TWiStErRob added this to the v0.17 milestone Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug something isn't working as expected in:test test module and project tests
Projects
None yet
Development

No branches or pull requests

1 participant