diff options
| author | Chris Boesch <chrboesch@noreply.codeberg.org> | 2025-12-29 12:46:28 +0100 |
|---|---|---|
| committer | Chris Boesch <chrboesch@noreply.codeberg.org> | 2025-12-29 12:46:28 +0100 |
| commit | 4927ef6a2624430d9be54d40350b1c0e60a3fb06 (patch) | |
| tree | 85f54e6b6f190250322c233fa5b3a9e8965b9332 /test | |
| parent | a5febf58c9f9229bdf9e57df727fa45ea47d2fd6 (diff) | |
| parent | e8f81ddb96208bd363df2e4cc1af906fa84f0aef (diff) | |
Merge pull request 'Integrate file system I/O with the std.Io interface' (#339) from std_Io into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/339
Diffstat (limited to 'test')
| -rw-r--r-- | test/tests.zig | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/test/tests.zig b/test/tests.zig index 9a8e9e9..36fabfa 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -3,16 +3,14 @@ const root = @import("../build.zig"); const debug = std.debug; const fmt = std.fmt; -const fs = std.fs; const mem = std.mem; const Allocator = std.mem.Allocator; const Child = std.process.Child; const Build = std.Build; -const LazyPath = std.Build.LazyPath; -const Reader = fs.File.Reader; -const RunStep = std.Build.RunStep; const Step = Build.Step; +const RunStep = Build.RunStep; +const LazyPath = Build.LazyPath; const Exercise = root.Exercise; @@ -152,17 +150,17 @@ const CheckNamedStep = struct { fn make(step: *Step, _: Step.MakeOptions) !void { const b = step.owner; + const io = b.graph.io; const self: *CheckNamedStep = @alignCast(@fieldParentPtr("step", step)); const ex = self.exercise; - const stderr_file = try fs.cwd().openFile( + const stderr_file = try std.Io.Dir.cwd().openFile( + io, self.stderr.getPath(b), .{ .mode = .read_only }, ); - defer stderr_file.close(); + defer stderr_file.close(io); - var threaded: std.Io.Threaded = .init_single_threaded; - const io = threaded.io(); var stderr = stderr_file.readerStreaming(io, &.{}); { // Skip the logo. @@ -206,17 +204,17 @@ const CheckStep = struct { fn make(step: *Step, _: Step.MakeOptions) !void { const b = step.owner; + const io = b.graph.io; const self: *CheckStep = @alignCast(@fieldParentPtr("step", step)); const exercises = self.exercises; - const stderr_file = try fs.cwd().openFile( + const stderr_file = try std.Io.Dir.cwd().openFile( + io, self.stderr.getPath(b), .{ .mode = .read_only }, ); - defer stderr_file.close(); + defer stderr_file.close(io); - var threaded: std.Io.Threaded = .init_single_threaded; - const io = threaded.io(); var stderr = stderr_file.readerStreaming(io, &.{}); for (exercises) |ex| { if (ex.number() == 1) { @@ -234,7 +232,7 @@ const CheckStep = struct { } }; -fn check_output(step: *Step, exercise: Exercise, reader: *Reader) !void { +fn check_output(step: *Step, exercise: Exercise, reader: *std.Io.File.Reader) !void { const b = step.owner; var buf: [1024]u8 = undefined; @@ -301,7 +299,7 @@ fn check( } } -fn readLine(reader: *fs.File.Reader, buf: []u8) !?[]const u8 { +fn readLine(reader: *std.Io.File.Reader, buf: []u8) !?[]const u8 { try reader.interface.readSliceAll(buf); return mem.trimEnd(u8, buf, " \r\n"); } @@ -379,8 +377,9 @@ const HealStep = struct { /// Heals all the exercises. fn heal(allocator: Allocator, exercises: []const Exercise, work_path: []const u8) !void { - const sep = std.fs.path.sep_str; - const join = fs.path.join; + const io = std.Options.debug_io; + const sep = std.Io.Dir.path.sep_str; + const join = std.Io.Dir.path.join; const exercises_path = "exercises"; const patches_path = "patches" ++ sep ++ "patches"; @@ -398,19 +397,17 @@ fn heal(allocator: Allocator, exercises: []const Exercise, work_path: []const u8 const argv = &.{ "patch", "-i", patch, "-o", output, "-s", file }; var child = Child.init(argv, allocator); - _ = try child.spawnAndWait(); + _ = try child.spawnAndWait(io); } } /// This function is the same as the one in std.Build.makeTempPath, with the /// difference that returns an error when the temp path cannot be created. pub fn makeTempPath(b: *Build) ![]const u8 { + const io = b.graph.io; const rand_int = std.crypto.random.int(u64); - 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); - - return path; + const tmp_dir_sub_path = "tmp" ++ std.Io.Dir.path.sep_str ++ std.fmt.hex(rand_int); + const result_path = b.cache_root.join(b.allocator, &.{tmp_dir_sub_path}) catch @panic("OOM"); + try b.cache_root.handle.createDirPath(io, tmp_dir_sub_path); + return result_path; } |
