diff options
| author | Chris Boesch <chrboesch@noreply.codeberg.org> | 2025-08-24 14:59:26 +0200 |
|---|---|---|
| committer | Chris Boesch <chrboesch@noreply.codeberg.org> | 2025-08-24 14:59:26 +0200 |
| commit | a46db7e0e84718d1898d26b3d798c767792c0779 (patch) | |
| tree | 9233974b52c566b83c865239fd7c73954315e2b1 /test/tests.zig | |
| parent | f5d2c5124c2728d14d4c349c9287edb00f9eb633 (diff) | |
| parent | 564ea3405d2dce481001c52b64784b5fce4bd37a (diff) | |
Merge branch 'main' into test-expect
Diffstat (limited to 'test/tests.zig')
| -rw-r--r-- | test/tests.zig | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/test/tests.zig b/test/tests.zig index 5f64f8e..b191610 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -161,7 +161,7 @@ const CheckNamedStep = struct { ); defer stderr_file.close(); - const stderr = stderr_file.reader(); + var stderr = stderr_file.readerStreaming(&.{}); { // Skip the logo. const nlines = mem.count(u8, root.logo, "\n"); @@ -169,10 +169,10 @@ const CheckNamedStep = struct { var lineno: usize = 0; while (lineno < nlines) : (lineno += 1) { - _ = try readLine(stderr, &buf); + _ = try readLine(&stderr, &buf); } } - try check_output(step, ex, stderr); + try check_output(step, ex, &stderr); } }; @@ -213,7 +213,7 @@ const CheckStep = struct { ); defer stderr_file.close(); - const stderr = stderr_file.reader(); + var stderr = stderr_file.readerStreaming(&.{}); for (exercises) |ex| { if (ex.number() == 1) { // Skip the logo. @@ -222,15 +222,15 @@ const CheckStep = struct { var lineno: usize = 0; while (lineno < nlines) : (lineno += 1) { - _ = try readLine(stderr, &buf); + _ = try readLine(&stderr, &buf); } } - try check_output(step, ex, stderr); + try check_output(step, ex, &stderr); } } }; -fn check_output(step: *Step, exercise: Exercise, reader: Reader) !void { +fn check_output(step: *Step, exercise: Exercise, reader: *Reader) !void { const b = step.owner; var buf: [1024]u8 = undefined; @@ -297,12 +297,9 @@ fn check( } } -fn readLine(reader: fs.File.Reader, buf: []u8) !?[]const u8 { - if (try reader.readUntilDelimiterOrEof(buf, '\n')) |line| { - return mem.trimRight(u8, line, " \r\n"); - } - - return null; +fn readLine(reader: *fs.File.Reader, buf: []u8) !?[]const u8 { + try reader.interface.readSliceAll(buf); + return mem.trimRight(u8, buf, " \r\n"); } /// Fails with a custom error message. @@ -405,7 +402,8 @@ fn heal(allocator: Allocator, exercises: []const Exercise, work_path: []const u8 /// difference that returns an error when the temp path cannot be created. pub fn makeTempPath(b: *Build) ![]const u8 { const rand_int = std.crypto.random.int(u64); - const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ Build.hex64(rand_int); + const rand_hex64 = std.fmt.hex(rand_int); + const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ rand_hex64; const path = b.cache_root.join(b.allocator, &.{tmp_dir_sub_path}) catch @panic("OOM"); try b.cache_root.handle.makePath(tmp_dir_sub_path); |
