| ... | ... | @@ -161,6 +161,38 @@ static TestCase *add_compile_fail_case(const char *case_name, const char *source |
| 161 | 161 | return test_case; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | static TestCase *add_compile_fail_case_exe(const char *case_name, const char *source, size_t count, ...) { |
| 165 | va_list ap; |
| 166 | va_start(ap, count); |
| 167 | |
| 168 | TestCase *test_case = allocate<TestCase>(1); |
| 169 | test_case->case_name = case_name; |
| 170 | test_case->source_files.resize(1); |
| 171 | test_case->source_files.at(0).relative_path = tmp_source_path; |
| 172 | test_case->source_files.at(0).source_code = source; |
| 173 | |
| 174 | for (size_t i = 0; i < count; i += 1) { |
| 175 | const char *arg = va_arg(ap, const char *); |
| 176 | test_case->compile_errors.append(arg); |
| 177 | } |
| 178 | |
| 179 | test_case->compiler_args.append("build_exe"); |
| 180 | test_case->compiler_args.append(tmp_source_path); |
| 181 | |
| 182 | test_case->compiler_args.append("--name"); |
| 183 | test_case->compiler_args.append("test"); |
| 184 | |
| 185 | test_case->compiler_args.append("--output"); |
| 186 | test_case->compiler_args.append(tmp_exe_path); |
| 187 | |
| 188 | test_case->compiler_args.append("--release"); |
| 189 | test_case->compiler_args.append("--strip"); |
| 190 | |
| 191 | test_cases.append(test_case); |
| 192 | |
| 193 | return test_case; |
| 194 | } |
| 195 | |
| 164 | 196 | static void add_debug_safety_case(const char *case_name, const char *source) { |
| 165 | 197 | TestCase *test_case = allocate<TestCase>(1); |
| 166 | 198 | test_case->is_debug_safety = true; |
| ... | ... | @@ -220,6 +252,11 @@ static TestCase *add_example_compile_extra(const char *root_source_file, bool li |
| 220 | 252 | test_case->compiler_args.append("build_exe"); |
| 221 | 253 | test_case->compiler_args.append(buf_ptr(buf_sprintf("../%s", root_source_file))); |
| 222 | 254 | |
| 255 | if (libc) { |
| 256 | test_case->compiler_args.append("--library"); |
| 257 | test_case->compiler_args.append("c"); |
| 258 | } |
| 259 | |
| 223 | 260 | test_cases.append(test_case); |
| 224 | 261 | |
| 225 | 262 | return test_case; |
| ... | ... | @@ -1952,6 +1989,16 @@ comptime { |
| 1952 | 1989 | const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); |
| 1953 | 1990 | } |
| 1954 | 1991 | )SOURCE", 1, ".tmp_source.zig:9:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'"); |
| 1992 | |
| 1993 | add_compile_fail_case_exe("missing main fn in executable", R"SOURCE( |
| 1994 | )SOURCE", 1, "error: no member named 'main' in '"); |
| 1995 | |
| 1996 | add_compile_fail_case_exe("private main fn", R"SOURCE( |
| 1997 | fn main() {} |
| 1998 | )SOURCE", 2, |
| 1999 | "error: 'main' is private", |
| 2000 | ".tmp_source.zig:2:1: note: declared here"); |
| 2001 | |
| 1955 | 2002 | } |
| 1956 | 2003 | |
| 1957 | 2004 | ////////////////////////////////////////////////////////////////////////////// |