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: TYBLE16_simple_data_logger TYBLE16_MP3_Air
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+'test = {test};'.format(test=test.strip())) 00018 lines.append(tab+'test_assert("{name}", test, {expect});'.format( 00019 name = re.match('\w*', test.strip()).group(), 00020 expect = expect.strip())) 00021 else: 00022 lines.append(line) 00023 00024 # Create test file 00025 with open('test.c', 'w') as file: 00026 file.write(template.format(tests='\n'.join(lines))) 00027 00028 # Remove build artifacts to force rebuild 00029 try: 00030 os.remove('test.o') 00031 os.remove('lfs') 00032 except OSError: 00033 pass 00034 00035 def compile(): 00036 subprocess.check_call([ 00037 os.environ.get('MAKE', 'make'), 00038 '--no-print-directory', '-s']) 00039 00040 def execute(): 00041 if 'EXEC' in os.environ: 00042 subprocess.check_call([os.environ['EXEC'], "./lfs"]) 00043 else: 00044 subprocess.check_call(["./lfs"]) 00045 00046 def main(test=None): 00047 if test and not test.startswith('-'): 00048 with open(test) as file: 00049 generate(file) 00050 else: 00051 generate(sys.stdin) 00052 00053 compile() 00054 00055 if test == '-s': 00056 sys.exit(1) 00057 00058 execute() 00059 00060 if __name__ == "__main__": 00061 main(*sys.argv[1:])
Generated on Tue Jul 12 2022 13:54:55 by
