hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 2003bf9b541e58e6d86d2e0df9f940cbc66b4c77
parent 406bf057625e83b1d4cf5f28342e7113249ae9a4
Author: Sebastian <sebastian@sebsite.pw>
Date:   Mon,  6 Nov 2023 23:27:26 -0500

test: disallow expectabort outside @test

Also renamed common to util, since that's just a better name

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Dtest/common.ha | 8--------
Atest/util+test.ha | 15+++++++++++++++
Atest/util.ha | 8++++++++
3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/test/common.ha b/test/common.ha @@ -1,8 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -// (c) Hare authors <https://harelang.org> - -let want_abort = false; - -// Expect the currently running test to abort. The test will fail if it doesn't -// abort. -export fn expectabort() void = want_abort = true; diff --git a/test/util+test.ha b/test/util+test.ha @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MPL-2.0 +// (c) Hare authors <https://harelang.org> + +use rt; + +let want_abort = false; + +// Expect the currently running test to abort. The test will fail if it doesn't +// abort. +export fn expectabort() void = { + if (rt::jmp == null) { + abort("Attempted to call test::expectabort outside of @test function"); + }; + want_abort = true; +}; diff --git a/test/util.ha b/test/util.ha @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: MPL-2.0 +// (c) Hare authors <https://harelang.org> + +// Expect the currently running test to abort. The test will fail if it doesn't +// abort. +export fn expectabort() void = { + abort("Attempted to call test::expectabort outside of @test function"); +};