| ... | @@ -536,6 +536,7 @@ pub const CompileErrorContext = struct { | ... | @@ -536,6 +536,7 @@ pub const CompileErrorContext = struct { |
| 536 | name: []const u8, | 536 | name: []const u8, |
| 537 | sources: ArrayList(SourceFile), | 537 | sources: ArrayList(SourceFile), |
| 538 | expected_errors: ArrayList([]const u8), | 538 | expected_errors: ArrayList([]const u8), |
| | 539 | expect_exact: bool, |
| 539 | link_libc: bool, | 540 | link_libc: bool, |
| 540 | is_exe: bool, | 541 | is_exe: bool, |
| 541 | is_test: bool, | 542 | is_test: bool, |
| ... | @@ -565,6 +566,26 @@ pub const CompileErrorContext = struct { | ... | @@ -565,6 +566,26 @@ pub const CompileErrorContext = struct { |
| 565 | case: *const TestCase, | 566 | case: *const TestCase, |
| 566 | build_mode: Mode, | 567 | build_mode: Mode, |
| 567 | | 568 | |
| | 569 | const ErrLineIter = struct { |
| | 570 | lines: mem.SplitIterator, |
| | 571 | |
| | 572 | const source_file = ".tmp_source.zig"; |
| | 573 | |
| | 574 | fn init(input: []const u8) ErrLineIter { |
| | 575 | return ErrLineIter { |
| | 576 | .lines = mem.separate(input, "\n"), |
| | 577 | }; |
| | 578 | } |
| | 579 | |
| | 580 | fn next(self: *ErrLineIter) ?[]const u8 { |
| | 581 | while (self.lines.next()) |line| { |
| | 582 | if (mem.indexOf(u8, line, source_file) != null) |
| | 583 | return line; |
| | 584 | } |
| | 585 | return null; |
| | 586 | } |
| | 587 | }; |
| | 588 | |
| 568 | pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep { | 589 | pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep { |
| 569 | const allocator = context.b.allocator; | 590 | const allocator = context.b.allocator; |
| 570 | const ptr = allocator.create(CompileCmpOutputStep) catch unreachable; | 591 | const ptr = allocator.create(CompileCmpOutputStep) catch unreachable; |
| ... | @@ -674,19 +695,50 @@ pub const CompileErrorContext = struct { | ... | @@ -674,19 +695,50 @@ pub const CompileErrorContext = struct { |
| 674 | return error.TestFailed; | 695 | return error.TestFailed; |
| 675 | } | 696 | } |
| 676 | | 697 | |
| 677 | for (self.case.expected_errors.toSliceConst()) |expected_error| { | 698 | var ok = true; |
| 678 | if (mem.indexOf(u8, stderr, expected_error) == null) { | 699 | if (self.case.expect_exact) { |
| 679 | warn( | 700 | var err_iter = ErrLineIter.init(stderr); |
| 680 | \\ | 701 | var i: usize = 0; |
| 681 | \\========= Expected this compile error: ========= | 702 | ok = while (err_iter.next()) |line| : (i += 1) { |
| 682 | \\{} | 703 | if (i >= self.case.expected_errors.len) break false; |
| 683 | \\================================================ | 704 | const expected = self.case.expected_errors.at(i); |
| 684 | \\{} | 705 | if (mem.indexOf(u8, line, expected) == null) break false; |
| 685 | \\ | 706 | continue; |
| 686 | , expected_error, stderr); | 707 | } else true; |
| 687 | return error.TestFailed; | 708 | |
| | 709 | ok = ok and i == self.case.expected_errors.len; |
| | 710 | |
| | 711 | if (!ok) { |
| | 712 | warn("\n======== Expected these compile errors: ========\n"); |
| | 713 | for (self.case.expected_errors.toSliceConst()) |expected| { |
| | 714 | warn("{}\n", expected); |
| | 715 | } |
| | 716 | } |
| | 717 | } else { |
| | 718 | for (self.case.expected_errors.toSliceConst()) |expected| { |
| | 719 | if (mem.indexOf(u8, stderr, expected) == null) { |
| | 720 | warn( |
| | 721 | \\=========== Expected compile error: ============ |
| | 722 | \\{} |
| | 723 | \\ |
| | 724 | , expected |
| | 725 | ); |
| | 726 | ok = false; |
| | 727 | break; |
| | 728 | } |
| 688 | } | 729 | } |
| 689 | } | 730 | } |
| | 731 | |
| | 732 | if (!ok) { |
| | 733 | warn( |
| | 734 | \\================= Full output: ================= |
| | 735 | \\{} |
| | 736 | \\ |
| | 737 | , stderr |
| | 738 | ); |
| | 739 | return error.TestFailed; |
| | 740 | } |
| | 741 | |
| 690 | warn("OK\n"); | 742 | warn("OK\n"); |
| 691 | } | 743 | } |
| 692 | }; | 744 | }; |
| ... | @@ -704,6 +756,7 @@ pub const CompileErrorContext = struct { | ... | @@ -704,6 +756,7 @@ pub const CompileErrorContext = struct { |
| 704 | .name = name, | 756 | .name = name, |
| 705 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), | 757 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 706 | .expected_errors = ArrayList([]const u8).init(self.b.allocator), | 758 | .expected_errors = ArrayList([]const u8).init(self.b.allocator), |
| | 759 | .expect_exact = false, |
| 707 | .link_libc = false, | 760 | .link_libc = false, |
| 708 | .is_exe = false, | 761 | .is_exe = false, |
| 709 | .is_test = false, | 762 | .is_test = false, |