wip: full smoke test
This commit is contained in:
@@ -65,6 +65,7 @@ fn execute(
|
||||
const groupFname = result.argFlag("--group") orelse "./group";
|
||||
const outFile = result.argFlag("--output") orelse "./db.turbo";
|
||||
|
||||
std.debug.print("passwd file name: {s}\n", .{passwdFname});
|
||||
var passwdFile = try fs.cwd().openFile(passwdFname, .{ .mode = .read_only });
|
||||
defer passwdFile.close();
|
||||
var groupFile = try fs.cwd().openFile(groupFname, .{ .mode = .read_only });
|
||||
@@ -80,7 +81,7 @@ fn execute(
|
||||
var db = try DB.fromCorpus(allocator, &corpus);
|
||||
defer db.deinit(allocator);
|
||||
|
||||
const fd = try os.open(outFile, os.O.WRONLY | os.O.TRUNC, 0644);
|
||||
const fd = try os.open(outFile, os.O.WRONLY | os.O.TRUNC | os.O.CREAT, 0644);
|
||||
errdefer os.close(fd);
|
||||
|
||||
const len = try os.writev(fd, db.iov().constSlice());
|
||||
@@ -114,8 +115,57 @@ test "invalid argument" {
|
||||
|
||||
test "smoke test" {
|
||||
const allocator = testing.allocator;
|
||||
const args = &[_][*:0]const u8{"--invalid-argument"};
|
||||
var stderr = ArrayList(u8).init(allocator);
|
||||
defer stderr.deinit();
|
||||
_ = args;
|
||||
|
||||
var corpus = try Corpus.testCorpus(allocator);
|
||||
defer corpus.deinit();
|
||||
|
||||
var tmp = testing.tmpDir(.{});
|
||||
//errdefer tmp.cleanup();
|
||||
|
||||
const tmp_path = blk: {
|
||||
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;
|
||||
};
|
||||
defer allocator.free(tmp_path);
|
||||
|
||||
const passwdPath = try fs.path.joinZ(allocator, &[_][]const u8{ tmp_path, "passwd" });
|
||||
defer allocator.free(passwdPath);
|
||||
const groupPath = try fs.path.joinZ(allocator, &[_][]const u8{ tmp_path, "group" });
|
||||
defer allocator.free(groupPath);
|
||||
const outPath = try fs.path.joinZ(allocator, &[_][]const u8{ tmp_path, "tmp.turbo" });
|
||||
defer allocator.free(outPath);
|
||||
|
||||
const passwd_fd = try os.open(passwdPath, os.O.CREAT | os.O.WRONLY, 0o644);
|
||||
const group_fd = try os.open(groupPath, os.O.CREAT | os.O.WRONLY, 0o644);
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < corpus.users.len) : (i += 1) {
|
||||
const user = corpus.users.get(i);
|
||||
const line = user.toLine();
|
||||
_ = try os.write(passwd_fd, line.constSlice());
|
||||
}
|
||||
os.close(passwd_fd);
|
||||
|
||||
var group_writer = (fs.File{ .handle = group_fd }).writer();
|
||||
i = 0;
|
||||
while (i < corpus.groups.len) : (i += 1)
|
||||
try corpus.groups.get(i).writeTo(group_writer);
|
||||
os.close(group_fd);
|
||||
|
||||
const args = &[_][*:0]const u8{
|
||||
"--passwd", passwdPath,
|
||||
"--group", groupPath,
|
||||
"--output", outPath,
|
||||
};
|
||||
const exit_code = try execute(allocator, stderr.writer(), args);
|
||||
|
||||
try testing.expectEqual(@as(u8, 0), exit_code);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user