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