[LLVM] Fix Maintainers.md formatting (NFC)
[llvm-project.git] / flang / test / Semantics / common.py
blobee7a820965b0c08743c99931355bcbe35d1bbc9b
1 """Provides common functionality to the test scripts."""
3 import os
4 import sys
5 from pathlib import Path
8 def 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)
15 def 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)
23 def 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)
29 def 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)
38 def 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)
45 def 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)