mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:24:33 +01:00
std.debug: fix printLineFromFile
This commit is contained in:
parent
5b436d2c51
commit
03526c59d4
4 changed files with 10 additions and 12 deletions
|
|
@ -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| {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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 .{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue