env: add test to ensure config precedence is high-to-low

This commit is contained in:
Todd Gamblin 2018-10-26 16:51:06 -07:00
parent 66aa3426ac
commit 36623a27fd
2 changed files with 46 additions and 3 deletions

View File

@ -377,9 +377,12 @@ def repo(self):
def included_config_scopes(self):
"""List of included configuration scopes from the environment.
Scopes are in order from lowest to highest precedence, i.e., the
order they should be pushed on the stack, but the opposite of the
order they appaer in the spack.yaml file.
Scopes are listed in the YAML file in order from highest to
lowest precedence, so configuration from earlier scope will take
precedence over later ones.
This routine returns them in the order they should be pushed onto
the internal scope stack (so, in reverse, from lowest to highest).
"""
scopes = []

View File

@ -428,6 +428,46 @@ def test_env_config_precedence():
x.satisfies('libelf@0.8.12') for x in e._get_environment_specs())
def test_included_config_precedence():
test_config = """\
env:
include:
- ./high-config.yaml # this one should take precedence
- ./low-config.yaml
specs:
- mpileaks
"""
spack.package_prefs.PackagePrefs.clear_caches()
_env_create('test', StringIO(test_config))
e = ev.read('test')
with open(os.path.join(e.path, 'high-config.yaml'), 'w') as f:
f.write("""\
packages:
libelf:
version: [0.8.10] # this should override libelf version below
""")
with open(os.path.join(e.path, 'low-config.yaml'), 'w') as f:
f.write("""\
packages:
mpileaks:
version: [2.2]
libelf:
version: [0.8.12]
""")
ev.prepare_config_scope(e)
e.concretize()
assert any(
x.satisfies('mpileaks@2.2') for x in e._get_environment_specs())
assert any(
[x.satisfies('libelf@0.8.10') for x in e._get_environment_specs()])
def test_bad_env_yaml_format(tmpdir):
filename = str(tmpdir.join('spack.yaml'))
with open(filename, 'w') as f: