authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-08-15 16:08:10-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-08-17 00:59:19-07:00
log8c8f3cbd43df7748d6be712db392ed8502c2a84b
tree815f83e3b735a06a8fc70557083c9f34fb3aefba
parent8f5f1ff25aebba87f8f6eb9682d7f1b7cb7d0efd

fs tests: Update some testing.expect calls to use the more specific expect functions


1 files changed, 17 insertions(+), 17 deletions(-)

lib/std/fs/test.zig+17-17
...@@ -300,7 +300,7 @@ test "readLinkAbsolute" {...@@ -300,7 +300,7 @@ test "readLinkAbsolute" {
300fn testReadLinkAbsolute(target_path: []const u8, symlink_path: []const u8) !void {300fn testReadLinkAbsolute(target_path: []const u8, symlink_path: []const u8) !void {
301 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;301 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
302 const given = try fs.readLinkAbsolute(symlink_path, buffer[0..]);302 const given = try fs.readLinkAbsolute(symlink_path, buffer[0..]);
303 try testing.expect(mem.eql(u8, target_path, given));303 try testing.expectEqualStrings(target_path, given);
304}304}
305305
306test "Dir.Iterator" {306test "Dir.Iterator" {
...@@ -328,7 +328,7 @@ test "Dir.Iterator" {...@@ -328,7 +328,7 @@ test "Dir.Iterator" {
328 try entries.append(.{ .name = name, .kind = entry.kind });328 try entries.append(.{ .name = name, .kind = entry.kind });
329 }329 }
330330
331 try testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'331 try testing.expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..'
332 try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .file }));332 try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .file }));
333 try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .directory }));333 try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .directory }));
334}334}
...@@ -395,7 +395,7 @@ test "Dir.Iterator twice" {...@@ -395,7 +395,7 @@ test "Dir.Iterator twice" {
395 try entries.append(.{ .name = name, .kind = entry.kind });395 try entries.append(.{ .name = name, .kind = entry.kind });
396 }396 }
397397
398 try testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'398 try testing.expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..'
399 try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .file }));399 try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .file }));
400 try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .directory }));400 try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .directory }));
401 }401 }
...@@ -429,7 +429,7 @@ test "Dir.Iterator reset" {...@@ -429,7 +429,7 @@ test "Dir.Iterator reset" {
429 try entries.append(.{ .name = name, .kind = entry.kind });429 try entries.append(.{ .name = name, .kind = entry.kind });
430 }430 }
431431
432 try testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'432 try testing.expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..'
433 try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .file }));433 try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .file }));
434 try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .directory }));434 try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .directory }));
435435
...@@ -542,7 +542,7 @@ test "readAllAlloc" {...@@ -542,7 +542,7 @@ test "readAllAlloc" {
542542
543 const buf1 = try file.readToEndAlloc(testing.allocator, 1024);543 const buf1 = try file.readToEndAlloc(testing.allocator, 1024);
544 defer testing.allocator.free(buf1);544 defer testing.allocator.free(buf1);
545 try testing.expect(buf1.len == 0);545 try testing.expectEqual(@as(usize, 0), buf1.len);
546546
547 const write_buf: []const u8 = "this is a test.\nthis is a test.\nthis is a test.\nthis is a test.\n";547 const write_buf: []const u8 = "this is a test.\nthis is a test.\nthis is a test.\nthis is a test.\n";
548 try file.writeAll(write_buf);548 try file.writeAll(write_buf);
...@@ -552,14 +552,14 @@ test "readAllAlloc" {...@@ -552,14 +552,14 @@ test "readAllAlloc" {
552 const buf2 = try file.readToEndAlloc(testing.allocator, 1024);552 const buf2 = try file.readToEndAlloc(testing.allocator, 1024);
553 defer testing.allocator.free(buf2);553 defer testing.allocator.free(buf2);
554 try testing.expectEqual(write_buf.len, buf2.len);554 try testing.expectEqual(write_buf.len, buf2.len);
555 try testing.expect(std.mem.eql(u8, write_buf, buf2));555 try testing.expectEqualStrings(write_buf, buf2);
556 try file.seekTo(0);556 try file.seekTo(0);
557557
558 // max_bytes == file_size558 // max_bytes == file_size
559 const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len);559 const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len);
560 defer testing.allocator.free(buf3);560 defer testing.allocator.free(buf3);
561 try testing.expectEqual(write_buf.len, buf3.len);561 try testing.expectEqual(write_buf.len, buf3.len);
562 try testing.expect(std.mem.eql(u8, write_buf, buf3));562 try testing.expectEqualStrings(write_buf, buf3);
563 try file.seekTo(0);563 try file.seekTo(0);
564564
565 // max_bytes < file_size565 // max_bytes < file_size
...@@ -586,7 +586,7 @@ test "directory operations on files" {...@@ -586,7 +586,7 @@ test "directory operations on files" {
586 // ensure the file still exists and is a file as a sanity check586 // ensure the file still exists and is a file as a sanity check
587 file = try ctx.dir.openFile(test_file_name, .{});587 file = try ctx.dir.openFile(test_file_name, .{});
588 const stat = try file.stat();588 const stat = try file.stat();
589 try testing.expect(stat.kind == .file);589 try testing.expectEqual(File.Kind.file, stat.kind);
590 file.close();590 file.close();
591 }591 }
592 }.impl);592 }.impl);
...@@ -839,7 +839,7 @@ test "renameAbsolute" {...@@ -839,7 +839,7 @@ test "renameAbsolute" {
839 try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));839 try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
840 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});840 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
841 const stat = try file.stat();841 const stat = try file.stat();
842 try testing.expect(stat.kind == .file);842 try testing.expectEqual(File.Kind.file, stat.kind);
843 file.close();843 file.close();
844844
845 // Renaming directories845 // Renaming directories
...@@ -1109,7 +1109,7 @@ test "sendfile" {...@@ -1109,7 +1109,7 @@ test "sendfile" {
1109 .header_count = 2,1109 .header_count = 2,
1110 });1110 });
1111 const amt = try dest_file.preadAll(&written_buf, 0);1111 const amt = try dest_file.preadAll(&written_buf, 0);
1112 try testing.expect(mem.eql(u8, written_buf[0..amt], "header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n"));1112 try testing.expectEqualStrings("header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n", written_buf[0..amt]);
1113}1113}
11141114
1115test "copyRangeAll" {1115test "copyRangeAll" {
...@@ -1135,7 +1135,7 @@ test "copyRangeAll" {...@@ -1135,7 +1135,7 @@ test "copyRangeAll" {
1135 _ = try src_file.copyRangeAll(0, dest_file, 0, data.len);1135 _ = try src_file.copyRangeAll(0, dest_file, 0, data.len);
11361136
1137 const amt = try dest_file.preadAll(&written_buf, 0);1137 const amt = try dest_file.preadAll(&written_buf, 0);
1138 try testing.expect(mem.eql(u8, written_buf[0..amt], data));1138 try testing.expectEqualStrings(data, written_buf[0..amt]);
1139}1139}
11401140
1141test "copyFile" {1141test "copyFile" {
...@@ -1185,7 +1185,7 @@ test "AtomicFile" {...@@ -1185,7 +1185,7 @@ test "AtomicFile" {
1185 }1185 }
1186 const content = try ctx.dir.readFileAlloc(testing.allocator, test_out_file, 9999);1186 const content = try ctx.dir.readFileAlloc(testing.allocator, test_out_file, 9999);
1187 defer testing.allocator.free(content);1187 defer testing.allocator.free(content);
1188 try testing.expect(mem.eql(u8, content, test_content));1188 try testing.expectEqualStrings(test_content, content);
11891189
1190 try ctx.dir.deleteFile(test_out_file);1190 try ctx.dir.deleteFile(test_out_file);
1191 }1191 }
...@@ -1486,17 +1486,17 @@ test "chmod" {...@@ -1486,17 +1486,17 @@ test "chmod" {
14861486
1487 const file = try tmp.dir.createFile("test_file", .{ .mode = 0o600 });1487 const file = try tmp.dir.createFile("test_file", .{ .mode = 0o600 });
1488 defer file.close();1488 defer file.close();
1489 try testing.expect((try file.stat()).mode & 0o7777 == 0o600);1489 try testing.expectEqual(@as(File.Mode, 0o600), (try file.stat()).mode & 0o7777);
14901490
1491 try file.chmod(0o644);1491 try file.chmod(0o644);
1492 try testing.expect((try file.stat()).mode & 0o7777 == 0o644);1492 try testing.expectEqual(@as(File.Mode, 0o644), (try file.stat()).mode & 0o7777);
14931493
1494 try tmp.dir.makeDir("test_dir");1494 try tmp.dir.makeDir("test_dir");
1495 var iterable_dir = try tmp.dir.openIterableDir("test_dir", .{});1495 var iterable_dir = try tmp.dir.openIterableDir("test_dir", .{});
1496 defer iterable_dir.close();1496 defer iterable_dir.close();
14971497
1498 try iterable_dir.chmod(0o700);1498 try iterable_dir.chmod(0o700);
1499 try testing.expect((try iterable_dir.dir.stat()).mode & 0o7777 == 0o700);1499 try testing.expectEqual(@as(File.Mode, 0o700), (try iterable_dir.dir.stat()).mode & 0o7777);
1500}1500}
15011501
1502test "chown" {1502test "chown" {
...@@ -1525,8 +1525,8 @@ test "File.Metadata" {...@@ -1525,8 +1525,8 @@ test "File.Metadata" {
1525 defer file.close();1525 defer file.close();
15261526
1527 const metadata = try file.metadata();1527 const metadata = try file.metadata();
1528 try testing.expect(metadata.kind() == .file);1528 try testing.expectEqual(File.Kind.file, metadata.kind());
1529 try testing.expect(metadata.size() == 0);1529 try testing.expectEqual(@as(u64, 0), metadata.size());
1530 _ = metadata.accessed();1530 _ = metadata.accessed();
1531 _ = metadata.modified();1531 _ = metadata.modified();
1532 _ = metadata.created();1532 _ = metadata.created();