diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2015-12-03 00:47:35 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2015-12-03 00:47:35 -0700 |
| commit | f8ca6c70c74db6e6f0d4462aa763adb6f1f41c7e (patch) | |
| tree | 99bc3d06bb37abb267a2a59f3ba04523c2c430eb /test/run_tests.cpp | |
| parent | c89f77dd8e5005e60e8fb223c6c68b50566ac1ed (diff) | |
| download | zig-f8ca6c70c74db6e6f0d4462aa763adb6f1f41c7e.tar.gz zig-f8ca6c70c74db6e6f0d4462aa763adb6f1f41c7e.zip | |
add labels and goto
Diffstat (limited to 'test/run_tests.cpp')
| -rw-r--r-- | test/run_tests.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/run_tests.cpp b/test/run_tests.cpp index 78f35db5a3..a8bc81bf11 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -232,6 +232,30 @@ static void add_compiling_test_cases(void) { exit(0); } )SOURCE", "pass\n"); + + add_simple_case("goto", R"SOURCE( + #link("c") + extern { + fn puts(s: *const u8) -> i32; + fn exit(code: i32) -> unreachable; + } + + fn loop(a : i32) { + if a == 0 { + goto done; + } + puts("loop"); + loop(a - 1); + + done: + return; + } + + export fn _start() -> unreachable { + loop(3); + exit(0); + } + )SOURCE", "loop\nloop\nloop\n"); } static void add_compile_failure_test_cases(void) { @@ -305,6 +329,17 @@ fn a() { )SOURCE", 2, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'", ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'"); + + add_compile_fail_case("goto cause unreachable code", R"SOURCE( +fn a() { + goto done; + b(); +done: + return; +} +fn b() {} + )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code"); + } static void print_compiler_invokation(TestCase *test_case, Buf *zig_stderr) { |
