rustfmt
[ouch.git] / makeshift_testing.py
blob9790699db03fdd8d8a5bb9b33e052c4e02dd0b71
1 #!/usr/bin/python3
2 """
3 Little integration testing script while proper integration tests in Rust aren't implemented.
4 """
6 import magic, os, hashlib
8 def make_random_file():
9 with open('test-file', 'wb') as fout:
10 fout.write(os.urandom(2048))
12 def sanity_check_format(format: str):
13 make_random_file()
14 md5sum = hashlib.md5(open('test-file', 'rb').read()).hexdigest()
15 os.system(f"cargo run -- -i test-file -o test-file.{format}")
16 os.remove('test-file')
17 os.system(f"cargo run -- -i test-file.{format}")
18 if md5sum != hashlib.md5(open('test-file', 'rb').read()).hexdigest():
19 print("Something went wrong with tar (de)compression.")
20 os._exit(2)
21 os.remove('test-file')
22 os.remove(f'test-file.{format}')
25 if __name__ == "__main__":
27 # We'll use MIME sniffing through magic numbers to
28 # verify if ouch is actually outputting the file formats
29 # that it should
31 m = magic.open(magic.MAGIC_MIME)
33 try:
34 os.mkdir("testbuilds")
35 except OSError:
36 print ("Could not make testbuilds folder. Exiting.")
37 os._exit(2)
39 os.chdir("testbuilds")
41 m.load()
42 files = [
43 "src.tar",
44 "src.zip",
45 "src.tar.gz",
46 "src.tar.bz",
47 "src.tar.bz2",
48 "src.tar.lz",
49 "src.tar.lzma",
52 expected_mime_types = [
53 "application/x-tar",
54 "application/zip",
55 "application/gzip",
56 "application/x-bzip2",
57 "application/x-bzip2",
58 "application/x-xz",
59 "application/x-xz"
62 for file in files:
63 rv = os.system(f"cargo run -- -i ../src/ -o {file}")
64 if rv != 0:
65 print(f"Failed while compressing {file}")
67 for (file, expected_mime) in zip(files, expected_mime_types):
68 if m.file(file) != expected_mime:
69 print(f"Test failed at file {file}")
70 os._exit(2)
72 for (idx, file) in enumerate(files):
73 rv = os.system(f"cargo run -- -i {file} -o out{idx}/")
74 if rv != 0:
75 print(f"Failed while decompressing {file}")
76 os._exit(2)
78 os.chdir("..")
79 os.system("rm -rf testbuilds")
81 # We'll now verify if ouch is not altering the data it is compressing
82 # and decompressing
84 sanity_check_format("tar")
85 sanity_check_format("tar.gz")
86 sanity_check_format("tar.bz")
87 sanity_check_format("tar.bz2")
88 sanity_check_format("tar.lz")
89 sanity_check_format("tar.lzma")