# Path: test/reference.py
# def check(left, right, result):
# 
# Path: test/source.py
# def _warriors():
# def count():
# def warriors():
# def pairs():
# 
# Path: tools/runfiles.py
# _WORKSPACE = 'fi_zem_chainlance'
# def _find_runfiles():
# def _runfiles():
# def path(path):
# def open(file, *args, **kwargs):


import itertools
import os.path
import shutil
import subprocess
import sys
import tempfile
from test import reference
from test import source
from tools import runfiles


def main():
    failed = 0

    workdir = tempfile.mkdtemp(prefix='torquelance-test-')
    try:
        for w in source.warriors():
            compiled = os.path.join(workdir, str(w.index))
            subprocess.check_call([runfiles.path('torquelance-compile'), w.path, compiled + '.A', 'A'])
            subprocess.check_call([runfiles.path('torquelance-compile'), w.path, compiled + '.B', 'B'])
            subprocess.check_call([runfiles.path('torquelance-compile'), w.path, compiled + '.B2', 'B2'])

        for left, right in source.pairs():
            result = subprocess.check_output(
                [runfiles.path('torquelance'),
                 os.path.join(workdir, str(left.index) + '.A'),
                 os.path.join(workdir, str(right.index) + '.B'),
                 os.path.join(workdir, str(right.index) + '.B2')])

# Path: test/reference.py
# def check(left, right, result):
# 
# Path: test/source.py
# def _warriors():
# def count():
# def warriors():
# def pairs():
# 
# Path: tools/runfiles.py
# _WORKSPACE = 'fi_zem_chainlance'
# def _find_runfiles():
# def _runfiles():
# def path(path):
# def open(file, *args, **kwargs):


# Path: torquelance_test.py
import itertools
import os.path
import shutil
import subprocess
import sys
import tempfile
from test import reference
from test import source
from tools import runfiles



def main():
    failed = 0

    workdir = tempfile.mkdtemp(prefix='torquelance-test-')
    try:
        for w in source.warriors():
            compiled = os.path.join(workdir, str(w.index))
            subprocess.check_call([runfiles.path('torquelance-compile'), w.path, compiled + '.A', 'A'])
            subprocess.check_call([runfiles.path('torquelance-compile'), w.path, compiled + '.B', 'B'])
            subprocess.check_call([runfiles.path('torquelance-compile'), w.path, compiled + '.B2', 'B2'])

        for left, right in source.pairs():
            result = subprocess.check_output(
                [runfiles.path('torquelance'),
                 os.path.join(workdir, str(left.index) + '.A'),
                 os.path.join(workdir, str(right.index) + '.B'),
                 os.path.join(workdir, str(right.index) + '.B2')])

            if not reference.check(left.name, right.name, result):