| ... | ... | @@ -236,6 +236,7 @@ pub const ExpectedCompileErrors = union(enum) { |
| 236 | 236 | contains: []const u8, |
| 237 | 237 | exact: []const []const u8, |
| 238 | 238 | starts_with: []const u8, |
| 239 | stderr_contains: []const u8, |
| 239 | 240 | }; |
| 240 | 241 | |
| 241 | 242 | pub const Entry = union(enum) { |
| ... | ... | @@ -1945,24 +1946,24 @@ fn checkCompileErrors(compile: *Compile) !void { |
| 1945 | 1946 | |
| 1946 | 1947 | const arena = compile.step.owner.allocator; |
| 1947 | 1948 | |
| 1948 | | var actual_stderr_list = std.ArrayList(u8).init(arena); |
| 1949 | var actual_errors_list = std.ArrayList(u8).init(arena); |
| 1949 | 1950 | try actual_eb.renderToWriter(.{ |
| 1950 | 1951 | .ttyconf = .no_color, |
| 1951 | 1952 | .include_reference_trace = false, |
| 1952 | 1953 | .include_source_line = false, |
| 1953 | | }, actual_stderr_list.writer()); |
| 1954 | | const actual_stderr = try actual_stderr_list.toOwnedSlice(); |
| 1954 | }, actual_errors_list.writer()); |
| 1955 | const actual_errors = try actual_errors_list.toOwnedSlice(); |
| 1955 | 1956 | |
| 1956 | 1957 | // Render the expected lines into a string that we can compare verbatim. |
| 1957 | 1958 | var expected_generated = std.ArrayList(u8).init(arena); |
| 1958 | 1959 | const expect_errors = compile.expect_errors.?; |
| 1959 | 1960 | |
| 1960 | | var actual_line_it = mem.splitScalar(u8, actual_stderr, '\n'); |
| 1961 | var actual_line_it = mem.splitScalar(u8, actual_errors, '\n'); |
| 1961 | 1962 | |
| 1962 | 1963 | // TODO merge this with the testing.expectEqualStrings logic, and also CheckFile |
| 1963 | 1964 | switch (expect_errors) { |
| 1964 | 1965 | .starts_with => |expect_starts_with| { |
| 1965 | | if (std.mem.startsWith(u8, actual_stderr, expect_starts_with)) return; |
| 1966 | if (std.mem.startsWith(u8, actual_errors, expect_starts_with)) return; |
| 1966 | 1967 | return compile.step.fail( |
| 1967 | 1968 | \\ |
| 1968 | 1969 | \\========= should start with: ============ |
| ... | ... | @@ -1970,7 +1971,7 @@ fn checkCompileErrors(compile: *Compile) !void { |
| 1970 | 1971 | \\========= but not found: ================ |
| 1971 | 1972 | \\{s} |
| 1972 | 1973 | \\========================================= |
| 1973 | | , .{ expect_starts_with, actual_stderr }); |
| 1974 | , .{ expect_starts_with, actual_errors }); |
| 1974 | 1975 | }, |
| 1975 | 1976 | .contains => |expect_line| { |
| 1976 | 1977 | while (actual_line_it.next()) |actual_line| { |
| ... | ... | @@ -1978,6 +1979,29 @@ fn checkCompileErrors(compile: *Compile) !void { |
| 1978 | 1979 | return; |
| 1979 | 1980 | } |
| 1980 | 1981 | |
| 1982 | return compile.step.fail( |
| 1983 | \\ |
| 1984 | \\========= should contain: =============== |
| 1985 | \\{s} |
| 1986 | \\========= but not found: ================ |
| 1987 | \\{s} |
| 1988 | \\========================================= |
| 1989 | , .{ expect_line, actual_errors }); |
| 1990 | }, |
| 1991 | .stderr_contains => |expect_line| { |
| 1992 | const actual_stderr: []const u8 = if (compile.step.result_error_msgs.items.len > 0) |
| 1993 | compile.step.result_error_msgs.items[0] |
| 1994 | else |
| 1995 | &.{}; |
| 1996 | compile.step.result_error_msgs.clearRetainingCapacity(); |
| 1997 | |
| 1998 | var stderr_line_it = mem.splitScalar(u8, actual_stderr, '\n'); |
| 1999 | |
| 2000 | while (stderr_line_it.next()) |actual_line| { |
| 2001 | if (!matchCompileError(actual_line, expect_line)) continue; |
| 2002 | return; |
| 2003 | } |
| 2004 | |
| 1981 | 2005 | return compile.step.fail( |
| 1982 | 2006 | \\ |
| 1983 | 2007 | \\========= should contain: =============== |
| ... | ... | @@ -2003,7 +2027,7 @@ fn checkCompileErrors(compile: *Compile) !void { |
| 2003 | 2027 | try expected_generated.append('\n'); |
| 2004 | 2028 | } |
| 2005 | 2029 | |
| 2006 | | if (mem.eql(u8, expected_generated.items, actual_stderr)) return; |
| 2030 | if (mem.eql(u8, expected_generated.items, actual_errors)) return; |
| 2007 | 2031 | |
| 2008 | 2032 | return compile.step.fail( |
| 2009 | 2033 | \\ |
| ... | ... | @@ -2012,7 +2036,7 @@ fn checkCompileErrors(compile: *Compile) !void { |
| 2012 | 2036 | \\========= but found: ==================== |
| 2013 | 2037 | \\{s} |
| 2014 | 2038 | \\========================================= |
| 2015 | | , .{ expected_generated.items, actual_stderr }); |
| 2039 | , .{ expected_generated.items, actual_errors }); |
| 2016 | 2040 | }, |
| 2017 | 2041 | } |
| 2018 | 2042 | } |