1#!/usr/bin/env python3 2import sys 3import os 4 5template = '''#!/bin/zsh 6tests=( 7TEST_TARGETS 8) 9 10s_dir=${0:A:h} 11for file in ${tests[@]}; do 12 file_path=$s_dir/$file 13 echo "Running $file_path ..." 14 if [[ -f $file_path ]]; then 15 $file_path > /dev/null 2>/dev/null 16 ret=$? 17 if [[ $ret -eq 0 ]]; then 18 print -P "%F{green}*** PASS%f" 19 else 20 print -P "%F{red}*** FAILED: $file_path%f" 21 fi 22 else 23 print -P "%F{yellow}*** Missing%f" 24 fi 25done 26''' 27 28def main(): 29 targets_s = sys.argv[1] 30 output = sys.argv[2] 31 output_list = sys.argv[3] 32 33 targets = targets_s.strip().split(' ') 34 target_lines = '\n'.join([('"' + t + '"') for t in targets]) 35 s = template.replace('TEST_TARGETS', target_lines) 36 open(output, 'w').write(s) 37 print(f"wrote {output}") 38 39 open(output_list, 'w').write('\n'.join(targets) + '\n') 40 print(f"wrote {output_list}") 41 42if __name__ == "__main__": 43 sys.exit(main())