lit: Fix a sh lexing bug which caused annotate-token.m to fail when run with the
authorDaniel Dunbar <daniel@zuster.org>
Wed, 12 May 2010 21:47:58 +0000 (21:47 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 12 May 2010 21:47:58 +0000 (21:47 +0000)
internal shell parser; we weren't lexing the quotes in a command like::

  clang -DFOO='hello'

correctly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103652 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/lit/ShUtil.py

index c8f933245d31c7fad93705916c04792b3ac17d57..dda622a48a8487cbede5ad84d926210865eb0f66 100644 (file)
@@ -67,6 +67,9 @@ class ShLexer:
             elif c == '"':
                 self.eat()
                 str += self.lex_arg_quoted('"')
+            elif c == "'":
+                self.eat()
+                str += self.lex_arg_quoted("'")
             elif not self.win32Escapes and c == '\\':
                 # Outside of a string, '\\' escapes everything.
                 self.eat()
@@ -287,6 +290,10 @@ class TestShParse(unittest.TestCase):
                          Pipeline([Command(['echo', 'hello'], [])], False))
         self.assertEqual(self.parse('echo ""'),
                          Pipeline([Command(['echo', ''], [])], False))
+        self.assertEqual(self.parse("""echo -DFOO='a'"""),
+                         Pipeline([Command(['echo', '-DFOO=a'], [])], False))
+        self.assertEqual(self.parse('echo -DFOO="a"'),
+                         Pipeline([Command(['echo', '-DFOO=a'], [])], False))
 
     def test_redirection(self):
         self.assertEqual(self.parse('echo hello > c'),