aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-12-08 23:14:34 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-23 22:15:09 -0800
commit03526c59d4e2a00f83347cf06c741a3ed4fec520 (patch)
tree42f6f8f29ab7d233ae7f043021f2fdeb16ff3b40 /lib
parent5b436d2c5125b9cf9a08b3bff0dcb0248c4d1ec0 (diff)
downloadzig-03526c59d4e2a00f83347cf06c741a3ed4fec520.tar.gz
zig-03526c59d4e2a00f83347cf06c741a3ed4fec520.zip
std.debug: fix printLineFromFile
Diffstat (limited to 'lib')
-rw-r--r--lib/compiler/test_runner.zig4
-rw-r--r--lib/std/Io/File.zig2
-rw-r--r--lib/std/debug.zig10
-rw-r--r--lib/std/testing.zig6
4 files changed, 10 insertions, 12 deletions
diff --git a/lib/compiler/test_runner.zig b/lib/compiler/test_runner.zig
index 07a6724ec0..b0ef17a7e9 100644
--- a/lib/compiler/test_runner.zig
+++ b/lib/compiler/test_runner.zig
@@ -75,7 +75,7 @@ pub fn main() void {
fn mainServer() !void {
@disableInstrumentation();
var stdin_reader = Io.File.stdin().readerStreaming(runner_threaded_io.io(), &stdin_buffer);
- var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
+ var stdout_writer = Io.File.stdout().writerStreaming(runner_threaded_io.io(), &stdout_buffer);
var server = try std.zig.Server.init(.{
.in = &stdin_reader.interface,
.out = &stdout_writer.interface,
@@ -228,7 +228,7 @@ fn mainTerminal() void {
.root_name = "Test",
.estimated_total_items = test_fn_list.len,
});
- const have_tty = Io.File.stderr().isTty();
+ const have_tty = Io.File.stderr().isTty(runner_threaded_io.io()) catch unreachable;
var leaks: usize = 0;
for (test_fn_list, 0..) |test_fn, i| {
diff --git a/lib/std/Io/File.zig b/lib/std/Io/File.zig
index 7718b56f8a..ccf18a8f56 100644
--- a/lib/std/Io/File.zig
+++ b/lib/std/Io/File.zig
@@ -280,7 +280,7 @@ pub fn sync(file: File, io: Io) SyncError!void {
/// See also:
/// * `enableAnsiEscapeCodes`
/// * `supportsAnsiEscapeCodes`.
-pub fn isTty(file: File, io: Io) bool {
+pub fn isTty(file: File, io: Io) Io.Cancelable!bool {
return io.vtable.fileIsTty(io.userdata, file);
}
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 6ffa254271..7b111215f3 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -1207,9 +1207,8 @@ fn printLineFromFile(io: Io, writer: *Writer, source_location: SourceLocation) !
var buffer: [4096]u8 = undefined;
var file_reader: File.Reader = .init(file, io, &buffer);
- const r = &file_reader.interface;
var line_index: usize = 0;
- while (r.takeDelimiterExclusive('\n')) |line| {
+ while (try file_reader.interface.takeDelimiter('\n')) |line| {
line_index += 1;
if (line_index == source_location.line) {
// TODO delete hard tabs from the language
@@ -1219,9 +1218,8 @@ fn printLineFromFile(io: Io, writer: *Writer, source_location: SourceLocation) !
try writer.writeByte('\n');
return;
}
- } else |err| {
- return err;
}
+ return error.EndOfStream;
}
test printLineFromFile {
@@ -1248,7 +1246,7 @@ test printLineFromFile {
defer gpa.free(path);
try test_dir.dir.writeFile(io, .{ .sub_path = "one_line.zig", .data = "no new lines in this file, but one is printed anyway" });
- try expectError(error.EndOfFile, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));
+ try expectError(error.EndOfStream, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));
try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 });
try expectEqualStrings("no new lines in this file, but one is printed anyway\n", aw.written());
@@ -1317,7 +1315,7 @@ test printLineFromFile {
const writer = &file_writer.interface;
try writer.splatByteAll('a', 3 * std.heap.page_size_max);
- try expectError(error.EndOfFile, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));
+ try expectError(error.EndOfStream, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));
try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 });
try expectEqualStrings(("a" ** (3 * std.heap.page_size_max)) ++ "\n", aw.written());
diff --git a/lib/std/testing.zig b/lib/std/testing.zig
index 9eb2ad5e96..ab9f1f73c3 100644
--- a/lib/std/testing.zig
+++ b/lib/std/testing.zig
@@ -629,12 +629,12 @@ pub fn tmpDir(opts: Io.Dir.OpenOptions) TmpDir {
_ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
const cwd = Io.Dir.cwd();
- var cache_dir = cwd.makeOpenPath(".zig-cache", .{}) catch
+ var cache_dir = cwd.makeOpenPath(io, ".zig-cache", .{}) catch
@panic("unable to make tmp dir for testing: unable to make and open .zig-cache dir");
defer cache_dir.close(io);
- const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
+ const parent_dir = cache_dir.makeOpenPath(io, "tmp", .{}) catch
@panic("unable to make tmp dir for testing: unable to make and open .zig-cache/tmp dir");
- const dir = parent_dir.makeOpenPath(&sub_path, opts) catch
+ const dir = parent_dir.makeOpenPath(io, &sub_path, .{ .open_options = opts }) catch
@panic("unable to make tmp dir for testing: unable to make and open the tmp dir");
return .{