diff --git a/flang/test/Semantics/test_errors.py b/flang/test/Semantics/test_errors.py --- a/flang/test/Semantics/test_errors.py +++ b/flang/test/Semantics/test_errors.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 -"""Compiles a source file and checks errors against those listed in the file. +"""Compiles a source file and checks errors and warnings against those + listed in the file. Parameters: sys.argv[1]: a source file with contains the input and expected output @@ -19,8 +20,10 @@ srcdir = cm.set_source(sys.argv[1]) with open(srcdir, 'r') as f: src = f.readlines() -actual = "" -expect = "" +err_actual = "" +err_expect = "" +warn_actual = "" +warn_expect = "" diffs = "" log = "" @@ -34,6 +37,7 @@ try: proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, universal_newlines=True, cwd=tmpdir) + log = proc.stderr except subprocess.CalledProcessError as e: log = e.stderr if e.returncode >= 128: @@ -44,25 +48,42 @@ for line in log.split('\n'): m = re.search(r"[^:]*:(\d+:).*(?:error:)(.*)", line) if m: - actual += m.expand(r"\1\2\n") + err_actual += m.expand(r"\1\2\n") +for line in log.split('\n'): + m = re.search(r"[^:]*:(\d+:).*(?:warning:|portability:)(.*)", line) + if m: + warn_actual += m.expand(r"\1\2\n") -# Gets the expected errors and their line number +# Gets the expected diagnostics and their line number errors = [] +warnings = [] for i, line in enumerate(src, 1): - m = re.search(r"(?:^\s*!\s*ERROR: )(.*)", line) - if m: - errors.append(m.group(1)) + me = re.search(r"(?:^\s*!\s*ERROR: )(.*)", line) + mw = re.search(r"(?:^\s*!\s*WARNING: )(.*)", line) + if me: + errors.append(me.group(1)) + continue + if mw: + warnings.append(mw.group(1)) continue if errors: for x in errors: - expect += f"{i}: {x}\n" + err_expect += f"{i}: {x}\n" errors = [] + if warnings: + for x in warnings: + warn_expect += f"{i}: {x}\n" + warnings = [] -# Compares the expected errors with the compiler errors -for line in unified_diff(actual.split("\n"), expect.split("\n"), n=0): +# Compares the expected errors and warnings with the compiler diagnostics +for line in unified_diff(err_actual.split("\n"), err_expect.split("\n"), n=0): line = re.sub(r"(^\-)(\d+:)", r"\nactual at \g<2>", line) line = re.sub(r"(^\+)(\d+:)", r"\nexpect at \g<2>", line) diffs += line +for line in unified_diff(warn_actual.split("\n"), warn_expect.split("\n"), n=0): + line = re.sub(r"(^\-)(\d+:)", r"\nactual warning at \g<2>", line) + line = re.sub(r"(^\+)(\d+:)", r"\nexpected warning at \g<2>", line) + diffs += line if diffs != "": print(diffs)