summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-07-17 09:48:55 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-17 09:38:59 +0000
commit2bd91640f4ba7e29d92633f7e573deb2073dc27d (patch)
tree015ef9a27ab035d671d98d91372d9f86eaf5a95d
parent9b2cac15e57d879f3a5da8f0f9e013ba533f4d15 (diff)
downloadbuildstream-2bd91640f4ba7e29d92633f7e573deb2073dc27d.tar.gz
_variables: Fix reporting of missing variable
When the missing variable was not defined, we would get an exception as a string doesn't contain provenance information. - Add a test to prevent regression
-rw-r--r--src/buildstream/_variables.pyx2
-rw-r--r--tests/format/variables.py5
-rw-r--r--tests/format/variables/missing_variables/manual2.bst4
3 files changed, 8 insertions, 3 deletions
diff --git a/src/buildstream/_variables.pyx b/src/buildstream/_variables.pyx
index 470feddc9..8f91c9ced 100644
--- a/src/buildstream/_variables.pyx
+++ b/src/buildstream/_variables.pyx
@@ -139,7 +139,7 @@ cdef class Variables:
for var in expstr[1::2]:
if var not in self._expstr_map:
line = " unresolved variable '{unmatched}' in declaration of '{variable}' at: {provenance}"
- provenance = expstr.get_provenance()
+ provenance = self.original.get_scalar(key).get_provenance()
summary.append(line.format(unmatched=var, variable=key, provenance=provenance))
if summary:
raise LoadError(LoadErrorReason.UNRESOLVED_VARIABLE,
diff --git a/tests/format/variables.py b/tests/format/variables.py
index 93814279a..4610e039f 100644
--- a/tests/format/variables.py
+++ b/tests/format/variables.py
@@ -78,11 +78,12 @@ def test_overrides(cli, datafiles, target, varname, expected):
assert result_vars.get_str(varname) == expected
+@pytest.mark.parametrize("element", ["manual.bst", "manual2.bst"])
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'missing_variables'))
-def test_missing_variable(cli, datafiles):
+def test_missing_variable(cli, datafiles, element):
project = str(datafiles)
result = cli.run(project=project, silent=True, args=[
- 'show', '--deps', 'none', '--format', '%{config}', 'manual.bst'
+ 'show', '--deps', 'none', '--format', '%{config}', element
])
result.assert_main_error(ErrorDomain.LOAD,
LoadErrorReason.UNRESOLVED_VARIABLE)
diff --git a/tests/format/variables/missing_variables/manual2.bst b/tests/format/variables/missing_variables/manual2.bst
new file mode 100644
index 000000000..bd8e2baf7
--- /dev/null
+++ b/tests/format/variables/missing_variables/manual2.bst
@@ -0,0 +1,4 @@
+kind: manual
+
+variables:
+ test: hello %{missing}