CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
146 lines
4.5 KiB
Python
146 lines
4.5 KiB
Python
# RUN: %{python} %s
|
|
|
|
import unittest
|
|
|
|
from lit.ShUtil import Command, Pipeline, Seq, ShLexer, ShParser
|
|
|
|
|
|
class TestShLexer(unittest.TestCase):
|
|
def lex(self, str, *args, **kwargs):
|
|
return list(ShLexer(str, *args, **kwargs).lex())
|
|
|
|
def test_basic(self):
|
|
self.assertEqual(
|
|
self.lex("a|b>c&d<e;f"),
|
|
["a", ("|",), "b", (">",), "c", ("&",), "d", ("<",), "e", (";",), "f"],
|
|
)
|
|
|
|
def test_redirection_tokens(self):
|
|
self.assertEqual(self.lex("a2>c"), ["a2", (">",), "c"])
|
|
self.assertEqual(self.lex("a 2>c"), ["a", (">", 2), "c"])
|
|
|
|
def test_quoting(self):
|
|
self.assertEqual(self.lex(""" 'a' """), ["a"])
|
|
self.assertEqual(self.lex(""" "hello\\"world" """), ['hello"world'])
|
|
self.assertEqual(self.lex(""" "hello\\'world" """), ["hello\\'world"])
|
|
self.assertEqual(self.lex(""" "hello\\\\world" """), ["hello\\world"])
|
|
self.assertEqual(self.lex(""" he"llo wo"rld """), ["hello world"])
|
|
self.assertEqual(self.lex(""" a\\ b a\\\\b """), ["a b", "a\\b"])
|
|
self.assertEqual(self.lex(""" "" "" """), ["", ""])
|
|
self.assertEqual(self.lex(""" a\\ b """, win32Escapes=True), ["a\\", "b"])
|
|
self.assertEqual(self.lex('"\\$y = 11"'), ["$y = 11"])
|
|
self.assertEqual(self.lex('"expr \\$y = 11"'), ["expr $y = 11"])
|
|
self.assertEqual(self.lex("'\\$y = 11'"), ["\\$y = 11"])
|
|
self.assertEqual(self.lex("'expr \\$y = 11'"), ["expr \\$y = 11"])
|
|
|
|
class TestShParse(unittest.TestCase):
|
|
def parse(self, str):
|
|
return ShParser(str).parse()
|
|
|
|
def test_basic(self):
|
|
self.assertEqual(
|
|
self.parse("echo hello"), 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"),
|
|
Pipeline([Command(["echo", "hello"], [(((">"),), "c")])], False),
|
|
)
|
|
self.assertEqual(
|
|
self.parse("echo hello > c >> d"),
|
|
Pipeline(
|
|
[Command(["echo", "hello"], [((">",), "c"), ((">>",), "d")])], False
|
|
),
|
|
)
|
|
self.assertEqual(
|
|
self.parse("a 2>&1"), Pipeline([Command(["a"], [((">&", 2), "1")])], False)
|
|
)
|
|
|
|
def test_pipeline(self):
|
|
self.assertEqual(
|
|
self.parse("a | b"),
|
|
Pipeline([Command(["a"], []), Command(["b"], [])], False),
|
|
)
|
|
|
|
self.assertEqual(
|
|
self.parse("a | b | c"),
|
|
Pipeline(
|
|
[Command(["a"], []), Command(["b"], []), Command(["c"], [])], False
|
|
),
|
|
)
|
|
|
|
def test_list(self):
|
|
self.assertEqual(
|
|
self.parse("a ; b"),
|
|
Seq(
|
|
Pipeline([Command(["a"], [])], False),
|
|
";",
|
|
Pipeline([Command(["b"], [])], False),
|
|
),
|
|
)
|
|
|
|
self.assertEqual(
|
|
self.parse("a & b"),
|
|
Seq(
|
|
Pipeline([Command(["a"], [])], False),
|
|
"&",
|
|
Pipeline([Command(["b"], [])], False),
|
|
),
|
|
)
|
|
|
|
self.assertEqual(
|
|
self.parse("a && b"),
|
|
Seq(
|
|
Pipeline([Command(["a"], [])], False),
|
|
"&&",
|
|
Pipeline([Command(["b"], [])], False),
|
|
),
|
|
)
|
|
|
|
self.assertEqual(
|
|
self.parse("a || b"),
|
|
Seq(
|
|
Pipeline([Command(["a"], [])], False),
|
|
"||",
|
|
Pipeline([Command(["b"], [])], False),
|
|
),
|
|
)
|
|
|
|
self.assertEqual(
|
|
self.parse("a && b || c"),
|
|
Seq(
|
|
Seq(
|
|
Pipeline([Command(["a"], [])], False),
|
|
"&&",
|
|
Pipeline([Command(["b"], [])], False),
|
|
),
|
|
"||",
|
|
Pipeline([Command(["c"], [])], False),
|
|
),
|
|
)
|
|
|
|
self.assertEqual(
|
|
self.parse("a; b"),
|
|
Seq(
|
|
Pipeline([Command(["a"], [])], False),
|
|
";",
|
|
Pipeline([Command(["b"], [])], False),
|
|
),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|