diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-04-29 22:54:45 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-04-29 22:54:45 +0900 |
| commit | bd72d3c4acde3f5e79bd494d4678a6e72e92e313 (patch) | |
| tree | 0d0a9e09d915dc185ec99b7b7bda68b380c93b84 /tests/src/SpecTestsuites/SpecTestsuiteBase.php | |
| parent | 7b982693cc5f25f9010c30ef14f719e05a3ae605 (diff) | |
| download | php-waddiwasi-bd72d3c4acde3f5e79bd494d4678a6e72e92e313.tar.gz php-waddiwasi-bd72d3c4acde3f5e79bd494d4678a6e72e92e313.tar.zst php-waddiwasi-bd72d3c4acde3f5e79bd494d4678a6e72e92e313.zip | |
test: support action command
Diffstat (limited to 'tests/src/SpecTestsuites/SpecTestsuiteBase.php')
| -rw-r--r-- | tests/src/SpecTestsuites/SpecTestsuiteBase.php | 80 |
1 files changed, 38 insertions, 42 deletions
diff --git a/tests/src/SpecTestsuites/SpecTestsuiteBase.php b/tests/src/SpecTestsuites/SpecTestsuiteBase.php index 285ce12..f5cc39a 100644 --- a/tests/src/SpecTestsuites/SpecTestsuiteBase.php +++ b/tests/src/SpecTestsuites/SpecTestsuiteBase.php @@ -39,27 +39,14 @@ abstract class SpecTestsuiteBase extends TestCase array $expected, int $line, ): void { - $targetModuleName = $module ?? '_'; - $targetModule = self::$modules[$targetModuleName]; - $actionType = $action['type']; - $actionField = $action['field']; - if ($actionType === 'invoke') { - $actionArgs = $action['args']; - $runtime = self::$runtimes[$targetModuleName]; - try { - $this->assertWasmInvokeResults( - $expected, - $runtime->invoke( - $actionField, - array_map($this->toWasmArg(...), $actionArgs), - ), - "at $line", - ); - } catch (TrapException $e) { - $this->assertTrue(false, "assert_return: trap, $e at $line"); - } - } else { - $this->assertTrue(false, "assert_return: unknown action, $actionType"); + try { + $this->assertWasmInvokeResults( + $expected, + $this->doAction($module, $action), + "at $line", + ); + } catch (TrapException $e) { + $this->assertTrue(false, "assert_return: trap, $e at $line"); } } @@ -69,27 +56,14 @@ abstract class SpecTestsuiteBase extends TestCase string $text, int $line, ): void { - $targetModuleName = $module ?? '_'; - $targetModule = self::$modules[$targetModuleName]; - $actionType = $action['type']; - $actionField = $action['field']; - if ($actionType === 'invoke') { - $actionArgs = $action['args']; - $runtime = self::$runtimes[$targetModuleName]; - $exception = null; - try { - $runtime->invoke( - $actionField, - array_map($this->toWasmArg(...), $actionArgs), - ); - } catch (TrapException $e) { - $exception = $e; - } - $this->assertNotNull($exception, "at $line"); - $this->assertTrapKind($text, $e->getTrapKind(), "at $line"); - } else { - $this->assertTrue(false, "assert_trap: unknown action, $actionType"); + $exception = null; + try { + $this->doAction($module, $action); + } catch (TrapException $e) { + $exception = $e; } + $this->assertNotNull($exception, "at $line"); + $this->assertTrapKind($text, $e->getTrapKind(), "at $line"); } protected function runAssertMalformedCommand( @@ -143,10 +117,12 @@ abstract class SpecTestsuiteBase extends TestCase } protected function runActionCommand( + ?string $module, array $action, int $line, ): void { - $this->assertTrue(false, "action"); + $this->doAction($module, $action); + $this->assertTrue(true); } protected function runRegisterCommand( @@ -173,6 +149,26 @@ abstract class SpecTestsuiteBase extends TestCase }; } + private function doAction( + ?string $module, + array $action, + ): array { + $targetModuleName = $module ?? '_'; + $targetModule = self::$modules[$targetModuleName]; + $actionType = $action['type']; + $actionField = $action['field']; + if ($actionType === 'invoke') { + $actionArgs = $action['args']; + $runtime = self::$runtimes[$targetModuleName]; + return $runtime->invoke( + $actionField, + array_map($this->toWasmArg(...), $actionArgs), + ); + } else { + $this->assertTrue(false, "unknown action: $actionType"); + } + } + /** * @param list<mixed> $actualResults * @param list<array{type: string, value: string}> $expectedResults |
