import base64,hashlib,json,os,subprocess,sys from pathlib import Path from lxml import etree ROOT=Path(__file__).resolve().parents[1] php=json.loads(os.environ.get('PHP_TEST_COMMAND','["php"]'));node=os.environ.get('NODE_TEST_COMMAND','node') files=[ROOT/'main.php']+[f for directory in ['classes','bin','tests'] for f in (ROOT/directory).glob('*.php')] for file in files: result=subprocess.run(php+['-l',str(file)],cwd=ROOT,capture_output=True,text=True) if result.returncode:raise RuntimeError(result.stdout+result.stderr) scripts=list((ROOT/'js').glob('*.js')) for file in scripts: result=subprocess.run([node,'--check',str(file)],capture_output=True,text=True) if result.returncode:raise RuntimeError(result.stdout+result.stderr) styles=list((ROOT/'xsl').glob('*.xsl')) for file in styles:etree.XSLT(etree.parse(str(file))) dependency=json.loads((ROOT/'browser-dependencies.json').read_text())['jquery'] assert base64.b64encode(hashlib.sha256((ROOT/dependency['file']).read_bytes()).digest()).decode()==dependency['sha256_base64'] assert not (ROOT/'js/jquery-3.2.0.min.js').exists() assert all('jquery-3.2.0' not in file.read_text(encoding='utf-8-sig') for file in styles) print(f'Source checks passed: {len(files)} PHP files, {len(scripts)} JavaScript files, {len(styles)} XSL stylesheets, and jQuery integrity.')