diff --git a/staticlibs/tests/unit/src/com/android/net/module/util/CleanupTest.kt b/staticlibs/tests/unit/src/com/android/net/module/util/CleanupTest.kt index 649b30e11d..851d09af69 100644 --- a/staticlibs/tests/unit/src/com/android/net/module/util/CleanupTest.kt +++ b/staticlibs/tests/unit/src/com/android/net/module/util/CleanupTest.kt @@ -174,6 +174,25 @@ class CleanupTest { assertTrue(thrown.suppressedExceptions.isEmpty()) } + @Test + fun testAssertionErrorInCatch() { + var x = 1 + val thrown = assertFailsWith { + tryTest { + x = 2 + throw TestException1() + }.catch { + x = 3 + fail("Test failure in catch") + } cleanup { + assertTrue(x == 3) + x = 4 + } + } + assertTrue(x == 4) + assertTrue(thrown.suppressedExceptions.isEmpty()) + } + @Test fun testMultipleCleanups() { var x = 1 diff --git a/staticlibs/testutils/hostdevice/com/android/testutils/Cleanup.kt b/staticlibs/testutils/hostdevice/com/android/testutils/Cleanup.kt index 45783d82db..3db357b565 100644 --- a/staticlibs/testutils/hostdevice/com/android/testutils/Cleanup.kt +++ b/staticlibs/testutils/hostdevice/com/android/testutils/Cleanup.kt @@ -90,7 +90,7 @@ inline class TryExpr(val result: Result) { if (originalException !is E) return this return TryExpr(try { Result.success(block(originalException)) - } catch (e: Exception) { + } catch (e: Throwable) { Result.failure(e) }) }