# Path: tests/klltest.py
# def kll_run(args):
#     '''
#     Run kll compiler
# 
#     @return: Exit code
#     '''
#     with pytest.raises(SystemExit) as pytest_wrapped_e:
#         kll.main(args)
#     assert pytest_wrapped_e.type == SystemExit
#     return pytest_wrapped_e.value.code
# 
# def header_test(name, args):
#     '''
#     Prints out the name of the test and the arguments passed
# 
#     @param name: Name of the test
#     @param args: List of arguments
#     '''
#     print('\n---- {} ---- {}'.format(name, args))


import difflib
import filecmp
import os
import pytest
import tempfile
from tests.klltest import kll_run, header_test
    'kll/layouts/mouseTest.kll',
    'kll/layouts/klltest.kll',
    'kll/layouts/klltest_default.kll',
    'kll/examples/triggers.kll',
    'kll/examples/utf8.kll',
]



### Tests ###

@pytest.mark.parametrize('input_file', test_files)
def test_regen(input_file):
    '''
    Runs regen test on each of the specified files
    '''
    # Prepare tmp directory
    sanitized_input_file = input_file.replace('/', '-')
    tmp_dir = os.path.join(tempfile.gettempdir(), 'kll_pytest')
    os.makedirs(tmp_dir, exist_ok=True)
    target_dir = tempfile.mkdtemp(suffix='-{}'.format(sanitized_input_file), prefix='regen-', dir=tmp_dir)

    # Determine cmp and new files
    cmp_filename = '{}_final.kll'.format(os.path.splitext(os.path.basename(input_file))[0])
    cmp_file = os.path.join('tests', 'cmp_regen', cmp_filename)
    new_file = os.path.join(target_dir, 'final.kll')

    # Run test
    args = ['--emitter', 'kll', '--output-debug', input_file, '--target-dir', target_dir]
    header_test('{} {} {}'.format(input_file, target_dir, cmp_file), args)

# Path: tests/klltest.py
# def kll_run(args):
#     '''
#     Run kll compiler
# 
#     @return: Exit code
#     '''
#     with pytest.raises(SystemExit) as pytest_wrapped_e:
#         kll.main(args)
#     assert pytest_wrapped_e.type == SystemExit
#     return pytest_wrapped_e.value.code
# 
# def header_test(name, args):
#     '''
#     Prints out the name of the test and the arguments passed
# 
#     @param name: Name of the test
#     @param args: List of arguments
#     '''
#     print('\n---- {} ---- {}'.format(name, args))


# Path: tests/test_regen.py
import difflib
import filecmp
import os
import pytest
import tempfile
from tests.klltest import kll_run, header_test

    'kll/layouts/mouseTest.kll',
    'kll/layouts/klltest.kll',
    'kll/layouts/klltest_default.kll',
    'kll/examples/triggers.kll',
    'kll/examples/utf8.kll',
]



### Tests ###

@pytest.mark.parametrize('input_file', test_files)
def test_regen(input_file):
    '''
    Runs regen test on each of the specified files
    '''
    # Prepare tmp directory
    sanitized_input_file = input_file.replace('/', '-')
    tmp_dir = os.path.join(tempfile.gettempdir(), 'kll_pytest')
    os.makedirs(tmp_dir, exist_ok=True)
    target_dir = tempfile.mkdtemp(suffix='-{}'.format(sanitized_input_file), prefix='regen-', dir=tmp_dir)

    # Determine cmp and new files
    cmp_filename = '{}_final.kll'.format(os.path.splitext(os.path.basename(input_file))[0])
    cmp_file = os.path.join('tests', 'cmp_regen', cmp_filename)
    new_file = os.path.join(target_dir, 'final.kll')

    # Run test
    args = ['--emitter', 'kll', '--output-debug', input_file, '--target-dir', target_dir]
    header_test('{} {} {}'.format(input_file, target_dir, cmp_file), args)

    ret = kll_run(args)