From 98fe1521598204d6c7476c3233bdb63b40793ca6 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 6 Jun 2015 17:15:06 +0300 Subject: [PATCH] Add lit-based tests for diagnostics. --- artiq/py2llvm/typing.py | 8 +++++++- lit-test/harness.py | 6 ++++-- lit-test/py2llvm/typing/error_unify.py | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 lit-test/py2llvm/typing/error_unify.py diff --git a/artiq/py2llvm/typing.py b/artiq/py2llvm/typing.py index 310819530..aef05b9fd 100644 --- a/artiq/py2llvm/typing.py +++ b/artiq/py2llvm/typing.py @@ -358,7 +358,11 @@ class Printer(algorithm.Visitor): def main(): import sys, fileinput, os - inference_mode = True + if sys.argv[1] == '+diag': + del sys.argv[1] + inference_mode = False + else: + inference_mode = True engine = diagnostic.Engine(all_errors_are_fatal=True) try: @@ -375,6 +379,8 @@ def main(): if inference_mode: print("\n".join(e.diagnostic.render()), file=sys.stderr) exit(1) + else: + print("\n".join(e.diagnostic.render(only_line=True))) if __name__ == "__main__": main() diff --git a/lit-test/harness.py b/lit-test/harness.py index 1779e3266..9821ae61f 100644 --- a/lit-test/harness.py +++ b/lit-test/harness.py @@ -12,8 +12,10 @@ emulate the same behavior when invoked under lit. import sys, os, argparse, importlib parser = argparse.ArgumentParser(description=__doc__) -parser.add_argument('-m', metavar='mod', type=str, help='run library module as a script') -parser.add_argument('args', type=str, nargs='+', help='arguments passed to program in sys.argv[1:]') +parser.add_argument('-m', metavar='mod', type=str, required=True, + help='run library module as a script') +parser.add_argument('args', type=str, nargs='+', + help='arguments passed to program in sys.argv[1:]') args = parser.parse_args(sys.argv[1:]) artiq_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) diff --git a/lit-test/py2llvm/typing/error_unify.py b/lit-test/py2llvm/typing/error_unify.py new file mode 100644 index 000000000..859e49205 --- /dev/null +++ b/lit-test/py2llvm/typing/error_unify.py @@ -0,0 +1,8 @@ +# RUN: %python -m artiq.py2llvm.typing +diag %s >%t +# RUN: OutputCheck %s --file-to-check=%t + +a = 1 +b = [] + +# CHECK-L: ${LINE:+1}: fatal: cannot unify int(width='a) with list(elt='b) +a = b