diff options
Diffstat (limited to 'core/panes.zig')
| -rw-r--r-- | core/panes.zig | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/core/panes.zig b/core/panes.zig index 280fd3f9..4b9aa7a7 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -1073,11 +1073,21 @@ pub const Pane = struct { const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit status fits 16 // A failed run's last rows, read before its `exit N` goes under // them: a report's places are at its end, and its detail is the - // tool's lines, not the run's status (UX F2). + // tool's lines, not the run's status (UX F2). Its own: those after + // its `% line` (exec.echoCommand), not a run's before it in the + // pane, whose places are no longer where it said. const rows: ?[]const []const u8 = if (status == 0) null else if (pane.terminal) |state| read: { const grid = Term.grid(state); const first = grid.total -| 400; - break :read Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch null; + const last = Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch break :read null; + const command = pane.command orelse break :read last; + var from = last.len; + while (from > 0) { + from -= 1; + const echo = std.mem.trimEnd(u8, last[from], " "); + if (echo.len > "% ".len and std.mem.startsWith(u8, echo, "% ") and std.mem.startsWith(u8, command, echo["% ".len..])) break :read last[from + 1 ..]; + } + break :read last; } else null; var said: pardes.Kind.Buf(32) = .{}; const lead = if (Term.grid(pane.terminal).cursor_x != 0) "\r\n" else ""; @@ -2002,3 +2012,37 @@ test "a command whose run fails naming places is an error of its pane, those pla while (p.nextEffect()) |_| {} try std.testing.expect(p.messages.headline() == null or p.messages.headline().?.kind != .@"error"); } + +test "a failed run's error names that run's places, each once: a rerun in the same pane does not read the run before it again, and a note at an error's place is not a second place" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane's terminal + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{}); + defer p.deinit(); + while (p.nextEffect()) |_| {} + p.setCwd(.at(0), "/tmp/pardes-cmd"); + _ = try pardes.Kind.open(p, 1, pardes.Kind.test_kind.of(p), "/tmp/pardes-cmd/pic.ppm", null); + const dst = exec.execute(p, 1, "zig build") orelse return error.NoCommandPane; + while (p.nextEffect()) |_| {} + // `zig build`'s report, ZIG_BUILD_ERROR_STYLE=minimal: the error, its + // source line and caret, a note at the same place; then the same + // error a line lower once a line went in above it. + for ([_]u32{ 11, 12 }) |line| { + var out: [512]u8 = undefined; + p.update(.{ .output = .{ .pane = .at(dst), .bytes = try std.fmt.bufPrint(&out, "report.zig:{d}:9: error: local variable is never mutated\r\n var s = if (c.words == 1) \"\" else \"s\";\r\n ^\r\nreport.zig:{d}:9: note: consider using 'const'\r\nerror: 1 compilation errors\r\n", .{ line, line }) } }); + p.update(.{ .exited = .{ .pane = .at(dst), .status = 2 } }); + const said = p.messages.headline() orelse return error.NothingSaid; + try std.testing.expectEqual(pardes.Messages.Kind.@"error", said.kind); + var names: [256]u8 = undefined; + var w: std.Io.Writer = .fixed(&names); + for (said.places[0..said.places_len]) |*place| try w.print("{s}:{d}:{d} ", .{ place.path.slice(), place.line, place.col }); + var want: [64]u8 = undefined; + try std.testing.expectEqualStrings(try std.fmt.bufPrint(&want, "/tmp/pardes-cmd/report.zig:{d}:9 ", .{line}), w.buffered()); + try std.testing.expectEqualStrings("local variable is never mutated", said.places[0].text.slice()); + try std.testing.expectEqual(@as(u8, 2), said.detail_len); + if (line == 12) break; + // Its next run, in the same pane: the rows above are the last run's. + p.update(.{ .eof = .{ .pane = .at(dst) } }); + try std.testing.expectEqual(@as(?usize, dst), exec.execute(p, 1, "zig build")); + while (p.nextEffect()) |_| {} + } +} |
