Scoop API

scoop:scoop.test:0.1.0

src/execution/process.scoop

Selected production source · src/execution/process.scoop

1package scoop.test.execution
3@Extern(name = "scoop_test_isolated", abi = "c")
4private fun isolated(index: Ptr<Int8>, name: Ptr<UInt8>, length: Long): Int
5@Extern(name = "scoop_test_child_start", abi = "c")
6private fun childStart(): Long
7@Extern(name = "scoop_test_monotonic_ns", abi = "c")
8private fun now(): Long
9@Extern(name = "scoop_test_child_publish", abi = "c")
10private fun publish(bytes: Ptr<UInt8>, length: Long): Int
11@Extern(name = "scoop_test_child_published", abi = "c")
12private fun published(): Int
14private fun passed(result: TestResult): Boolean = when (result) {
15 case TestResult.Passed -> true
16 case TestResult.Failed(_, _) -> false
19private fun runChild(caseIndex: String, location: SourceLocation, initialize: () -> TestActions): Boolean {
20 @Unsafe {
21 val start = childStart()
22 if (start < 0L) return false
23 val result = runTestCase(location, initialize)
24 val end = now()
25 if (end < start) return false
26 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 }
35/** Runs the selected case in its designated process and reports whether it completed successfully. */
36public fun runSelectedTestCase(
37 arguments: Array<String>, caseIndex: String, caseName: String, useProcess: Boolean,
38 location: SourceLocation, initialize: () -> TestActions
39): 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 == 0
54 }
55 }
56 return passed(runReportedTestCase(caseIndex, location, initialize))
59/** Completes suite reporting, or checks that a private single-case dispatch published its result. */
60public 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 status