diff options
author | bst-marge-bot <marge-bot@buildstream.build> | 2020-05-18 11:47:42 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-05-18 11:47:42 +0000 |
commit | ef00fc2f384631a001442b5cd2b5765c58809720 (patch) | |
tree | 773d2bc0a7003563dfa77cfb2ecaa208a1d388d6 | |
parent | 0c9ca749b32c2ed8b41e6f94e7c6f5431eae4d70 (diff) | |
parent | 6157b4fd09397ecb5304c523bf31f079f6a8d44e (diff) | |
download | buildstream-ef00fc2f384631a001442b5cd2b5765c58809720.tar.gz |
Merge branch 'chandan/fix-subst-non-greedy' into 'master'
_frontend/profile: Use non-greedy search to substitute variables
Closes #1307
See merge request BuildStream/buildstream!1932
-rw-r--r-- | src/buildstream/_frontend/profile.py | 2 | ||||
-rw-r--r-- | tests/format/substitutions.py | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/buildstream/_frontend/profile.py b/src/buildstream/_frontend/profile.py index f49be5b0a..02b601c66 100644 --- a/src/buildstream/_frontend/profile.py +++ b/src/buildstream/_frontend/profile.py @@ -73,4 +73,4 @@ class Profile: return self.fmt(formatted, **kwargs) # Lazy regex, after our word, match anything that does not have '%' - return re.sub(r"%(\{(" + varname + r")[^%]*\})", subst_callback, text) + return re.sub(r"%(\{(" + varname + r")[^%]*?\})", subst_callback, text) diff --git a/tests/format/substitutions.py b/tests/format/substitutions.py new file mode 100644 index 000000000..265f13e66 --- /dev/null +++ b/tests/format/substitutions.py @@ -0,0 +1,20 @@ +# Pylint doesn't play well with fixtures and dependency injection from pytest +# pylint: disable=redefined-outer-name + +import os +import pytest +from buildstream.testing import cli # pylint: disable=unused-import + + +DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project", "default") + + +# Test that output is formatted correctly, when there are multiple matches of a +# variable that is known to BuildStream. +# +@pytest.mark.datafiles(os.path.join(DATA_DIR)) +def test_match_multiple(cli, datafiles): + project = str(datafiles) + result = cli.run(project=project, args=["show", "--format", "%{name} {name} %{name}", "manual.bst"]) + result.assert_success() + assert result.output == "manual.bst {name} manual.bst\n" |