diff --git a/test/test.py b/test/test.py index 721db6a1..6f8a8a5f 100755 --- a/test/test.py +++ b/test/test.py @@ -1,24 +1,50 @@ #! /usr/bin/env python3 +import hashlib import os import subprocess import sys +from colorama import Fore, Style -def print_command(command_list): - print("running: " + " ".join(command_list), file=sys.stderr) +def print_status(message): + print("{}{}{}".format(Fore.CYAN, message, Style.RESET_ALL), file=sys.stderr) + +def print_success(message): + print("{}{}{}".format(Fore.GREEN, message, Style.RESET_ALL), file=sys.stderr) + +def print_error(message): + print("{}{}{}".format(Fore.RED, message, Style.RESET_ALL), file=sys.stderr) + exit(1) + +def print_command_run(command_list): + print_status("Running command: {}".format(" ".join(command_list))) + +def print_command_success(command_list): + print_success("Command succeeded: {}".format(" ".join(command_list))) def convert_path(path): return path.replace("/", os.path.sep) +def check_file(file_path, known_sum): + print_status("Checking file: {}".format(file_path)) + check_sum = hashlib.blake2b(open(file_path, "rb").read()).hexdigest() + if check_sum != known_sum: + print_error("Error: {}'s checksum {} doesn't match known {}".format(file_path, check_sum, known_sum)) + print_success("File check succeeded: {}".format(file_path)) + def run(command_list): - print_command(command_list) + print_command_run(command_list) returncode = subprocess.run(command_list).returncode if returncode: + print_error("Command failed: {}".format(" ".join(command_list))) exit(returncode) + print_command_success(command_list) def mkdir(path): - print_command(["mkdir", path]) + command_list = ["mkdir", path] + print_command_run(command_list) os.makedirs(path, exist_ok=True) + print_command_success(command_list) def crunch(input_path, output_path, options=[]): executable_extension = ["", ".exe"][sys.platform == 'win32'] @@ -35,71 +61,135 @@ def crunch(input_path, output_path, options=[]): if input_path: input_path = convert_path(input_path) output_path = convert_path(output_path) - command_list += ["-noTitle", "-file", input_path, "-out", output_path] + command_list += ["-noTitle", "-nostats", "-noprogress", "-file", input_path, "-out", output_path] run(command_list) +def crunch_check(input_path, output_path, known_sum): + crunch(input_path, output_path) + check_file(output_path, known_sum) + crunch(None, None, ["--help"]) +tga_sum="34434170b06843b2d4fb5964a4b8751ec3a151a7d03e351e45a5967508f6a21f6e40ffc214bb46640105c4058bc35e196ecb5dd3261528a64acfeff52034fb40" +bmp_sum="1c5f28be8151a8125346e9cf17b1bf6e3f9fe27f6947b164b7eefa8fd3732a2e4dff173c354a0cd4ed599cd604d4b8f916c0575b0a4b4b508acc68dc9b4067ae" +png_sum="71bb28da97cd778b99f131acaeb1c28ea37bae295a9e9934bed339508d8428587120c0da8f5bbc7963cdb77741ef789414f9d0d2c1e0da46026336efde147cc5" +crn_sum="a3b526e95f44b6a4c919bc8eb79f4debf592f0bccc163c900cd1b6f9add0ce58c3db9fc8dac1828d350bbcd915823d7743a0c114a533fbc08c163fcb4846d2f5" +dds_sum="ce98b21c574b4883e4aff4a0b92fd0f533f22e00ab753686f353111fa7503287c2c4dba25f2c2670508630d79b59464578e094461bad81ad803e1d58ed5e69f8" +ktx_sum="d82eab591163d802231722ef325571735971b6a9b0703ed8ea59b4a4144189825d96d3455605426453fb3ad8d7cc61f931c52b3e73df2bb6787f7408baeb4ac7" +jpg_sum="6cd22de7e2e5baced5ef16e84f816dde3049f822459d552ced4dcd4e3f9a16be82ee0747ed1479fe8339991176004b4ccc90380b7ef51292c7d9b518503a348d" + mkdir("build/test/png-to-all") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.crn") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.dds") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.ktx") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.tga") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.bmp") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.png") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.jpg") +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.tga", tga_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.bmp", bmp_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.png", png_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.crn", crn_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.dds", dds_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.ktx", ktx_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.jpg", jpg_sum) + +mkdir("build/test/tga-to-all") +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.tga", tga_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.bmp", bmp_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.png", png_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.crn", crn_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.dds", dds_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.ktx", ktx_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.jpg", jpg_sum) + +mkdir("build/test/bmp-to-all") +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.tga", tga_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.bmp", bmp_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.png", png_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.crn", crn_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.dds", dds_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.ktx", ktx_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.jpg", jpg_sum) mkdir("build/test/crn-to-all") -crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.crn") -crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.dds") -crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.tga") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.bmp") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.dds") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.jpg") mkdir("build/test/dds-to-all") -crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.crn") -crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.dds") -crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.tga") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.bmp") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.crn") +crunch_check("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.dds", dds_sum) +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.jpg") mkdir("build/test/ktx-to-all") -crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.crn") -crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.dds") -crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.tga") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.bmp") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.dds") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.jpg") +mkdir("build/test/jpg-to-all") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.tga") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.bmp") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.dds") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.ktx") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.jpg") + +mkdir("build/test/tga-to-png") +tga_png_sum="6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3" +crunch_check("test/raw-bottom-left.tga", "build/test/tga-to-png/raw-bottom-left.png", tga_png_sum) +crunch_check("test/raw-bottom-right.tga", "build/test/tga-to-png/raw-bottom-right.png", tga_png_sum) +crunch_check("test/raw-top-left.tga", "build/test/tga-to-png/raw-top-left.png", tga_png_sum) +crunch_check("test/raw-top-right.tga", "build/test/tga-to-png/raw-top-right.png", tga_png_sum) +crunch_check("test/rle-bottom-left.tga", "build/test/tga-to-png/rle-bottom-left.png", tga_png_sum) +crunch_check("test/rle-bottom-right.tga", "build/test/tga-to-png/rle-bottom-right.png", tga_png_sum) +crunch_check("test/rle-top-left.tga", "build/test/tga-to-png/rle-top-left.png", tga_png_sum) +crunch_check("test/rle-top-right.tga", "build/test/tga-to-png/rle-top-right.png", tga_png_sum) + mkdir("build/test/tga-to-crn") -crunch("test/raw-bottom-left.tga", "build/test/tga-to-crn/raw-bottom-left.crn") -crunch("test/raw-bottom-right.tga", "build/test/tga-to-crn/raw-bottom-right.crn") -crunch("test/raw-top-left.tga", "build/test/tga-to-crn/raw-top-left.crn") -crunch("test/raw-top-right.tga", "build/test/tga-to-crn/raw-top-right.crn") -crunch("test/rle-bottom-left.tga", "build/test/tga-to-crn/rle-bottom-left.crn") -crunch("test/rle-bottom-right.tga", "build/test/tga-to-crn/rle-bottom-right.crn") -crunch("test/rle-top-left.tga", "build/test/tga-to-crn/rle-top-left.crn") -crunch("test/rle-top-right.tga", "build/test/tga-to-crn/rle-top-right.crn") +tga_crn_sum="fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854" +crunch_check("test/raw-bottom-left.tga", "build/test/tga-to-crn/raw-bottom-left.crn", tga_crn_sum) +crunch_check("test/raw-bottom-right.tga", "build/test/tga-to-crn/raw-bottom-right.crn", tga_crn_sum) +crunch_check("test/raw-top-left.tga", "build/test/tga-to-crn/raw-top-left.crn", tga_crn_sum) +crunch_check("test/raw-top-right.tga", "build/test/tga-to-crn/raw-top-right.crn", tga_crn_sum) +crunch_check("test/rle-bottom-left.tga", "build/test/tga-to-crn/rle-bottom-left.crn", tga_crn_sum) +crunch_check("test/rle-bottom-right.tga", "build/test/tga-to-crn/rle-bottom-right.crn", tga_crn_sum) +crunch_check("test/rle-top-left.tga", "build/test/tga-to-crn/rle-top-left.crn", tga_crn_sum) +crunch_check("test/rle-top-right.tga", "build/test/tga-to-crn/rle-top-right.crn", tga_crn_sum) + +mkdir("build/test/png-to-png") +crunch_check("test/test-colormap1-alpha1.png", "build/test/png-to-png/test-colormap1-alpha1.png", "f596534970da37597230ae60112a4fe4d08d950e03b99754a633d9d285f4683624b1f710727d6b3e556b80b9d44428bfa297dc898beaf6fecad29fe98bbc98cb") +crunch_check("test/test-colormap2-alpha1.png", "build/test/png-to-png/test-colormap2-alpha1.png", "2ffd5907e77157dfaac01c786b5150dcf822699254bebdd51ef1797568208ae924a572d90bc3ed3a06cc5e524c4c0d5a3de7aa75ae99febc4638533e41a6dda0") +crunch_check("test/test-colormap4-alpha1.png", "build/test/png-to-png/test-colormap4-alpha1.png", "f8cd5a9b1ae040baee41a7f378e18bba426f79532555e22fe2f8c605a8347d79e7b98bb8284130536512b187f9d8435d58665eddb8d36596296f84f05ee904ae") +crunch_check("test/test-colormap8-alpha1.png", "build/test/png-to-png/test-colormap8-alpha1.png", "3561be7b7958d37913708664413c149942f302907bf5f928782c7cf6cc4b312082f51fea6d8a3271b93bd37ace03ec22af65c224d6e7617ed8644fbe2f95dc35") +crunch_check("test/test-grayscale1-alpha1.png", "build/test/png-to-png/test-grayscale1-alpha1.png", "57876e1d84ada2604c5e2dbbfd08c19286c87c8f1843cf47a9b77b4f6561c3b414a269f924c2be74bba4662503ede0fd9d94cb0a084c35a9f63a3cce07dcb876") +crunch_check("test/test-grayscale1-alpha8.png", "build/test/png-to-png/test-grayscale1-alpha8.png", "62ba2ca3669febcb88959224732c295d891f10942dcddf2494c052886c4f502b0e30c1238d05196ce8113c2c150fa4d96fc81436af5ad6a28f7b8a64a77bbe7f") +crunch_check("test/test-grayscale8-alpha1.png", "build/test/png-to-png/test-grayscale8-alpha1.png", "62ba2ca3669febcb88959224732c295d891f10942dcddf2494c052886c4f502b0e30c1238d05196ce8113c2c150fa4d96fc81436af5ad6a28f7b8a64a77bbe7f") +crunch_check("test/test-rgb8-alpha8.png", "build/test/png-to-png/test-rgb8-alpha8.png", "21630317b2ed9957241f4982c4e8207f7a00af23e0dd5df863965dbca9dcefd9a3c4f77b15ea91141c6c35181e44801ff1b5d0a7ed62f0c11eddfdaf7122b1a9") mkdir("build/test/png-to-crn") -crunch("test/test-colormap1-alpha1.png", "build/test/png-to-crn/test-colormap1-alpha1.crn") -crunch("test/test-colormap2-alpha1.png", "build/test/png-to-crn/test-colormap2-alpha1.crn") -crunch("test/test-colormap4-alpha1.png", "build/test/png-to-crn/test-colormap4-alpha1.crn") -crunch("test/test-colormap8-alpha1.png", "build/test/png-to-crn/test-colormap8-alpha1.crn") -crunch("test/test-grayscale1-alpha1.png", "build/test/png-to-crn/test-grayscale1-alpha1.crn") -crunch("test/test-grayscale1-alpha8.png", "build/test/png-to-crn/test-grayscale1-alpha8.crn") -crunch("test/test-grayscale8-alpha1.png", "build/test/png-to-crn/test-grayscale8-alpha1.crn") -crunch("test/test-rgb8-alpha8.png", "build/test/png-to-crn/test-rgb8-alpha8.crn") +crunch_check("test/test-colormap1-alpha1.png", "build/test/png-to-crn/test-colormap1-alpha1.crn", "c331744f6d683cbe18718e2b74ab7bdce5561fcf51321a8b778e848712129964ae78dcb7204c3f6e736a7f3d42e9f52af9f0c170a62243e9c71520709710bdae") +crunch_check("test/test-colormap2-alpha1.png", "build/test/png-to-crn/test-colormap2-alpha1.crn", "ef06c38192e6b6baa7b9c368f604cf86da0b3ee3307eb670492ec18bcf7622fe9565f98f8f764f7dcc6bf84fb824acb28582f1cca7301438e9d19f513931a9a9") +crunch_check("test/test-colormap4-alpha1.png", "build/test/png-to-crn/test-colormap4-alpha1.crn", "12e36ebb68d603282120a92fc8a184d6505bb316bedadf56f7cb9828f878f475bb055f569f73c54046d36410d502e8bd4e9200d26d94053ead52b720c272be6d") +crunch_check("test/test-colormap8-alpha1.png", "build/test/png-to-crn/test-colormap8-alpha1.crn", "657eb9b7ec4c3d21c4a02d235af04b0f1626267a38f1519afb0c8e374a6ac8e4bf2024aebe738d33a3b35c12dcd277d27de1743a86ac61ed58f809047b03d682") +crunch_check("test/test-grayscale1-alpha1.png", "build/test/png-to-crn/test-grayscale1-alpha1.crn", "31906b0368d7d009954917597066b21813db53a13d01290153a064623db48ad3a1617a0af8a47178fc303f598b8d757547c31ad74dac9899feaa258546a8810a") +crunch_check("test/test-grayscale1-alpha8.png", "build/test/png-to-crn/test-grayscale1-alpha8.crn", "22d6726ef894102eb95f00199c90dc2c675751b884560b65176f5a9ee4b57b148793144c08ef63aa4ea5f064378423f3ca805c4ca05f8e1f18033522a9658582") +crunch_check("test/test-grayscale8-alpha1.png", "build/test/png-to-crn/test-grayscale8-alpha1.crn", "3b7ecf85212aca71cd3a36e5e3578f44ffaf61c53614edc60c3a7a591995856202c2b4f6792520060c2256c62eafd99b5999ae9e7ffeab3719bdc93c670bc236") +crunch_check("test/test-rgb8-alpha8.png", "build/test/png-to-crn/test-rgb8-alpha8.crn", "87dcb6922f2f8ee8cab69d5f9a36e8e3b94ae0603fddd8e04c588128a006507af9475fa469cf1483b49a40a1a9cfb5cc9338de5b3085f6366b5b237d40c47fc1") mkdir("build/test/bmp-to-crn") -crunch("test/sample-default.bmp", "build/test/bmp-to-crn/sample-default.crn") -crunch("test/sample-vertical-flip.bmp", "build/test/bmp-to-crn/sample-vertical-flip.crn") +bmp_crn_sum="119f0f756811e56ba688c402ea317923d9665017aed19022ad19fc8396e45d3ca3bb7b5383f3edc00e859e31558a0865de88af71110529b16b89ded731070925" +crunch_check("test/sample-default.bmp", "build/test/bmp-to-crn/sample-default.crn", bmp_crn_sum) +crunch_check("test/sample-vertical-flip.bmp", "build/test/bmp-to-crn/sample-vertical-flip.crn", bmp_crn_sum) mkdir("build/test/jpg-to-crn") -crunch("test/black.jpg", "build/test/jpg-to-crn/black.crn") +crunch_check("test/black.jpg", "build/test/jpg-to-crn/black.crn", "19fb840c8dbb7da96400af5af1c45fe48c7c7e19340d03fbe5a2af28ceecfb9efba26fe6c1bf46bd76164ecb0efe91cc9237917e8e431cd8365f80e9ffacc906") + +print_success("All tests succeeded")