From e2d20bb8059d04cb4a89d32b7d5b797eb817bfd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Tue, 7 Jun 2022 06:30:18 +0300 Subject: [PATCH] formatting --- src/File.zig | 26 +++++++++++++++++++------- src/libnss.zig | 4 ++-- src/unix2db/main.zig | 8 +++++++- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/File.zig b/src/File.zig index 15813b4..46944b4 100644 --- a/src/File.zig +++ b/src/File.zig @@ -37,11 +37,12 @@ pub fn close(self: *File) void { const testing = std.testing; -pub const TestFile = struct { +pub const TestDB = struct { + allocator: Allocator, dir: testing.TmpDir, path: [:0]const u8, - pub fn init(allocator: Allocator) !TestFile { + pub fn init(allocator: Allocator) !TestDB { var corpus = try Corpus.testCorpus(allocator); defer corpus.deinit(); @@ -52,13 +53,20 @@ pub const TestFile = struct { errdefer tmp.cleanup(); const base_path = blk: { - const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); + const relative_path = try fs.path.join(allocator, &[_][]const u8{ + "zig-cache", + "tmp", + tmp.sub_path[0..], + }); const real_path = try fs.realpathAlloc(allocator, relative_path); allocator.free(relative_path); break :blk real_path; }; - const full_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "db.turbo\x00" }); + const full_path = try fs.path.join(allocator, &[_][]const u8{ + base_path, + "turbo.db\x00", + }); allocator.free(base_path); const mode = os.O.RDWR | os.O.CREAT | os.O.EXCL; @@ -67,11 +75,15 @@ pub const TestFile = struct { _ = try os.writev(fd, db.iov().constSlice()); - return TestFile{ .dir = tmp, .path = full_path[0 .. full_path.len - 1 :0] }; + return TestDB{ + .dir = tmp, + .path = full_path[0 .. full_path.len - 1 :0], + .allocator = allocator, + }; } - pub fn deinit(self: *TestFile, allocator: Allocator) void { + pub fn deinit(self: *TestDB) void { self.dir.cleanup(); - allocator.free(self.path); + self.allocator.free(self.path); } }; diff --git a/src/libnss.zig b/src/libnss.zig index 7ded9e6..abe982f 100644 --- a/src/libnss.zig +++ b/src/libnss.zig @@ -131,8 +131,8 @@ export fn _nss_turbo_getpwuid_r( const testing = std.testing; test "nss_turbo_getpwuid_r" { - var tf = try File.TestFile.init(testing.allocator); - defer tf.deinit(testing.allocator); + var tf = try File.TestDB.init(testing.allocator); + defer tf.deinit(); var env = try process.getEnvMap(testing.allocator); defer env.deinit(); diff --git a/src/unix2db/main.zig b/src/unix2db/main.zig index 05ed2af..829cd32 100644 --- a/src/unix2db/main.zig +++ b/src/unix2db/main.zig @@ -112,4 +112,10 @@ test "invalid argument" { )); } -test "smoke test" {} +test "smoke test" { + const allocator = testing.allocator; + const args = &[_][*:0]const u8{"--invalid-argument"}; + var stderr = ArrayList(u8).init(allocator); + defer stderr.deinit(); + _ = args; +}