Skip to content

Commit

Permalink
test: also test examples, make possible to use custom CRUNCH_BUILD_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jul 7, 2024
1 parent ed6c813 commit e6eeb5a
Showing 1 changed file with 71 additions and 7 deletions.
78 changes: 71 additions & 7 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand Down Expand Up @@ -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")

0 comments on commit e6eeb5a

Please sign in to comment.