formatting

This commit is contained in:
Motiejus Jakštys 2022-06-07 06:30:18 +03:00
parent a5c24ace80
commit e2d20bb805
3 changed files with 28 additions and 10 deletions

View File

@ -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);
}
};

View File

@ -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();

View File

@ -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;
}