From e090f43621b904ec93e663177ba6a0042d96bfcc Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sun, 7 Jul 2024 23:31:05 +0200 Subject: [PATCH] test: also test examples, make possible to use custom CRUNCH_BUILD_DIR --- test/test.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/test/test.py b/test/test.py index 78a9b760..c29aa271 100755 --- a/test/test.py +++ b/test/test.py @@ -4,32 +4,62 @@ import subprocess import sys +if "CRUNCH_BUILD_DIR" in os.environ.keys(): + build_dir = os.environ["CRUNCH_BUILD_DIR"] +else: + build_dir = "build" + +if "CRUNCH_RUNNER" in os.environ.keys(): + crunch_runner = os.environ["CRUNCH_RUNNER"] +else: + crunch_runner = None + +if "CRUNCH_EXTENSION" in os.environ.keys(): + crunch_extension = os.environ["CRUNCH_EXTENSION"] +else: + crunch_extension = None + def print_command(command_list): print("running: " + " ".join(command_list), file=sys.stderr) def convert_path(path): + if path.startswith("build/"): + path = build_dir + path[len("build"):] return path.replace("/", os.path.sep) def run(command_list): + if crunch_runner: + command_list = [crunch_runner] + command_list print_command(command_list) returncode = subprocess.run(command_list).returncode if returncode: exit(returncode) def mkdir(path): + path = convert_path(path) print_command(["mkdir", path]) os.makedirs(path, exist_ok=True) -def crunch(input_path, output_path, options=[]): - executable_extension = ["", ".exe"][sys.platform == 'win32'] - executable_name = "crunch" + executable_extension - - build_dir = "build" +def get_build_dir(): windows_build_dir = os.path.join(build_dir, "Release") if os.path.exists(windows_build_dir): - build_dir = windows_build_dir + return windows_build_dir + return build_dir + +def get_executable_path(executable_name): + if crunch_extension: + executable_extension = crunch_extension + elif sys.platform == "win32": + executable_extension = ".exe" + else: + executable_extension = "" + + executable_name += executable_extension + build_dir = get_build_dir() + return os.path.join(build_dir, executable_name) - executable_path = os.path.join(build_dir, executable_name) +def crunch(input_path, output_path, options=[]): + executable_path = get_executable_path("crunch") command_list = [executable_path] + options if input_path: @@ -39,6 +69,26 @@ def crunch(input_path, output_path, options=[]): run(command_list) +def example(num, input_path, output_path, options=[]): + executable_path = get_executable_path("example" + str(num)) + command_list = [executable_path] + + if (num == 1): + command_list += [options[0]] + options = options[1:] + + if input_path: + input_path = convert_path(input_path) + command_list += [input_path] + + command_list += options + + if output_path: + output_path = convert_path(output_path) + command_list += ["-out", output_path] + + run(command_list) + crunch(None, None, ["--help"]) mkdir("build/test/0") @@ -99,3 +149,17 @@ def crunch(input_path, output_path, options=[]): mkdir("build/test/7") crunch("test/black.jpg", "build/test/7/black.crn") + +mkdir("build/test/8") +example(1, "test/unvanquished_64.png", None, ["i"]) +example(1, "test/unvanquished_64.png", "build/test/8/unvanquished_64.dds", ["c"]) + +mkdir("build/test/9") +example(1, "test/unvanquished_64.png", "build/test/9/unvanquished_64.crn", ["c", "-crn"]) +example(1, "build/test/9/unvanquished_64.crn", "build/test/9/unvanquished_64.dds", ["d"]) + +mkdir("build/test/10") +example(2, "build/test/9/unvanquished_64.crn", "build/test/10/unvanquished_64.dds") + +mkdir("build/test/11") +example(3, "test/unvanquished_64.png", "build/test/11/unvanquished_64.dds")