1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
import os
import pytest
from buildstream import _yaml
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils import cli
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'variables',
)
PROTECTED_VARIABLES = [('project-name'), ('element-name'), ('max-jobs')]
@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES)
@pytest.mark.datafiles(DATA_DIR)
def test_use_of_protected_var_project_conf(cli, tmpdir, datafiles, protected_var):
project = os.path.join(str(datafiles), 'simple')
conf = {
'name': 'test',
'variables': {
protected_var: 'some-value'
}
}
_yaml.dump(conf, os.path.join(project, 'project.conf'))
element = {
'kind': 'import',
'sources': [
{
'kind': 'local',
'path': 'foo.txt'
}
],
}
_yaml.dump(element, os.path.join(project, 'target.bst'))
result = cli.run(project=project, args=['build', 'target.bst'])
result.assert_main_error(ErrorDomain.LOAD,
LoadErrorReason.PROTECTED_VARIABLE_REDEFINED)
@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES)
@pytest.mark.datafiles(DATA_DIR)
def test_use_of_protected_var_element_overrides(cli, tmpdir, datafiles, protected_var):
project = os.path.join(str(datafiles), 'simple')
conf = {
'name': 'test',
'elements': {
'manual': {
'variables': {
protected_var: 'some-value'
}
}
}
}
_yaml.dump(conf, os.path.join(project, 'project.conf'))
element = {
'kind': 'manual',
'sources': [
{
'kind': 'local',
'path': 'foo.txt'
}
],
}
_yaml.dump(element, os.path.join(project, 'target.bst'))
result = cli.run(project=project, args=['build', 'target.bst'])
result.assert_main_error(ErrorDomain.LOAD,
LoadErrorReason.PROTECTED_VARIABLE_REDEFINED)
@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES)
@pytest.mark.datafiles(DATA_DIR)
def test_use_of_protected_var_in_element(cli, tmpdir, datafiles, protected_var):
project = os.path.join(str(datafiles), 'simple')
element = {
'kind': 'import',
'sources': [
{
'kind': 'local',
'path': 'foo.txt'
}
],
'variables': {
protected_var: 'some-value'
}
}
_yaml.dump(element, os.path.join(project, 'target.bst'))
result = cli.run(project=project, args=['build', 'target.bst'])
result.assert_main_error(ErrorDomain.LOAD,
LoadErrorReason.PROTECTED_VARIABLE_REDEFINED)
|