| ... | @@ -122,11 +122,6 @@ pub const TestContext = struct { | ... | @@ -122,11 +122,6 @@ pub const TestContext = struct { |
| 122 | path: []const u8, | 122 | path: []const u8, |
| 123 | }; | 123 | }; |
| 124 | | 124 | |
| 125 | pub const Extension = enum { | | |
| 126 | Zig, | | |
| 127 | ZIR, | | |
| 128 | }; | | |
| 129 | | | |
| 130 | /// A `Case` consists of a list of `Update`. The same `Compilation` is used for each | 125 | /// A `Case` consists of a list of `Update`. The same `Compilation` is used for each |
| 131 | /// update, so each update's source is treated as a single file being | 126 | /// update, so each update's source is treated as a single file being |
| 132 | /// updated by the test harness and incrementally compiled. | 127 | /// updated by the test harness and incrementally compiled. |
| ... | @@ -141,7 +136,6 @@ pub const TestContext = struct { | ... | @@ -141,7 +136,6 @@ pub const TestContext = struct { |
| 141 | /// to Executable. | 136 | /// to Executable. |
| 142 | output_mode: std.builtin.OutputMode, | 137 | output_mode: std.builtin.OutputMode, |
| 143 | updates: std.ArrayList(Update), | 138 | updates: std.ArrayList(Update), |
| 144 | extension: Extension, | | |
| 145 | object_format: ?std.builtin.ObjectFormat = null, | 139 | object_format: ?std.builtin.ObjectFormat = null, |
| 146 | emit_h: bool = false, | 140 | emit_h: bool = false, |
| 147 | llvm_backend: bool = false, | 141 | llvm_backend: bool = false, |
| ... | @@ -238,14 +232,12 @@ pub const TestContext = struct { | ... | @@ -238,14 +232,12 @@ pub const TestContext = struct { |
| 238 | ctx: *TestContext, | 232 | ctx: *TestContext, |
| 239 | name: []const u8, | 233 | name: []const u8, |
| 240 | target: CrossTarget, | 234 | target: CrossTarget, |
| 241 | extension: Extension, | | |
| 242 | ) *Case { | 235 | ) *Case { |
| 243 | ctx.cases.append(Case{ | 236 | ctx.cases.append(Case{ |
| 244 | .name = name, | 237 | .name = name, |
| 245 | .target = target, | 238 | .target = target, |
| 246 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), | 239 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), |
| 247 | .output_mode = .Exe, | 240 | .output_mode = .Exe, |
| 248 | .extension = extension, | | |
| 249 | .files = std.ArrayList(File).init(ctx.cases.allocator), | 241 | .files = std.ArrayList(File).init(ctx.cases.allocator), |
| 250 | }) catch @panic("out of memory"); | 242 | }) catch @panic("out of memory"); |
| 251 | return &ctx.cases.items[ctx.cases.items.len - 1]; | 243 | return &ctx.cases.items[ctx.cases.items.len - 1]; |
| ... | @@ -253,7 +245,7 @@ pub const TestContext = struct { | ... | @@ -253,7 +245,7 @@ pub const TestContext = struct { |
| 253 | | 245 | |
| 254 | /// Adds a test case for Zig input, producing an executable | 246 | /// Adds a test case for Zig input, producing an executable |
| 255 | pub fn exe(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case { | 247 | pub fn exe(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case { |
| 256 | return ctx.addExe(name, target, .Zig); | 248 | return ctx.addExe(name, target); |
| 257 | } | 249 | } |
| 258 | | 250 | |
| 259 | /// Adds a test case for ZIR input, producing an executable | 251 | /// Adds a test case for ZIR input, producing an executable |
| ... | @@ -269,7 +261,6 @@ pub const TestContext = struct { | ... | @@ -269,7 +261,6 @@ pub const TestContext = struct { |
| 269 | .target = target, | 261 | .target = target, |
| 270 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), | 262 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), |
| 271 | .output_mode = .Exe, | 263 | .output_mode = .Exe, |
| 272 | .extension = .Zig, | | |
| 273 | .object_format = .c, | 264 | .object_format = .c, |
| 274 | .files = std.ArrayList(File).init(ctx.cases.allocator), | 265 | .files = std.ArrayList(File).init(ctx.cases.allocator), |
| 275 | }) catch @panic("out of memory"); | 266 | }) catch @panic("out of memory"); |
| ... | @@ -284,7 +275,6 @@ pub const TestContext = struct { | ... | @@ -284,7 +275,6 @@ pub const TestContext = struct { |
| 284 | .target = target, | 275 | .target = target, |
| 285 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), | 276 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), |
| 286 | .output_mode = .Exe, | 277 | .output_mode = .Exe, |
| 287 | .extension = .Zig, | | |
| 288 | .files = std.ArrayList(File).init(ctx.cases.allocator), | 278 | .files = std.ArrayList(File).init(ctx.cases.allocator), |
| 289 | .llvm_backend = true, | 279 | .llvm_backend = true, |
| 290 | }) catch @panic("out of memory"); | 280 | }) catch @panic("out of memory"); |
| ... | @@ -295,14 +285,12 @@ pub const TestContext = struct { | ... | @@ -295,14 +285,12 @@ pub const TestContext = struct { |
| 295 | ctx: *TestContext, | 285 | ctx: *TestContext, |
| 296 | name: []const u8, | 286 | name: []const u8, |
| 297 | target: CrossTarget, | 287 | target: CrossTarget, |
| 298 | extension: Extension, | | |
| 299 | ) *Case { | 288 | ) *Case { |
| 300 | ctx.cases.append(Case{ | 289 | ctx.cases.append(Case{ |
| 301 | .name = name, | 290 | .name = name, |
| 302 | .target = target, | 291 | .target = target, |
| 303 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), | 292 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), |
| 304 | .output_mode = .Obj, | 293 | .output_mode = .Obj, |
| 305 | .extension = extension, | | |
| 306 | .files = std.ArrayList(File).init(ctx.cases.allocator), | 294 | .files = std.ArrayList(File).init(ctx.cases.allocator), |
| 307 | }) catch @panic("out of memory"); | 295 | }) catch @panic("out of memory"); |
| 308 | return &ctx.cases.items[ctx.cases.items.len - 1]; | 296 | return &ctx.cases.items[ctx.cases.items.len - 1]; |
| ... | @@ -310,7 +298,7 @@ pub const TestContext = struct { | ... | @@ -310,7 +298,7 @@ pub const TestContext = struct { |
| 310 | | 298 | |
| 311 | /// Adds a test case for Zig input, producing an object file. | 299 | /// Adds a test case for Zig input, producing an object file. |
| 312 | pub fn obj(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case { | 300 | pub fn obj(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case { |
| 313 | return ctx.addObj(name, target, .Zig); | 301 | return ctx.addObj(name, target); |
| 314 | } | 302 | } |
| 315 | | 303 | |
| 316 | /// Adds a test case for ZIR input, producing an object file. | 304 | /// Adds a test case for ZIR input, producing an object file. |
| ... | @@ -319,13 +307,12 @@ pub const TestContext = struct { | ... | @@ -319,13 +307,12 @@ pub const TestContext = struct { |
| 319 | } | 307 | } |
| 320 | | 308 | |
| 321 | /// Adds a test case for Zig or ZIR input, producing C code. | 309 | /// Adds a test case for Zig or ZIR input, producing C code. |
| 322 | pub fn addC(ctx: *TestContext, name: []const u8, target: CrossTarget, ext: Extension) *Case { | 310 | pub fn addC(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case { |
| 323 | ctx.cases.append(Case{ | 311 | ctx.cases.append(Case{ |
| 324 | .name = name, | 312 | .name = name, |
| 325 | .target = target, | 313 | .target = target, |
| 326 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), | 314 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), |
| 327 | .output_mode = .Obj, | 315 | .output_mode = .Obj, |
| 328 | .extension = ext, | | |
| 329 | .object_format = .c, | 316 | .object_format = .c, |
| 330 | .files = std.ArrayList(File).init(ctx.cases.allocator), | 317 | .files = std.ArrayList(File).init(ctx.cases.allocator), |
| 331 | }) catch @panic("out of memory"); | 318 | }) catch @panic("out of memory"); |
| ... | @@ -333,21 +320,20 @@ pub const TestContext = struct { | ... | @@ -333,21 +320,20 @@ pub const TestContext = struct { |
| 333 | } | 320 | } |
| 334 | | 321 | |
| 335 | pub fn c(ctx: *TestContext, name: []const u8, target: CrossTarget, src: [:0]const u8, comptime out: [:0]const u8) void { | 322 | pub fn c(ctx: *TestContext, name: []const u8, target: CrossTarget, src: [:0]const u8, comptime out: [:0]const u8) void { |
| 336 | ctx.addC(name, target, .Zig).addCompareObjectFile(src, zig_h ++ out); | 323 | ctx.addC(name, target).addCompareObjectFile(src, zig_h ++ out); |
| 337 | } | 324 | } |
| 338 | | 325 | |
| 339 | pub fn h(ctx: *TestContext, name: []const u8, target: CrossTarget, src: [:0]const u8, comptime out: [:0]const u8) void { | 326 | pub fn h(ctx: *TestContext, name: []const u8, target: CrossTarget, src: [:0]const u8, comptime out: [:0]const u8) void { |
| 340 | ctx.addC(name, target, .Zig).addHeader(src, zig_h ++ out); | 327 | ctx.addC(name, target).addHeader(src, zig_h ++ out); |
| 341 | } | 328 | } |
| 342 | | 329 | |
| 343 | pub fn addCompareOutput( | 330 | pub fn addCompareOutput( |
| 344 | ctx: *TestContext, | 331 | ctx: *TestContext, |
| 345 | name: []const u8, | 332 | name: []const u8, |
| 346 | extension: Extension, | | |
| 347 | src: [:0]const u8, | 333 | src: [:0]const u8, |
| 348 | expected_stdout: []const u8, | 334 | expected_stdout: []const u8, |
| 349 | ) void { | 335 | ) void { |
| 350 | ctx.addExe(name, .{}, extension).addCompareOutput(src, expected_stdout); | 336 | ctx.addExe(name, .{}).addCompareOutput(src, expected_stdout); |
| 351 | } | 337 | } |
| 352 | | 338 | |
| 353 | /// Adds a test case that compiles the Zig source given in `src`, executes | 339 | /// Adds a test case that compiles the Zig source given in `src`, executes |
| ... | @@ -358,7 +344,7 @@ pub const TestContext = struct { | ... | @@ -358,7 +344,7 @@ pub const TestContext = struct { |
| 358 | src: [:0]const u8, | 344 | src: [:0]const u8, |
| 359 | expected_stdout: []const u8, | 345 | expected_stdout: []const u8, |
| 360 | ) void { | 346 | ) void { |
| 361 | return ctx.addCompareOutput(name, .Zig, src, expected_stdout); | 347 | return ctx.addCompareOutput(name, src, expected_stdout); |
| 362 | } | 348 | } |
| 363 | | 349 | |
| 364 | /// Adds a test case that compiles the ZIR source given in `src`, executes | 350 | /// Adds a test case that compiles the ZIR source given in `src`, executes |
| ... | @@ -376,11 +362,10 @@ pub const TestContext = struct { | ... | @@ -376,11 +362,10 @@ pub const TestContext = struct { |
| 376 | ctx: *TestContext, | 362 | ctx: *TestContext, |
| 377 | name: []const u8, | 363 | name: []const u8, |
| 378 | target: CrossTarget, | 364 | target: CrossTarget, |
| 379 | extension: Extension, | | |
| 380 | src: [:0]const u8, | 365 | src: [:0]const u8, |
| 381 | result: [:0]const u8, | 366 | result: [:0]const u8, |
| 382 | ) void { | 367 | ) void { |
| 383 | ctx.addObj(name, target, extension).addTransform(src, result); | 368 | ctx.addObj(name, target).addTransform(src, result); |
| 384 | } | 369 | } |
| 385 | | 370 | |
| 386 | /// Adds a test case that compiles the Zig given in `src` to ZIR and tests | 371 | /// Adds a test case that compiles the Zig given in `src` to ZIR and tests |
| ... | @@ -392,7 +377,7 @@ pub const TestContext = struct { | ... | @@ -392,7 +377,7 @@ pub const TestContext = struct { |
| 392 | src: [:0]const u8, | 377 | src: [:0]const u8, |
| 393 | result: [:0]const u8, | 378 | result: [:0]const u8, |
| 394 | ) void { | 379 | ) void { |
| 395 | ctx.addTransform(name, target, .Zig, src, result); | 380 | ctx.addTransform(name, target, src, result); |
| 396 | } | 381 | } |
| 397 | | 382 | |
| 398 | /// Adds a test case that cleans up the ZIR source given in `src`, and | 383 | /// Adds a test case that cleans up the ZIR source given in `src`, and |
| ... | @@ -411,11 +396,10 @@ pub const TestContext = struct { | ... | @@ -411,11 +396,10 @@ pub const TestContext = struct { |
| 411 | ctx: *TestContext, | 396 | ctx: *TestContext, |
| 412 | name: []const u8, | 397 | name: []const u8, |
| 413 | target: CrossTarget, | 398 | target: CrossTarget, |
| 414 | extension: Extension, | | |
| 415 | src: [:0]const u8, | 399 | src: [:0]const u8, |
| 416 | expected_errors: []const []const u8, | 400 | expected_errors: []const []const u8, |
| 417 | ) void { | 401 | ) void { |
| 418 | ctx.addObj(name, target, extension).addError(src, expected_errors); | 402 | ctx.addObj(name, target).addError(src, expected_errors); |
| 419 | } | 403 | } |
| 420 | | 404 | |
| 421 | /// Adds a test case that ensures that the Zig given in `src` fails to | 405 | /// Adds a test case that ensures that the Zig given in `src` fails to |
| ... | @@ -428,7 +412,7 @@ pub const TestContext = struct { | ... | @@ -428,7 +412,7 @@ pub const TestContext = struct { |
| 428 | src: [:0]const u8, | 412 | src: [:0]const u8, |
| 429 | expected_errors: []const []const u8, | 413 | expected_errors: []const []const u8, |
| 430 | ) void { | 414 | ) void { |
| 431 | ctx.addError(name, target, .Zig, src, expected_errors); | 415 | ctx.addError(name, target, src, expected_errors); |
| 432 | } | 416 | } |
| 433 | | 417 | |
| 434 | /// Adds a test case that ensures that the ZIR given in `src` fails to | 418 | /// Adds a test case that ensures that the ZIR given in `src` fails to |
| ... | @@ -448,10 +432,9 @@ pub const TestContext = struct { | ... | @@ -448,10 +432,9 @@ pub const TestContext = struct { |
| 448 | ctx: *TestContext, | 432 | ctx: *TestContext, |
| 449 | name: []const u8, | 433 | name: []const u8, |
| 450 | target: CrossTarget, | 434 | target: CrossTarget, |
| 451 | extension: Extension, | | |
| 452 | src: [:0]const u8, | 435 | src: [:0]const u8, |
| 453 | ) void { | 436 | ) void { |
| 454 | ctx.addObj(name, target, extension).compiles(src); | 437 | ctx.addObj(name, target).compiles(src); |
| 455 | } | 438 | } |
| 456 | | 439 | |
| 457 | /// Adds a test case that asserts that the Zig given in `src` compiles | 440 | /// Adds a test case that asserts that the Zig given in `src` compiles |
| ... | @@ -462,7 +445,7 @@ pub const TestContext = struct { | ... | @@ -462,7 +445,7 @@ pub const TestContext = struct { |
| 462 | target: CrossTarget, | 445 | target: CrossTarget, |
| 463 | src: [:0]const u8, | 446 | src: [:0]const u8, |
| 464 | ) void { | 447 | ) void { |
| 465 | ctx.addCompiles(name, target, .Zig, src); | 448 | ctx.addCompiles(name, target, src); |
| 466 | } | 449 | } |
| 467 | | 450 | |
| 468 | /// Adds a test case that asserts that the ZIR given in `src` compiles | 451 | /// Adds a test case that asserts that the ZIR given in `src` compiles |
| ... | @@ -489,7 +472,7 @@ pub const TestContext = struct { | ... | @@ -489,7 +472,7 @@ pub const TestContext = struct { |
| 489 | expected_errors: []const []const u8, | 472 | expected_errors: []const []const u8, |
| 490 | fixed_src: [:0]const u8, | 473 | fixed_src: [:0]const u8, |
| 491 | ) void { | 474 | ) void { |
| 492 | var case = ctx.addObj(name, target, .Zig); | 475 | var case = ctx.addObj(name, target); |
| 493 | case.addError(src, expected_errors); | 476 | case.addError(src, expected_errors); |
| 494 | case.compiles(fixed_src); | 477 | case.compiles(fixed_src); |
| 495 | } | 478 | } |
| ... | @@ -614,10 +597,7 @@ pub const TestContext = struct { | ... | @@ -614,10 +597,7 @@ pub const TestContext = struct { |
| 614 | .path = try std.fs.path.join(arena, &[_][]const u8{ tmp_dir_path, "zig-cache" }), | 597 | .path = try std.fs.path.join(arena, &[_][]const u8{ tmp_dir_path, "zig-cache" }), |
| 615 | }; | 598 | }; |
| 616 | | 599 | |
| 617 | const tmp_src_path = switch (case.extension) { | 600 | const tmp_src_path = "test_case.zig"; |
| 618 | .Zig => "test_case.zig", | | |
| 619 | .ZIR => "test_case.zir", | | |
| 620 | }; | | |
| 621 | | 601 | |
| 622 | var root_pkg: Package = .{ | 602 | var root_pkg: Package = .{ |
| 623 | .root_src_directory = .{ .path = tmp_dir_path, .handle = tmp.dir }, | 603 | .root_src_directory = .{ .path = tmp_dir_path, .handle = tmp.dir }, |