From 2cdc2ae6c662579e14c8f7d0dedb6b8873465ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Tue, 12 Jul 2022 12:59:47 +0300 Subject: [PATCH] prefix test cases with context --- src/Corpus.zig | 2 +- src/DB.zig | 16 ++++++++-------- src/ErrCtx.zig | 6 +++--- src/Group.zig | 2 +- src/PackedGroup.zig | 2 +- src/PackedUser.zig | 4 ++-- src/User.zig | 2 +- src/cmph.zig | 8 ++++---- src/compress.zig | 18 +++++++++--------- src/header.zig | 6 +++--- src/libnss.zig | 6 +++--- src/padding.zig | 2 +- src/shell.zig | 2 +- src/turbo-analyze.zig | 4 ++-- src/turbo-unix2db.zig | 8 ++++---- 15 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/Corpus.zig b/src/Corpus.zig index 18df47b..a9b8ddf 100644 --- a/src/Corpus.zig +++ b/src/Corpus.zig @@ -285,7 +285,7 @@ pub fn testCorpus(allocator: Allocator) !Corpus { return result; } -test "test corpus" { +test "corpus smoke test" { var corpus = try testCorpus(testing.allocator); defer corpus.deinit(); diff --git a/src/DB.zig b/src/DB.zig index 055f572..50c8473 100644 --- a/src/DB.zig +++ b/src/DB.zig @@ -760,7 +760,7 @@ fn assertDefinedLayout(comptime T: type) void { const testing = std.testing; -test "read/write via iovec" { +test "DB read/write via iovec" { const allocator = testing.allocator; var corpus = try Corpus.testCorpus(allocator); defer corpus.deinit(); @@ -787,7 +787,7 @@ test "read/write via iovec" { try testing.expectEqualStrings("", errc.unwrap().constSlice()); } -test "getgrnam/getgrgid" { +test "DB getgrnam/getgrgid" { var corpus = try Corpus.testCorpus(testing.allocator); defer corpus.deinit(); var errc = ErrCtx{}; @@ -829,7 +829,7 @@ test "getgrnam/getgrgid" { try testing.expectError(error.BufferTooSmall, db.getgrnam("all", buf, false)); } -test "getpwnam/getpwuid" { +test "DB getpwnam/getpwuid" { var corpus = try Corpus.testCorpus(testing.allocator); defer corpus.deinit(); var errc = ErrCtx{}; @@ -863,7 +863,7 @@ test "getpwnam/getpwuid" { try testing.expectError(error.BufferTooSmall, db.getpwnam("Name" ** 8, buf)); } -test "additionalGids" { +test "DB additionalGids" { const allocator = testing.allocator; var corpus = try Corpus.testCorpus(allocator); defer corpus.deinit(); @@ -892,7 +892,7 @@ test "additionalGids" { } } -test "pack gids" { +test "DB pack gids" { const allocator = testing.allocator; var corpus = try Corpus.testCorpus(allocator); defer corpus.deinit(); @@ -922,7 +922,7 @@ fn expectUsedHashes(allocator: Allocator, arr: []const u32) !void { try testing.expect(used.get(item) != null); } -test "bdzIdx on u32" { +test "DB bdzIdx on u32" { const keys = [_]u32{ 42, 1, 2, 3 }; const mphf = try cmph.packU32(testing.allocator, keys[0..]); defer testing.allocator.free(mphf); @@ -931,7 +931,7 @@ test "bdzIdx on u32" { try expectUsedHashes(testing.allocator, result); } -test "bdzIdx on str" { +test "DB bdzIdx on str" { const keys = [_][]const u8{ "42", "1", "2", "3" }; const mphf = try cmph.packStr(testing.allocator, keys[0..]); defer testing.allocator.free(mphf); @@ -940,7 +940,7 @@ test "bdzIdx on str" { try expectUsedHashes(testing.allocator, result); } -test "nblocks" { +test "DB nblocks" { const tests = .{ .{ 0, &[_]u8{} }, .{ 1, &[_]u8{ 1, 2, 42 } }, diff --git a/src/ErrCtx.zig b/src/ErrCtx.zig index 7f5f164..2ed375e 100644 --- a/src/ErrCtx.zig +++ b/src/ErrCtx.zig @@ -104,7 +104,7 @@ pub fn unwrap(self: *const ErrCtx) BoundedArray(u8, capacity * 2) { const testing = std.testing; -test "basics" { +test "ErrCtx basics" { var ctx = ErrCtx{}; var wr = ctx.writer(); @@ -128,7 +128,7 @@ test "basics" { try testing.expectEqualSlices(u8, it_rev.next().?, "0" ** 10); } -test "almost overflow" { +test "ErrCtx almost overflow" { var ctx = ErrCtx{}; var wr = ctx.writer(); @@ -146,7 +146,7 @@ test "almost overflow" { try testing.expectEqual(it.next(), null); } -test "rev" { +test "ErrCtx rev" { var ctx = ErrCtx{}; ctx.print("yadda {s}", .{"xx"}); diff --git a/src/Group.zig b/src/Group.zig index a2b5929..6f21e0c 100644 --- a/src/Group.zig +++ b/src/Group.zig @@ -141,7 +141,7 @@ pub const ptr_size = @sizeOf(meta.Child(meta.fieldInfo(CGroup, .members).field_t const testing = std.testing; -test "Group.clone" { +test "Group clone" { // TODO: how to do this on stack? var member1 = mem.sliceTo(try testing.allocator.dupeZ(u8, "member1"), 0); defer testing.allocator.free(member1); diff --git a/src/PackedGroup.zig b/src/PackedGroup.zig index d799a10..0029257 100644 --- a/src/PackedGroup.zig +++ b/src/PackedGroup.zig @@ -116,7 +116,7 @@ test "PackedGroup alignment" { try testing.expectEqual(@sizeOf(PackedGroup) * 8, @bitSizeOf(PackedGroup)); } -test "construct PackedGroups" { +test "PackedGroup construct" { var buf = ArrayList(u8).init(testing.allocator); defer buf.deinit(); diff --git a/src/PackedUser.zig b/src/PackedUser.zig index 6b2fae6..a3f7c4a 100644 --- a/src/PackedUser.zig +++ b/src/PackedUser.zig @@ -247,7 +247,7 @@ const test_shell_reader = ShellReader{ .index = &[_]u16{ 0, 9, 17 }, }; -test "pack max_user" { +test "PackedUser pack max_user" { var arr = ArrayList(u8).init(testing.allocator); defer arr.deinit(); @@ -257,7 +257,7 @@ test "pack max_user" { try packTo(&arr, User.max_user, 0, idx_noop); } -test "construct PackedUser section" { +test "PackedUser construct section" { var buf = ArrayList(u8).init(testing.allocator); defer buf.deinit(); diff --git a/src/User.zig b/src/User.zig index 8beefb5..ddb89f5 100644 --- a/src/User.zig +++ b/src/User.zig @@ -234,7 +234,7 @@ test "User.fromLine" { } } -test "max_user and max_str_len are consistent" { +test "User max_user and max_str_len are consistent" { const total_len = max_user.name.len + max_user.gecos.len + max_user.home.len + diff --git a/src/cmph.zig b/src/cmph.zig index 965370a..9d0dce7 100644 --- a/src/cmph.zig +++ b/src/cmph.zig @@ -89,7 +89,7 @@ fn samplePack(allocator: Allocator) ![]const u8 { return pack(allocator, vector.items); } -test "basic pack/unpack" { +test "cmph basic pack/unpack" { const buf = try samplePack(testing.allocator); defer testing.allocator.free(buf); try testing.expect(buf.len < 100); @@ -111,7 +111,7 @@ pub fn unzeroZ(x: u32) [6]u8 { return buf; } -test "unzeroZ" { +test "cmph unzeroZ" { const result = unzeroZ(0); try testing.expect(result[0] != 0); try testing.expect(result[1] != 0); @@ -121,7 +121,7 @@ test "unzeroZ" { try testing.expect(result[5] == 0); } -test "pack u32" { +test "cmph pack u32" { const keys = &[_]u32{ 42, 1, math.maxInt(u32), 2 }; const packed_mphf = try packU32(testing.allocator, keys); defer testing.allocator.free(packed_mphf); @@ -133,7 +133,7 @@ test "pack u32" { try testing.expectEqual(i, hash); } -test "pack str" { +test "cmph pack str" { const keys = &[_][]const u8{ "foo", "bar", "baz", "1", "2", "3" }; const packed_mphf = try packStr(testing.allocator, keys[0..]); defer testing.allocator.free(packed_mphf); diff --git a/src/compress.zig b/src/compress.zig index 53da613..eb28301 100644 --- a/src/compress.zig +++ b/src/compress.zig @@ -209,7 +209,7 @@ const uvarint_tests = [_]u64{ 1 << 63 - 1, }; -test "putUvarint/uvarint" { +test "compress putUvarint/uvarint" { for (uvarint_tests) |x| { var buf: [maxVarintLen64]u8 = undefined; const n = putUvarint(buf[0..], x); @@ -220,7 +220,7 @@ test "putUvarint/uvarint" { } } -test "varintSliceIterator" { +test "compress varintSliceIterator" { var buf = ArrayList(u8).init(testing.allocator); defer buf.deinit(); try appendUvarint(&buf, uvarint_tests.len); @@ -235,7 +235,7 @@ test "varintSliceIterator" { try testing.expectEqual(i, uvarint_tests.len); } -test "delta compress/decompress" { +test "compress delta compress/decompress" { const tests = [_]struct { input: []const u8, want: []const u8 }{ .{ .input = &[_]u8{}, .want = &[_]u8{} }, .{ .input = &[_]u8{0}, .want = &[_]u8{0} }, @@ -260,7 +260,7 @@ test "delta compress/decompress" { } } -test "delta compression with varint tests" { +test "compress delta compression with varint tests" { var scratch: [uvarint_tests.len]u64 = undefined; std.mem.copy(u64, scratch[0..], uvarint_tests[0..]); try deltaCompress(u64, scratch[0..]); @@ -268,7 +268,7 @@ test "delta compression with varint tests" { try testing.expectEqualSlices(u64, uvarint_tests[0..], scratch[0..]); } -test "delta compression negative tests" { +test "compress delta compression negative tests" { for ([_][]const u8{ &[_]u8{ 0, 0 }, &[_]u8{ 0, 1, 1 }, @@ -281,7 +281,7 @@ test "delta compression negative tests" { } } -test "delta decompress overflow" { +test "compress delta decompress overflow" { for ([_][]const u8{ &[_]u8{ 255, 0 }, &[_]u8{ 0, 128, 127 }, @@ -293,7 +293,7 @@ test "delta decompress overflow" { } } -test "delta decompression with an iterator" { +test "compress delta decompression with an iterator" { var compressed: [uvarint_tests.len]u64 = undefined; std.mem.copy(u64, compressed[0..], uvarint_tests[0..]); try deltaCompress(u64, compressed[0..]); @@ -314,7 +314,7 @@ test "delta decompression with an iterator" { try testing.expectEqual(i, uvarint_tests.len); } -test "appendUvarint" { +test "compress appendUvarint" { for (uvarint_tests) |x| { var buf = ArrayList(u8).init(testing.allocator); defer buf.deinit(); @@ -326,7 +326,7 @@ test "appendUvarint" { } } -test "overflow" { +test "compress overflow" { for ([_][]const u8{ &[_]u8{ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x2 }, &[_]u8{ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1, 0, 0 }, diff --git a/src/header.zig b/src/header.zig index 4e95919..2a8c516 100644 --- a/src/header.zig +++ b/src/header.zig @@ -75,15 +75,15 @@ pub const Header = packed struct { const testing = std.testing; -test "Section length is a power of two" { +test "header Section length is a power of two" { try testing.expect(std.math.isPowerOfTwo(section_length)); } -test "Header fits into two sections" { +test "header fits into two sections" { try testing.expect(@sizeOf(Header) == 2 * section_length); } -test "bit header size is equal to @sizeOf(Header)" { +test "header bit header size is equal to @sizeOf(Header)" { try testing.expectEqual(@sizeOf(Header) * 8, @bitSizeOf(Header)); } diff --git a/src/libnss.zig b/src/libnss.zig index fcaa230..dc03537 100644 --- a/src/libnss.zig +++ b/src/libnss.zig @@ -492,7 +492,7 @@ fn getDBErrno(errnop: *c_int) ?DB { const testing = std.testing; -test "getpwuid_r and getpwnam_r" { +test "libnss getpwuid_r and getpwnam_r" { var tf = try File.TestDB.init(testing.allocator); defer tf.deinit(); const state = State{ @@ -544,7 +544,7 @@ fn testVidmantas(u: CUser) !void { try testing.expectEqualStrings("/bin/bash", mem.sliceTo(u.pw_shell, 0)); } -test "getgrgid_r and getgrnam_r" { +test "libnss getgrgid_r and getgrnam_r" { var tf = try File.TestDB.init(testing.allocator); defer tf.deinit(); const turbonss_db_path_old = turbonss_db_path; @@ -579,7 +579,7 @@ test "getgrgid_r and getgrnam_r" { try testing.expectEqual(@enumToInt(os.E.NOENT), @intCast(u16, errno)); } -test "initgroups_dyn" { +test "libnss initgroups_dyn" { const allocator = testing.allocator; var tf = try File.TestDB.init(allocator); diff --git a/src/padding.zig b/src/padding.zig index 0ea3aa7..d154f04 100644 --- a/src/padding.zig +++ b/src/padding.zig @@ -39,7 +39,7 @@ test "padding" { try testing.expectEqual(until(u12, 2, 4092), 0); } -test "arrayList" { +test "padding arrayList" { var buf = try ArrayList(u8).initCapacity(testing.allocator, 16); defer buf.deinit(); diff --git a/src/shell.zig b/src/shell.zig index 9c4b6e6..d9d37fc 100644 --- a/src/shell.zig +++ b/src/shell.zig @@ -148,7 +148,7 @@ pub const ShellWriter = struct { const testing = std.testing; -test "basic shellpopcon" { +test "shell basic shellpopcon" { var popcon = ShellWriter.init(testing.allocator); const bash = "/bin/bash"; // 9 chars diff --git a/src/turbo-analyze.zig b/src/turbo-analyze.zig index b527e4d..9c8d90e 100644 --- a/src/turbo-analyze.zig +++ b/src/turbo-analyze.zig @@ -159,7 +159,7 @@ fn execute( const testing = std.testing; -test "trivial error: db file" { +test "turbo-analyze trivial error: db file" { const args = &[_][*:0]const u8{"/does/not/exist.turbo"}; const allocator = testing.allocator; var stderr = ArrayList(u8).init(allocator); @@ -190,7 +190,7 @@ fn splitInt(n: u64) BoundedArray(u8, max_len) { return result; } -test "separators" { +test "turbo-analyze separators" { const tests = [_]struct { input: u64, want: []const u8, diff --git a/src/turbo-unix2db.zig b/src/turbo-unix2db.zig index c0ee53d..d0107f2 100644 --- a/src/turbo-unix2db.zig +++ b/src/turbo-unix2db.zig @@ -129,7 +129,7 @@ fn fail(errc: *ErrCtx, stderr: anytype, err: anytype) u8 { const testing = std.testing; -test "invalid argument" { +test "turbo-unix2db invalid argument" { const allocator = testing.allocator; const args = &[_][*:0]const u8{"--invalid-argument"}; var stderr = ArrayList(u8).init(allocator); @@ -146,7 +146,7 @@ test "invalid argument" { )); } -test "trivial error: missing passwd file" { +test "turbo-unix2db trivial error: missing passwd file" { const allocator = testing.allocator; const args = &[_][*:0]const u8{}; var stderr = ArrayList(u8).init(allocator); @@ -159,7 +159,7 @@ test "trivial error: missing passwd file" { try testing.expectEqualStrings(stderr.items, "ERROR FileNotFound: open 'passwd'\n"); } -test "fail" { +test "turbo-unix2db fail" { var errc = ErrCtx{}; var buf = ArrayList(u8).init(testing.allocator); defer buf.deinit(); @@ -169,7 +169,7 @@ test "fail" { try testing.expectEqualStrings(buf.items, "ERROR NotSure: invalid user 'foo'\n"); } -test "smoke test" { +test "turbo-unix2db smoke test" { const allocator = testing.allocator; var stderr = ArrayList(u8).init(allocator); defer stderr.deinit();