Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more
test.py
00001 #!/usr/bin/env python 00002 00003 import re 00004 import sys 00005 import subprocess 00006 import os 00007 00008 def generate(test): 00009 with open("tests/template.fmt") as file: 00010 template = file.read() 00011 00012 lines = [] 00013 for line in re.split('(?<=[;{}])\n', test.read()): 00014 match = re.match('(?: *\n)*( *)(.*)=>(.*);', line, re.DOTALL | re.MULTILINE) 00015 if match: 00016 tab, test, expect = match.groups() 00017 lines.append(tab+'res = {test};'.format(test=test.strip())) 00018 lines.append(tab+'test_assert("{name}", res, {expect});'.format( 00019 name = re.match('\w*', test.strip()).group(), 00020 expect = expect.strip())) 00021 else: 00022 lines.append(line) 00023 00024 with open('test.c', 'w') as file: 00025 file.write(template.format(tests='\n'.join(lines))) 00026 00027 def compile(): 00028 os.environ['CFLAGS'] = os.environ.get('CFLAGS', '') + ' -Werror' 00029 subprocess.check_call(['make', '--no-print-directory', '-s'], env=os.environ) 00030 00031 def execute(): 00032 subprocess.check_call(["./lfs"]) 00033 00034 def main(test=None): 00035 if test and not test.startswith('-'): 00036 with open(test) as file: 00037 generate(file) 00038 else: 00039 generate(sys.stdin) 00040 00041 compile() 00042 00043 if test == '-s': 00044 sys.exit(1) 00045 00046 execute() 00047 00048 if __name__ == "__main__": 00049 main(*sys.argv[1:])
Generated on Tue Jul 12 2022 13:03:19 by
