From 46149d1002969e680d16973616c255ff9f3cb2a0 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 13 Nov 2020 22:47:21 +0700 Subject: [PATCH] Add tests --- source/compiler/tests/__static_assert.meta | 25 ++++++++++ source/compiler/tests/__static_assert.pwn | 53 ++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 source/compiler/tests/__static_assert.meta create mode 100644 source/compiler/tests/__static_assert.pwn diff --git a/source/compiler/tests/__static_assert.meta b/source/compiler/tests/__static_assert.meta new file mode 100644 index 0000000..0bcf0e6 --- /dev/null +++ b/source/compiler/tests/__static_assert.meta @@ -0,0 +1,25 @@ +{ + 'test_type': 'output_check', + 'errors': """ +__static_assert.pwn(8) : warning 249: check failed: size of "TEST" is not 123 +__static_assert.pwn(14) : warning 249: check failed: size of "Test" array is not 123 +__static_assert.pwn(20) : warning 249: check failed: cval - 1 +__static_assert.pwn(21) : warning 249: check failed: test_string +__static_assert.pwn(22) : warning 249: check failed: \ test \ " abc " +__static_assert.pwn(23) : warning 249: check failed: string concatenation test +__static_assert.pwn(24) : warning 249: check failed: stringization test +__static_assert.pwn(27) : warning 249: check failed: array size must be even +__static_assert.pwn(32) : warning 249: check failed: cval != cval +__static_assert.pwn(32) : warning 249: check failed: 1 && __static_check(cval != cval) && false +__static_assert.pwn(34) : warning 249: check failed: inside fail +__static_assert.pwn(35) : warning 249: check failed: outside fail +__static_assert.pwn(37 -- 38) : warning 249: check failed: -expression- +__static_assert.pwn(40) : error 008: must be a constant expression; assumed zero +__static_assert.pwn(41) : error 001: expected token: "-string-", but found "-identifier-" +__static_assert.pwn(42) : error 001: expected token: "-string-", but found "!" +__static_assert.pwn(43) : error 001: expected token: "-string-", but found "!" +__static_assert.pwn(49) : fatal error 110: assertion failed: this is zero + +Compilation aborted. +""" +} diff --git a/source/compiler/tests/__static_assert.pwn b/source/compiler/tests/__static_assert.pwn new file mode 100644 index 0000000..907c92e --- /dev/null +++ b/source/compiler/tests/__static_assert.pwn @@ -0,0 +1,53 @@ +enum TEST +{ + ABC1, + ABC2 +}; + +__static_check(_:TEST == 2, "size of \"TEST\" is not 2"); +__static_check(_:TEST == 123, "size of \"TEST\" is not 123"); // warning 249: check failed: size of "TEST" is not 123 + +new Test[(__static_check(1), TEST)]; +#pragma unused Test + +__static_check(sizeof(Test) == 2, "size of \"Test\" array is not 2"); +__static_check(sizeof(Test) == 123, "size of \"Test\" array is not 123"); // warning 249: check failed: size of "Test" array is not 123 + +main() +{ + const cval = 1; + new var = 1234; + __static_check( cval - 1 ); // warning 249: check failed: cval - 1023 + __static_check(0, "test_string"); // warning 249: check failed: test_string + __static_check(0, "\\ test \\ \" abc \""); // warning 249: check failed: \ test \ " abc " + __static_check(0, "string" " concatenation " "test"); // warning 249: check failed: string concatenation test + __static_check(0, #stringization " test"); // warning 249: check failed: stringization test + + new arr[(__static_check(32%2 == 0, "array size must be even"), 32)]; + new arr2[(__static_check(33%2 == 0, "array size must be even"), 33)]; // warning 249: check failed: array size must be even + #pragma unused arr + #pragma unused arr2 + + __static_check(1 && __static_check(cval == cval) || false); + __static_check(1 && __static_check(cval != cval) && false); // warning 249: check failed: cval != cval + // warning 249: check failed: 1 && __static_check(cval != cval) && false + __static_check(__static_check(cval != cval, "inside fail") || true, "outside fail"); // warning 249: check failed: inside fail + __static_check(__static_check(cval == cval, "inside fail") && false, "outside fail"); // warning 249: check failed: outside fail + + __static_check((0 + 1 + 2 + 3 + 4 + + 5 + 6 + 7 + 8 + 9) * 0); // warning 249: check failed: -expression- + + __static_check(var); // error 008: must be a constant expression; assumed zero + __static_check(cval, var); // error 001: expected token: "-string-", but found "-identifier-" + __static_check(cval, !"test"); // error 001: expected token: "-string-", but found "!" + __static_check(cval, !""); // error 001: expected token: "-string-", but found "!" + +#if defined SecondPass + // Only check assertions on the 2'nd pass, otherwise + // warnings from the above checks won't be displayed. + __static_assert(1, "this is not zero"); + __static_assert(0, "this is zero"); // fatal error 110: assertion failed: this is zero +#endif +} + +stock SecondPass(){}