authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-08 23:14:34-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:09-08:00
log03526c59d4e2a00f83347cf06c741a3ed4fec520
tree42f6f8f29ab7d233ae7f043021f2fdeb16ff3b40
parent5b436d2c5125b9cf9a08b3bff0dcb0248c4d1ec0

std.debug: fix printLineFromFile


4 files changed, 10 insertions(+), 12 deletions(-)

lib/compiler/test_runner.zig+2-2
...@@ -75,7 +75,7 @@ pub fn main() void {...@@ -75,7 +75,7 @@ pub fn main() void {
75fn mainServer() !void {75fn mainServer() !void {
76 @disableInstrumentation();76 @disableInstrumentation();
77 var stdin_reader = Io.File.stdin().readerStreaming(runner_threaded_io.io(), &stdin_buffer);77 var stdin_reader = Io.File.stdin().readerStreaming(runner_threaded_io.io(), &stdin_buffer);
78 var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);78 var stdout_writer = Io.File.stdout().writerStreaming(runner_threaded_io.io(), &stdout_buffer);
79 var server = try std.zig.Server.init(.{79 var server = try std.zig.Server.init(.{
80 .in = &stdin_reader.interface,80 .in = &stdin_reader.interface,
81 .out = &stdout_writer.interface,81 .out = &stdout_writer.interface,
...@@ -228,7 +228,7 @@ fn mainTerminal() void {...@@ -228,7 +228,7 @@ fn mainTerminal() void {
228 .root_name = "Test",228 .root_name = "Test",
229 .estimated_total_items = test_fn_list.len,229 .estimated_total_items = test_fn_list.len,
230 });230 });
231 const have_tty = Io.File.stderr().isTty();231 const have_tty = Io.File.stderr().isTty(runner_threaded_io.io()) catch unreachable;
232232
233 var leaks: usize = 0;233 var leaks: usize = 0;
234 for (test_fn_list, 0..) |test_fn, i| {234 for (test_fn_list, 0..) |test_fn, i| {
lib/std/Io/File.zig+1-1
...@@ -280,7 +280,7 @@ pub fn sync(file: File, io: Io) SyncError!void {...@@ -280,7 +280,7 @@ pub fn sync(file: File, io: Io) SyncError!void {
280/// See also:280/// See also:
281/// * `enableAnsiEscapeCodes`281/// * `enableAnsiEscapeCodes`
282/// * `supportsAnsiEscapeCodes`.282/// * `supportsAnsiEscapeCodes`.
283pub fn isTty(file: File, io: Io) bool {283pub fn isTty(file: File, io: Io) Io.Cancelable!bool {
284 return io.vtable.fileIsTty(io.userdata, file);284 return io.vtable.fileIsTty(io.userdata, file);
285}285}
286286
lib/std/debug.zig+4-6
...@@ -1207,9 +1207,8 @@ fn printLineFromFile(io: Io, writer: *Writer, source_location: SourceLocation) !...@@ -1207,9 +1207,8 @@ fn printLineFromFile(io: Io, writer: *Writer, source_location: SourceLocation) !
12071207
1208 var buffer: [4096]u8 = undefined;1208 var buffer: [4096]u8 = undefined;
1209 var file_reader: File.Reader = .init(file, io, &buffer);1209 var file_reader: File.Reader = .init(file, io, &buffer);
1210 const r = &file_reader.interface;
1211 var line_index: usize = 0;1210 var line_index: usize = 0;
1212 while (r.takeDelimiterExclusive('\n')) |line| {1211 while (try file_reader.interface.takeDelimiter('\n')) |line| {
1213 line_index += 1;1212 line_index += 1;
1214 if (line_index == source_location.line) {1213 if (line_index == source_location.line) {
1215 // TODO delete hard tabs from the language1214 // TODO delete hard tabs from the language
...@@ -1219,9 +1218,8 @@ fn printLineFromFile(io: Io, writer: *Writer, source_location: SourceLocation) !...@@ -1219,9 +1218,8 @@ fn printLineFromFile(io: Io, writer: *Writer, source_location: SourceLocation) !
1219 try writer.writeByte('\n');1218 try writer.writeByte('\n');
1220 return;1219 return;
1221 }1220 }
1222 } else |err| {
1223 return err;
1224 }1221 }
1222 return error.EndOfStream;
1225}1223}
12261224
1227test printLineFromFile {1225test printLineFromFile {
...@@ -1248,7 +1246,7 @@ test printLineFromFile {...@@ -1248,7 +1246,7 @@ test printLineFromFile {
1248 defer gpa.free(path);1246 defer gpa.free(path);
1249 try test_dir.dir.writeFile(io, .{ .sub_path = "one_line.zig", .data = "no new lines in this file, but one is printed anyway" });1247 try test_dir.dir.writeFile(io, .{ .sub_path = "one_line.zig", .data = "no new lines in this file, but one is printed anyway" });
12501248
1251 try expectError(error.EndOfFile, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));1249 try expectError(error.EndOfStream, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));
12521250
1253 try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 });1251 try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 });
1254 try expectEqualStrings("no new lines in this file, but one is printed anyway\n", aw.written());1252 try expectEqualStrings("no new lines in this file, but one is printed anyway\n", aw.written());
...@@ -1317,7 +1315,7 @@ test printLineFromFile {...@@ -1317,7 +1315,7 @@ test printLineFromFile {
1317 const writer = &file_writer.interface;1315 const writer = &file_writer.interface;
1318 try writer.splatByteAll('a', 3 * std.heap.page_size_max);1316 try writer.splatByteAll('a', 3 * std.heap.page_size_max);
13191317
1320 try expectError(error.EndOfFile, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));1318 try expectError(error.EndOfStream, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));
13211319
1322 try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 });1320 try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 });
1323 try expectEqualStrings(("a" ** (3 * std.heap.page_size_max)) ++ "\n", aw.written());1321 try expectEqualStrings(("a" ** (3 * std.heap.page_size_max)) ++ "\n", aw.written());
lib/std/testing.zig+3-3
...@@ -629,12 +629,12 @@ pub fn tmpDir(opts: Io.Dir.OpenOptions) TmpDir {...@@ -629,12 +629,12 @@ pub fn tmpDir(opts: Io.Dir.OpenOptions) TmpDir {
629 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);629 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
630630
631 const cwd = Io.Dir.cwd();631 const cwd = Io.Dir.cwd();
632 var cache_dir = cwd.makeOpenPath(".zig-cache", .{}) catch632 var cache_dir = cwd.makeOpenPath(io, ".zig-cache", .{}) catch
633 @panic("unable to make tmp dir for testing: unable to make and open .zig-cache dir");633 @panic("unable to make tmp dir for testing: unable to make and open .zig-cache dir");
634 defer cache_dir.close(io);634 defer cache_dir.close(io);
635 const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch635 const parent_dir = cache_dir.makeOpenPath(io, "tmp", .{}) catch
636 @panic("unable to make tmp dir for testing: unable to make and open .zig-cache/tmp dir");636 @panic("unable to make tmp dir for testing: unable to make and open .zig-cache/tmp dir");
637 const dir = parent_dir.makeOpenPath(&sub_path, opts) catch637 const dir = parent_dir.makeOpenPath(io, &sub_path, .{ .open_options = opts }) catch
638 @panic("unable to make tmp dir for testing: unable to make and open the tmp dir");638 @panic("unable to make tmp dir for testing: unable to make and open the tmp dir");
639639
640 return .{640 return .{