Skip to content

Commit 3466bd2

Browse files
committed
Add a unit test for concrete specs that do not satisfy abstract specs
1 parent cdbf559 commit 3466bd2

File tree

2 files changed

+36
-48
lines changed

2 files changed

+36
-48
lines changed

lib/spack/spack/spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3417,7 +3417,7 @@ def constrain(self, other, deps=True):
34173417
if deps:
34183418
changed |= self._constrain_dependencies(other)
34193419

3420-
if other.concrete and not self.concrete:
3420+
if other.concrete and not self.concrete and other.satisfies(self):
34213421
self._finalize_concretization()
34223422

34233423
return changed

lib/spack/spack/test/spec_semantics.py

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,9 @@
2121
InvalidVariantValueError,
2222
MultipleValuesInExclusiveVariantError,
2323
UnknownVariantError,
24-
substitute_abstract_variants,
2524
)
2625

2726

28-
def make_spec(spec_like, concrete):
29-
spec = Spec(spec_like)
30-
if concrete:
31-
spec._mark_concrete()
32-
substitute_abstract_variants(spec)
33-
return spec
34-
35-
36-
def check_cannot_constrain(target_spec, constraint_spec):
37-
target = make_spec(target_spec, True)
38-
constraint = Spec(constraint_spec)
39-
40-
with pytest.raises(UnsatisfiableSpecError):
41-
constraint.copy().constrain(target)
42-
43-
4427
def check_constrain(expected, spec, constraint):
4528
exp = Spec(expected)
4629
spec = Spec(spec)
@@ -302,6 +285,41 @@ def test_constraining_abstract_specs_with_empty_intersection(self, lhs, rhs):
302285
with pytest.raises(UnsatisfiableSpecError):
303286
rhs.constrain(lhs)
304287

288+
@pytest.mark.parametrize(
289+
"lhs,rhs",
290+
[
291+
("mpich", "mpich +foo"),
292+
("mpich", "mpich~foo"),
293+
("mpich", "mpich foo=1"),
294+
("mpich", "mpich++foo"),
295+
("mpich", "mpich~~foo"),
296+
("mpich", "mpich foo==1"),
297+
# Flags semantics is currently different from other variant
298+
pytest.param("mpich", 'mpich cppflags="-O3"', marks=pytest.mark.xfail),
299+
pytest.param(
300+
"multivalue-variant foo=bar", "multivalue-variant +foo", marks=pytest.mark.xfail
301+
),
302+
pytest.param(
303+
"multivalue-variant foo=bar", "multivalue-variant ~foo", marks=pytest.mark.xfail
304+
),
305+
],
306+
)
307+
def test_concrete_specs_which_do_not_satisfy_abstract(
308+
self, lhs, rhs, default_mock_concretization
309+
):
310+
lhs, rhs = default_mock_concretization(lhs), Spec(rhs)
311+
312+
assert lhs.intersects(rhs)
313+
assert rhs.intersects(lhs)
314+
assert not lhs.satisfies(rhs)
315+
assert not rhs.satisfies(lhs)
316+
317+
with pytest.raises(UnsatisfiableSpecError):
318+
assert lhs.constrain(rhs)
319+
320+
with pytest.raises(UnsatisfiableSpecError):
321+
assert rhs.constrain(lhs)
322+
305323
def test_satisfies_single_valued_variant(self):
306324
"""Tests that the case reported in
307325
https://github.com/spack/spack/pull/2386#issuecomment-282147639
@@ -401,36 +419,6 @@ def test_unsatisfiable_multi_value_variant(self, default_mock_concretization):
401419
with pytest.raises(MultipleValuesInExclusiveVariantError):
402420
a.concretize()
403421

404-
def test_unsatisfiable_variant_types(self):
405-
# These should fail due to incompatible types
406-
407-
# FIXME: these needs to be checked as the new relaxed
408-
# FIXME: semantic makes them fail (constrain does not raise)
409-
# check_unsatisfiable('multivalue-variant +foo',
410-
# 'multivalue-variant foo="bar"')
411-
# check_unsatisfiable('multivalue-variant ~foo',
412-
# 'multivalue-variant foo="bar"')
413-
414-
check_cannot_constrain(
415-
target_spec='multivalue-variant foo="bar"', constraint_spec="multivalue-variant +foo"
416-
)
417-
418-
check_cannot_constrain(
419-
target_spec='multivalue-variant foo="bar"', constraint_spec="multivalue-variant ~foo"
420-
)
421-
422-
def test_unsatisfiable_variants(self):
423-
# 'mpich' is concrete:
424-
check_cannot_constrain("mpich", "mpich+foo")
425-
check_cannot_constrain("mpich", "mpich~foo")
426-
check_cannot_constrain("mpich", "mpich foo=1")
427-
check_cannot_constrain("mpich", "mpich++foo")
428-
check_cannot_constrain("mpich", "mpich~~foo")
429-
check_cannot_constrain("mpich", "mpich foo==1")
430-
431-
def test_unsatisfiable_compiler_flag(self):
432-
check_cannot_constrain("mpich", 'mpich cppflags="-O3"')
433-
434422
def test_copy_satisfies_transitive(self):
435423
spec = Spec("dttop")
436424
spec.concretize()

0 commit comments

Comments
 (0)