#! @PYTHON3@ import contextlib import os.path import shutil import subprocess import tempfile import exeter def host_run(cmd, **kwargs): return subprocess.run(cmd, shell=True, check=True, encoding='UTF-8', **kwargs) def host_out(cmd): return host_run(cmd, capture_output=True).stdout @contextlib.contextmanager def clone_source_tree(): with tempfile.TemporaryDirectory(ignore_cleanup_errors=False) as tmpdir: # Make a temporary copy of the sources srcfiles = host_out('git ls-files').splitlines() for src in srcfiles: dst = os.path.join(tmpdir, src) os.makedirs(os.path.dirname(dst), exist_ok=True) shutil.copy(src, dst) os.chdir(tmpdir) yield tmpdir def build_target(target, outputs): with clone_source_tree(): for o in outputs: assert not os.path.exists(o) host_run(f'make {target} CFLAGS="-Werror"') for o in outputs: assert os.path.exists(o) host_run('make clean') for o in outputs: assert not os.path.exists(o) @exeter.test def test_make_passt(): build_target('passt', ['passt']) @exeter.test def test_make_pasta(): build_target('pasta', ['pasta']) @exeter.test def test_make_qrap(): build_target('qrap', ['qrap']) @exeter.test def test_make_all(): build_target('all', ['passt', 'pasta', 'qrap']) @exeter.test def test_make_install_uninstall(): with clone_source_tree(): with tempfile.TemporaryDirectory(ignore_cleanup_errors=False) as prefix: bindir = os.path.join(prefix, 'bin') mandir = os.path.join(prefix, 'share', 'man') exes = ['passt', 'pasta', 'qrap'] # Install host_run(f'make install CFLAGS="-Werror" prefix={prefix}') for t in exes: assert os.path.isfile(os.path.join(bindir, t)) host_run(f'man -M {mandir} -W passt') # Uninstall host_run(f'make uninstall prefix={prefix}') for t in exes: assert not os.path.exists(os.path.join(bindir, t)) exeter.assert_raises(subprocess.CalledProcessError, host_run, f'man -M {mandir} -W passt') if __name__ == '__main__': exeter.main()