Files
sousa-gecko/testing/mozbase/mozshellutil/tests/test.py
T
Yannis Juglaret d5945624a8 Bug 1518065 - Add mozshellutil mozbase module to resolve circular dependency. r=mozbase-reviewers,mach-reviewers,geckoview-reviewers,taskgraph-reviewers,geckodriver-reviewers,bhearsum,whimboo,ahochheiden,m_kato
Move shellutil.py from python/mozbuild/mozbuild/ to a new standalone
mozbase module at testing/mozbase/mozshellutil/ to resolve circular
dependency issues between mozbuild and mozdebug in the next patch.

The new mozshellutil module provides shell command line parsing
utilities (split(), quote(), and MetaCharacterException) that can be
used by other mozbase modules without depending on the full mozbuild
package.

Differential Revision: https://phabricator.services.mozilla.com/D277646
2026-01-05 09:18:12 +00:00

69 lines
1.4 KiB
Python

#!/usr/bin/env python
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import mozunit
import pytest
from mozshellutil import MetaCharacterException, quote, split
def test_quote_simple():
assert quote("a", "b") == "a b"
def test_quote_with_spaces():
assert quote("a b", "c") == "'a b' c"
def test_quote_empty_string():
assert quote("") == "''"
def test_quote_single_quote():
assert quote("a'b") == "'a'\\''b'"
def test_quote_with_special_chars():
result = quote("a$b")
assert result == "'a$b'"
def test_quote_int():
assert quote(123) == "123"
def test_split_simple():
assert split("a b c") == ["a", "b", "c"]
def test_split_quoted():
assert split("'a b' c") == ["a b", "c"]
def test_split_double_quoted():
assert split('"a b" c') == ["a b", "c"]
def test_split_escaped():
assert split(r"a\ b c") == ["a b", "c"]
def test_split_with_comment():
assert split("a b # comment") == ["a", "b"]
def test_split_metacharacter_exception():
with pytest.raises(MetaCharacterException) as exc_info:
split("a | b")
assert exc_info.value.char == "|"
def test_split_escaped_newlines():
assert split("a\\\nb") == ["ab"]
if __name__ == "__main__":
mozunit.main()