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 {
7575fn mainServer() !void {
7676 @disableInstrumentation();
7777 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);
7979 var server = try std.zig.Server.init(.{
8080 .in = &stdin_reader.interface,
8181 .out = &stdout_writer.interface,
......@@ -228,7 +228,7 @@ fn mainTerminal() void {
228228 .root_name = "Test",
229229 .estimated_total_items = test_fn_list.len,
230230 });
231 const have_tty = Io.File.stderr().isTty();
231 const have_tty = Io.File.stderr().isTty(runner_threaded_io.io()) catch unreachable;
232232
233233 var leaks: usize = 0;
234234 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 {
280280/// See also:
281281/// * `enableAnsiEscapeCodes`
282282/// * `supportsAnsiEscapeCodes`.
283pub fn isTty(file: File, io: Io) bool {
283pub fn isTty(file: File, io: Io) Io.Cancelable!bool {
284284 return io.vtable.fileIsTty(io.userdata, file);
285285}
286286
lib/std/debug.zig+4-6
......@@ -1207,9 +1207,8 @@ fn printLineFromFile(io: Io, writer: *Writer, source_location: SourceLocation) !
12071207
12081208 var buffer: [4096]u8 = undefined;
12091209 var file_reader: File.Reader = .init(file, io, &buffer);
1210 const r = &file_reader.interface;
12111210 var line_index: usize = 0;
1212 while (r.takeDelimiterExclusive('\n')) |line| {
1211 while (try file_reader.interface.takeDelimiter('\n')) |line| {
12131212 line_index += 1;
12141213 if (line_index == source_location.line) {
12151214 // TODO delete hard tabs from the language
......@@ -1219,9 +1218,8 @@ fn printLineFromFile(io: Io, writer: *Writer, source_location: SourceLocation) !
12191218 try writer.writeByte('\n');
12201219 return;
12211220 }
1222 } else |err| {
1223 return err;
12241221 }
1222 return error.EndOfStream;
12251223}
12261224
12271225test printLineFromFile {
......@@ -1248,7 +1246,7 @@ test printLineFromFile {
12481246 defer gpa.free(path);
12491247 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
12531251 try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 });
12541252 try expectEqualStrings("no new lines in this file, but one is printed anyway\n", aw.written());
......@@ -1317,7 +1315,7 @@ test printLineFromFile {
13171315 const writer = &file_writer.interface;
13181316 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
13221320 try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 });
13231321 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 {
629629 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
630630
631631 const cwd = Io.Dir.cwd();
632 var cache_dir = cwd.makeOpenPath(".zig-cache", .{}) catch
632 var cache_dir = cwd.makeOpenPath(io, ".zig-cache", .{}) catch
633633 @panic("unable to make tmp dir for testing: unable to make and open .zig-cache dir");
634634 defer cache_dir.close(io);
635 const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
635 const parent_dir = cache_dir.makeOpenPath(io, "tmp", .{}) catch
636636 @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) catch
637 const dir = parent_dir.makeOpenPath(io, &sub_path, .{ .open_options = opts }) catch
638638 @panic("unable to make tmp dir for testing: unable to make and open the tmp dir");
639639
640640 return .{