diff options
author | Chalard Jean <jchalard@google.com> | 2019-06-19 16:07:14 +0900 |
---|---|---|
committer | Chalard Jean <jchalard@google.com> | 2019-06-28 16:23:46 +0900 |
commit | 708e800c80b9b3788c4a7f9aaa97f67bc4d4ae45 (patch) | |
tree | bb823339cbec7cb65fa2386ef1b4131852ab4403 | |
parent | e601bd1299fdc9ac75f3832bc08adfbc6ab5ad0c (diff) |
Add a test for the interpreter
Just a basic test. If the interpreter is broken one of the tests
using it will break anyway ; the only important thing is to make
sure that it's actually running the tests and actually reporting
failures, if any. So here's a test doing that.
Test: atest FrameworksNetTests NetworkStackTests
Change-Id: I84ce651a6e3b64aa94daa5ee1fe014b27d2fba76
-rw-r--r-- | tests/lib/src/com/android/testutils/FileUtils.kt | 11 | ||||
-rw-r--r-- | tests/unit/src/android/net/testutils/TrackRecordTest.kt | 23 |
2 files changed, 34 insertions, 0 deletions
diff --git a/tests/lib/src/com/android/testutils/FileUtils.kt b/tests/lib/src/com/android/testutils/FileUtils.kt new file mode 100644 index 0000000..edd8d83 --- /dev/null +++ b/tests/lib/src/com/android/testutils/FileUtils.kt @@ -0,0 +1,11 @@ +package com.android.testutils + +// This function is private because the 2 is hardcoded here, and is not correct if not called +// directly from __LINE__ or __FILE__. +private fun callerStackTrace(): StackTraceElement = try { + throw RuntimeException() +} catch (e: RuntimeException) { + e.stackTrace[2] // 0 is here, 1 is get() in __FILE__ or __LINE__ +} +val __FILE__: String get() = callerStackTrace().fileName +val __LINE__: Int get() = callerStackTrace().lineNumber diff --git a/tests/unit/src/android/net/testutils/TrackRecordTest.kt b/tests/unit/src/android/net/testutils/TrackRecordTest.kt index c240e65..54a3c91 100644 --- a/tests/unit/src/android/net/testutils/TrackRecordTest.kt +++ b/tests/unit/src/android/net/testutils/TrackRecordTest.kt @@ -19,6 +19,8 @@ package android.net.testutils import android.os.SystemClock import com.android.testutils.ArrayTrackRecord import com.android.testutils.TrackRecord +import com.android.testutils.__FILE__ +import com.android.testutils.__LINE__ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 @@ -207,6 +209,27 @@ class TrackRecordTest { assertTrue(delay > SHORT_TIMEOUT) } + // Just make sure the interpreter actually throws an exception when the spec + // does not conform to the behavior. The interpreter is just a tool to test a + // tool used for a tool for test, let's not have hundreds of tests for it ; + // if it's broken one of the tests using it will break. + @Test + fun testInterpreter() { + val interpretLine = __LINE__ + 2 + try { + interpretTestSpec(useReadHeads = true, spec = """ + add(4) | poll(1, 0) = 5 + """) + fail("This spec should have thrown") + } catch (e: InterpretException) { + assertTrue(e.cause is AssertionError) + assertEquals(interpretLine + 1, e.stackTrace[0].lineNumber) + assertTrue(e.stackTrace[0].fileName.contains(__FILE__)) + assertTrue(e.stackTrace[0].methodName.contains("testInterpreter")) + assertTrue(e.stackTrace[0].methodName.contains("thread1")) + } + } + @Test fun testMultiplePoll() { interpretTestSpec(useReadHeads = false, spec = """ |