1package soy.iko.opencode.data.repo
3import androidx.test.core.app.ApplicationProvider
4import androidx.test.ext.junit.runners.AndroidJUnit4
5import org.junit.Assert.assertEquals
6import org.junit.Assert.assertNotNull
7import org.junit.Assert.assertNull
8import org.junit.Assert.assertTrue
10import org.junit.runner.RunWith
13 * Instrumented test for [CrashLogger]. Runs on a device/emulator so it can exercise the
14 * real app-private filesystem: a simulated crash is written, then read back, listed, and
15 * deleted through the public API.
17@RunWith(AndroidJUnit4::class)
18class CrashLoggerTest {
20 private val context = ApplicationProvider.getApplicationContext<android.content.Context>()
21 private val logger = CrashLogger.get(context)
24 fun writeReadDeleteRoundTrip() {
27 // Simulate an uncaught exception by invoking the report path directly.
28 val report = writeFakeReport()
31 assertEquals(1, logger.reportCount())
33 val content = logger.readReport(report)
34 assertNotNull(content)
35 assertTrue("report should contain the stack trace", content!!.contains("IllegalStateException"))
36 assertTrue("report should contain device metadata", content.contains("Android:"))
38 logger.deleteReport(report)
39 assertEquals(0, logger.reportCount())
40 assertNull(logger.readReport(report))
44 fun clearAllRemovesEveryReport() {
48 assertTrue(logger.reportCount() >= 2)
51 assertEquals(0, logger.reportCount())
54 private fun writeFakeReport(tag: String = "test"): String {
55 val dir = java.io.File(context.filesDir, "crashes").apply { mkdirs() }
56 val name = "crash-test-${tag}-${System.nanoTime()}.txt"
57 java.io.File(dir, name).writeText(
59 opencode-android crash report
61 java.lang.IllegalStateException: boom $tag
62 at Crasher.crash(Crasher.kt:1)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list