commit eb1be33c198bbf3ff042651d95895d83a28987a5
parent 73f8cc5bb31ef25f8832a53767498735bce8b39b
Author: Armin Weigl <tb46305@gmail.com>
Date: Sat, 14 Jan 2023 17:30:18 +0100
tests/36-defines: initial commit
Signed-off-by: Armin Weigl <tb46305@gmail.com>
Diffstat:
2 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/tests/36-defines.ha b/tests/36-defines.ha
@@ -0,0 +1,51 @@
+use rt;
+
+fn import() void = {
+ assert(rt::compile("
+ use a = rt;
+ def b = a::TESTDEFINE;
+ ", "TESTDEFINE=1": rt::define) as rt::exited != rt::EXIT_SUCCESS);
+};
+
+fn mandatory() void = {
+ assert(rt::compile("
+ def TESTDEFINE = TESTDEFINE;
+ ", "TESTDEFINE=1": rt::define) as rt::exited == rt::EXIT_SUCCESS);
+ assert(rt::compile("
+ def TESTDEFINE = TESTDEFINE;
+ ") as rt::exited != rt::EXIT_SUCCESS);
+};
+
+fn optional() void = {
+ assert(rt::compile("
+ def TESTDEFINE = 1;
+ fn main() void = {
+ static assert(TESTDEFINE == 2);
+ };
+ ", "TESTDEFINE=2": rt::define) as rt::exited == rt::EXIT_SUCCESS);
+ assert(rt::compile("
+ def TESTDEFINE = 1;
+ fn main() void = {
+ static assert(TESTDEFINE == 1);
+ };
+ ") as rt::exited == rt::EXIT_SUCCESS);
+};
+
+fn compatibility() void = {
+ assert(rt::compile("
+ def TESTDEFINE: int = 0;
+ ", "TESTDEFINE:int=1": rt::define) as rt::exited == rt::EXIT_SUCCESS);
+ assert(rt::compile("
+ def TESTDEFINE: int = 0;
+ ", "TESTDEFINE:uint=1": rt::define) as rt::exited != rt::EXIT_SUCCESS);
+ assert(rt::compile("
+ const TEST = 1
+ ", "TEST=0": rt::define) as rt::exited != rt::EXIT_SUCCESS);
+};
+
+export fn main() void = {
+ // TODO: import();
+ mandatory();
+ optional();
+ // TODO: compatibility();
+};
diff --git a/tests/configure b/tests/configure
@@ -50,7 +50,8 @@ tests() {
32-copy \
33-yield \
34-declarations \
- 35-floats
+ 35-floats \
+ 36-defines
do
cat <<EOF
tests/$t: libhart.a testmod.a tests/$t.ha