commit 32dafdfae464e8bfa8d205e9962c29dc32e25ec9
parent 5ae88660fdfb51b6cb3524c6d024b9059b3942e0
Author: Bor Grošelj Simić <bgs@turminal.net>
Date: Sun, 5 Jun 2022 02:31:02 +0200
ensure 24-imports tests actually pass
Previously test code relied on evaluation of addresses of globals, which
isn't yet supported by harec. The tests failed silently because asserts
tested for nonzero exit code instead of specifically testing for
EXIT_FAILURE or equivalent.
Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>
Diffstat:
5 files changed, 42 insertions(+), 33 deletions(-)
diff --git a/rt/+freebsd/syscalls.ha b/rt/+freebsd/syscalls.ha
@@ -16,6 +16,9 @@ export fn dup2(old: int, new: int) int =
export fn getpid() int = syscall0(SYS_getpid): int;
+export def EXIT_SUCCESS: int = 0;
+export def EXIT_FAILURE: int = 1;
+
export @noreturn fn exit(status: int) void = { syscall1(SYS_exit, status: u64); };
export fn fork() int = syscall0(SYS_fork): int;
diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha
@@ -19,6 +19,9 @@ export fn dup2(old: int, new: int) int =
export fn getpid() int = syscall0(SYS_getpid): int;
+export def EXIT_SUCCESS: int = 0;
+export def EXIT_FAILURE: int = 1;
+
export @noreturn fn exit(status: int) void = { syscall1(SYS_exit, status: u64); };
export fn fork() int = syscall2(SYS_clone, SIGCHLD: u64, 0u64): int;
diff --git a/rt/+openbsd/syscalls.ha b/rt/+openbsd/syscalls.ha
@@ -16,6 +16,9 @@ export fn dup2(old: int, new: int) int =
export fn getpid() int = syscall0(SYS_getpid): int;
+export def EXIT_SUCCESS: int = 0;
+export def EXIT_FAILURE: int = 1;
+
export @noreturn fn exit(status: int) void = { syscall1(SYS_exit, status: u64); };
export fn fork() int = syscall0(SYS_fork): int;
diff --git a/testmod/testmod.ha b/testmod/testmod.ha
@@ -6,5 +6,5 @@ export type _enum = enum {
export type enum_alias = _enum;
-export fn testfunc1() void = void;
-export fn testfunc2() void = void;
+export def val: int = 42;
+export def val2: int = 90;
diff --git a/tests/24-imports.ha b/tests/24-imports.ha
@@ -4,78 +4,78 @@ use testmod;
fn accept() void = {
assert(rt::compile("
use testmod;
- export fn main() void = { &testmod::testfunc1; };
- ") == 0);
+ export fn main() void = static assert(testmod::val == 42);
+ ") == rt::EXIT_SUCCESS);
assert(rt::compile("
use testmod;
use alias = testmod;
- export fn main() void = static assert(&testmod::testfunc1 == &alias::testfunc1);
- ") == 0);
+ export fn main() void = static assert(testmod::val == alias::val);
+ ") == rt::EXIT_SUCCESS);
assert(rt::compile("
use testmod;
- use testmod::{testfunc1, testfunc2};
+ use testmod::{val, val2};
export fn main() void = static assert(
- &testmod::testfunc1 == &testfunc1 && &testmod::testfunc2 == &testfunc2
+ testmod::val == val && testmod::val2 == val2
);
- ") == 0);
+ ") == rt::EXIT_SUCCESS);
assert(rt::compile("
use testmod;
use testmod::*;
export fn main() void = static assert(
- &testmod::testfunc1 == &testfunc1 && &testmod::testfunc2 == &testfunc2
+ testmod::val == val && testmod::val2 == val2
);
- ") == 0);
+ ") == rt::EXIT_SUCCESS);
assert(rt::compile("
use testmod;
- use testmod::{alias = testfunc1, testfunc2};
+ use testmod::{alias = val, val2};
export fn main() void = static assert(
- &testmod::testfunc1 == &alias && &testmod::testfunc2 == &testfunc2
+ testmod::val == alias && testmod::val2 == val2
);
- ") == 0);
+ ") == rt::EXIT_SUCCESS);
assert(rt::compile("
use testmod;
- use modalias = testmod::{fnalias = testfunc1, testfunc2};
+ use modalias = testmod::{valalias = val, val2};
export fn main() void = static assert(
- &testmod::testfunc1 == &modalias::fnalias && &testmod::testfunc2 == &modalias::testfunc2
+ testmod::val == modalias::valalias && testmod::val2 == modalias::val2
);
- ") == 0);
+ ") == rt::EXIT_SUCCESS);
};
fn reject() void = {
assert(rt::compile("
use wrong;
- export fn main() void = { &testmod::testfunc1 };
- ") != 0);
+ export fn main() void = { testmod::val };
+ ") == rt::EXIT_FAILURE);
assert(rt::compile("
- use testmod::{testfunc1};
+ use testmod::{val};
export fn main() void = static assert(
- &testmod::testfunc1 != null
+ testmod::val == 42
);
- ") != 0);
+ ") == rt::EXIT_FAILURE);
assert(rt::compile("
- use testmod::{testfunc1};
+ use testmod::{val};
export fn main() void = static assert(
- &testfunc2 != null
+ val2 == 90
);
- ") != 0);
+ ") == rt::EXIT_FAILURE);
assert(rt::compile("
use testmod;
use test = testmod::*;
export fn main() void = void;
- ") != 0);
+ ") == rt::EXIT_FAILURE);
assert(rt::compile("
use testmod;
use testmod*;
export fn main() void = void;
- ") != 0);
+ ") == rt::EXIT_FAILURE);
assert(rt::compile("
- use testmod::{alias = testfunc1, testfunc2};
- export fn main() void = static assert(&testfunc1 != null);
- ") != 0);
+ use testmod::{alias = val, val2};
+ export fn main() void = static assert(val == 42);
+ ") == rt::EXIT_FAILURE);
assert(rt::compile("
- use modalias = testmod::{fnalias = testfunc1, testfunc2};
- export fn main() void = static assert(&fnalias != null);
- ") != 0);
+ use modalias = testmod::{valalias = val, val2};
+ export fn main() void = static assert(valalias == 42);
+ ") == rt::EXIT_FAILURE);
};