1"""Provides common functionality to the test scripts.""" 2 3import os 4import sys 5from pathlib import Path 6 7 8def set_source(source): 9 """Checks whether the source file exists and returns its path.""" 10 if not Path(source).is_file(): 11 die(source) 12 return Path(source) 13 14 15def set_executable(executable): 16 """Checks whether a Flang executable has been set and returns its path.""" 17 flang_fc1 = Path(executable) 18 if not flang_fc1.is_file(): 19 die(flang_fc1) 20 return str(flang_fc1) 21 22 23def set_temp(tmp): 24 """Sets a temporary directory or creates one if it doesn't exist.""" 25 os.makedirs(Path(tmp), exist_ok=True) 26 return Path(tmp) 27 28 29def die(file=None): 30 """Used in other functions.""" 31 if file is None: 32 print(f"{sys.argv[0]}: FAIL") 33 else: 34 print(f"{sys.argv[0]}: File not found: {file}") 35 sys.exit(1) 36 37 38def check_args(args): 39 """Verifies that 2 arguments have been passed.""" 40 if len(args) < 3: 41 print(f"Usage: {args[0]} <fortran-source> <flang-command>") 42 sys.exit(1) 43 44 45def check_args_long(args): 46 """Verifies that 3 arguments have been passed.""" 47 if len(args) < 4: 48 print(f"Usage: {args[0]} <fortran-source> <temp-test-dir> <flang-command>") 49 sys.exit(1) 50