diff --git a/test/test.py b/test/test.py index d1e9edef..f82c4fb4 100755 --- a/test/test.py +++ b/test/test.py @@ -1,15 +1,29 @@ #! /usr/bin/env python3 +import hashlib import os import subprocess import sys +def print_status(message): + print(message, file=sys.stderr) + +def print_error(message): + print(message, file=sys.stderr) + exit(1) + def print_command(command_list): - print("running: " + " ".join(command_list), file=sys.stderr) + print_status("Running command: {}".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 {}".format(file_path, check_sum, known_sum)) + def run(command_list): print_command(command_list) returncode = subprocess.run(command_list).returncode @@ -87,6 +101,16 @@ def crunch(input_path, output_path, options=[]): crunch("test/rle-top-left.tga", "build/test/tga-to-png/rle-top-left.png") crunch("test/rle-top-right.tga", "build/test/tga-to-png/rle-top-right.png") +png_known_sum="6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3" +check_file("build/test/tga-to-png/raw-bottom-left.png", png_known_sum) +check_file("build/test/tga-to-png/raw-bottom-right.png", png_known_sum) +check_file("build/test/tga-to-png/raw-top-left.png", png_known_sum) +check_file("build/test/tga-to-png/raw-top-right.png", png_known_sum) +check_file("build/test/tga-to-png/rle-bottom-left.png", png_known_sum) +check_file("build/test/tga-to-png/rle-bottom-right.png", png_known_sum) +check_file("build/test/tga-to-png/rle-top-left.png", png_known_sum) +check_file("build/test/tga-to-png/rle-top-right.png", png_known_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")