scoop:scoop.test:0.1.0
src/execution/process.scoop
Selected production source · src/execution/process.scoop
1
package scoop.test.execution3
@Extern(name = "scoop_test_isolated", abi = "c")4
private fun isolated(index: Ptr<Int8>, name: Ptr<UInt8>, length: Long): Int5
@Extern(name = "scoop_test_child_start", abi = "c")6
private fun childStart(): Long7
@Extern(name = "scoop_test_monotonic_ns", abi = "c")8
private fun now(): Long9
@Extern(name = "scoop_test_child_publish", abi = "c")10
private fun publish(bytes: Ptr<UInt8>, length: Long): Int11
@Extern(name = "scoop_test_child_published", abi = "c")12
private fun published(): Int14
private fun passed(result: TestResult): Boolean = when (result) {15
case TestResult.Passed -> true16
case TestResult.Failed(_, _) -> false17
}19
private fun runChild(caseIndex: String, location: SourceLocation, initialize: () -> TestActions): Boolean {20
@Unsafe {21
val start = childStart()22
if (start < 0L) return false23
val result = runTestCase(location, initialize)24
val end = now()25
if (end < start) return false26
val state = if (passed(result)) "passed" else "failed"27
val record = caseIndex + " " + state + " " + (end - start).toString() + "\n" +28
testFailuresJson(result) + "\n"29
return record.withUtf8Bytes<Boolean>(fun(bytes: Ptr<UInt8>, length: Long): Boolean {30
@Unsafe { return publish(bytes, length) == 0 }31
})32
}33
}35
/** Runs the selected case in its designated process and reports whether it completed successfully. */36
public fun runSelectedTestCase(37
arguments: Array<String>, caseIndex: String, caseName: String, useProcess: Boolean,38
location: SourceLocation, initialize: () -> TestActions39
): Boolean {40
if (arguments.size > 1L && arguments[1L] == "--scoop-test-child") {41
return runChild(caseIndex, location, initialize)42
}43
if (useProcess || (arguments.size > 1L && arguments[1L] == "--scoop-test-isolate-all")) {44
@Unsafe {45
val status = caseIndex.withCString<Int>(fun(index: Ptr<Int8>): Int {46
@Unsafe {47
return caseName.withUtf8Bytes<Int>(fun(name: Ptr<UInt8>, length: Long): Int {48
@Unsafe { return isolated(index, name, length) }49
})50
}51
})52
if (status < 0) { throw IllegalStateException(Some("cannot finish isolated test run")) }53
return status == 054
}55
}56
return passed(runReportedTestCase(caseIndex, location, initialize))57
}59
/** Completes suite reporting, or checks that a private single-case dispatch published its result. */60
public fun finishTestRun(arguments: Array<String>, status: Int): Int {61
if (arguments.size > 1L && arguments[1L] == "--scoop-test-child") {62
@Unsafe { return if (published() == 1) 0 else 1 }63
}64
completeTestRun()65
return status66
}