testing: fix v -stats test folder/ not failing for a _test.v that fails (#21483)

This commit is contained in:
Delyan Angelov 2024-05-10 23:30:24 +03:00 committed by GitHub
parent 776e7ad0b1
commit 0e2b6041b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 108 additions and 11 deletions

View file

@ -52,3 +52,8 @@ pub fn parse_file(file_path string) !Archive {
content := os.read_file(file_path)!
return parse(content)
}
// unpack_to extracts the content of the archive `a`, into the folder `path`.
pub fn (a &Archive) unpack_to(path string) ! {
unpack(a, path)!
}

View file

@ -78,7 +78,7 @@ fn test_parse() {
fn test_parse_file() {
dump(@LOCATION)
fpath := os.join_path(os.temp_dir(), 'txtar.txt')
fpath := os.join_path(os.vtmp_dir(), 'txtar.txt')
defer {
os.rm(fpath) or {}
}
@ -91,16 +91,19 @@ fn test_parse_file() {
fn test_unpack_to_folder_then_pack_same_folder() {
dump(@LOCATION)
folder := os.join_path(os.temp_dir(), 'txtar_folder')
defer {
os.rmdir_all(folder) or {}
}
folder := os.join_path(os.vtmp_dir(), 'txtar_folder')
a := txtar.parse(simple_archive_content)
txtar.unpack(a, folder)!
assert os.is_file(os.join_path(folder, 'empty'))
assert os.is_file(os.join_path(folder, 'folder2/another.txt'))
assert os.is_file(os.join_path(folder, 'folder3/final.txt'))
check_folder(folder)
os.rmdir_all(folder) or {}
a.unpack_to(folder)!
check_folder(folder)
b := txtar.pack(folder, 'abc')!
os.rmdir_all(folder) or {}
assert a.comment != b.comment
assert b.comment == 'abc'
assert b.files.len == a.files.len
@ -108,3 +111,9 @@ fn test_unpack_to_folder_then_pack_same_folder() {
pfiles := b.files.sorted(|x, y| x.path < y.path)
assert ofiles == pfiles
}
fn check_folder(folder string) {
assert os.is_file(os.join_path(folder, 'empty'))
assert os.is_file(os.join_path(folder, 'folder2/another.txt'))
assert os.is_file(os.join_path(folder, 'folder3/final.txt'))
}