From f42b49787bff04379e807588d0f1984ddf9f032b Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Thu, 15 May 2014 18:52:11 +0000 Subject: [PATCH] cleanup and test litlint llvm-svn: 208907 --- .../lib/sanitizer_common/scripts/litlint.py | 72 +++++++++++++++---- .../sanitizer_common/scripts/litlint_test.py | 23 ++++++ 2 files changed, 82 insertions(+), 13 deletions(-) create mode 100755 compiler-rt/lib/sanitizer_common/scripts/litlint_test.py diff --git a/compiler-rt/lib/sanitizer_common/scripts/litlint.py b/compiler-rt/lib/sanitizer_common/scripts/litlint.py index b82eec290495..1e78448b63d4 100755 --- a/compiler-rt/lib/sanitizer_common/scripts/litlint.py +++ b/compiler-rt/lib/sanitizer_common/scripts/litlint.py @@ -1,26 +1,72 @@ #!/usr/bin/python # -# lit-lint +# litlint # -# Check that the RUN commands in lit tests can be executed with an emulator. +# Ensure RUN commands in lit tests are free of common errors. +# +# If any errors are detected, litlint returns a nonzero exit code. # import optparse import re import sys -parser = optparse.OptionParser() -parser.add_option('--filter') # ignored -(options, filenames) = parser.parse_args() - +# Compile regex once for all files runRegex = re.compile(r'(? 0: + sys.exit(1) diff --git a/compiler-rt/lib/sanitizer_common/scripts/litlint_test.py b/compiler-rt/lib/sanitizer_common/scripts/litlint_test.py new file mode 100755 index 000000000000..3ce482d70444 --- /dev/null +++ b/compiler-rt/lib/sanitizer_common/scripts/litlint_test.py @@ -0,0 +1,23 @@ +#!/usr/bin/python + +# Tests for litlint.py +# +# Usage: python litlint_test.py +# +# Returns nonzero if any test fails + +import litlint +import unittest + +class TestLintLine(unittest.TestCase): + def test_missing_run(self): + f = litlint.LintLine + self.assertEqual(f(' %t '), ('missing %run before %t', 2)) + self.assertEqual(f(' %t\n'), ('missing %run before %t', 2)) + self.assertEqual(f(' %t.so '), (None, None)) + self.assertEqual(f(' %t.o '), (None, None)) + self.assertEqual(f('%run %t '), (None, None)) + self.assertEqual(f('-o %t '), (None, None)) + +if __name__ == '__main__': + unittest.main()