| ... | @@ -273,6 +273,22 @@ export fn _start() -> unreachable { | ... | @@ -273,6 +273,22 @@ export fn _start() -> unreachable { |
| 273 | exit(0); | 273 | exit(0); |
| 274 | } | 274 | } |
| 275 | )SOURCE", "OK\n"); | 275 | )SOURCE", "OK\n"); |
| | 276 | |
| | 277 | add_simple_case("bool literals", R"SOURCE( |
| | 278 | #link("c") |
| | 279 | extern { |
| | 280 | fn puts(s: *const u8) -> i32; |
| | 281 | fn exit(code: i32) -> unreachable; |
| | 282 | } |
| | 283 | |
| | 284 | export fn _start() -> unreachable { |
| | 285 | if (true) { puts("OK 1"); } |
| | 286 | if (false) { puts("BAD 1"); } |
| | 287 | if (!true) { puts("BAD 2"); } |
| | 288 | if (!false) { puts("OK 2"); } |
| | 289 | exit(0); |
| | 290 | } |
| | 291 | )SOURCE", "OK 1\nOK 2\n"); |
| 276 | } | 292 | } |
| 277 | | 293 | |
| 278 | static void add_compile_failure_test_cases(void) { | 294 | static void add_compile_failure_test_cases(void) { |
| ... | @@ -382,6 +398,12 @@ fn f() -> i32 { | ... | @@ -382,6 +398,12 @@ fn f() -> i32 { |
| 382 | } | 398 | } |
| 383 | )SOURCE", 1, ".tmp_source.zig:2:15: error: type mismatch. expected i32. got *const u8"); | 399 | )SOURCE", 1, ".tmp_source.zig:2:15: error: type mismatch. expected i32. got *const u8"); |
| 384 | | 400 | |
| | 401 | add_compile_fail_case("if condition is bool, not int", R"SOURCE( |
| | 402 | fn f() { |
| | 403 | if (0) {} |
| | 404 | } |
| | 405 | )SOURCE", 1, ".tmp_source.zig:3:9: error: type mismatch. expected bool. got i32"); |
| | 406 | |
| 385 | } | 407 | } |
| 386 | | 408 | |
| 387 | static void print_compiler_invokation(TestCase *test_case, Buf *zig_stderr) { | 409 | static void print_compiler_invokation(TestCase *test_case, Buf *zig_stderr) { |