From bbeb2fd8ff2fabf22a80678d9e58be0df9e8b4f7 Mon Sep 17 00:00:00 2001 From: AaronYoung5 Date: Thu, 13 Feb 2025 17:41:22 -0500 Subject: [PATCH] Added support for negative alt condition --- test/test_unit_score_file.py | 21 +++++++++++++++ yadm | 50 ++++++++++++++++++++++++++++++------ 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/test/test_unit_score_file.py b/test/test_unit_score_file.py index 9952c0c..673b954 100644 --- a/test/test_unit_score_file.py +++ b/test/test_unit_score_file.py @@ -321,3 +321,24 @@ def test_underscores_and_upper_case_in_distro_and_family(runner, yadm): assert run.success assert run.err == "" assert run.out == expected + +def test_negative_class_condition(runner, yadm): + """Test negative class condition: returns 0 when matching and proper score when not matching.""" + script = f""" + YADM_TEST=1 source {yadm} + score=0 + local_class="testclass" + local_classes=("testclass") + # Negative condition with matching value should yield delta -1 and zero the score. + score_file "filename##!class.testclass" "dest" + echo "score: $score" + # Negative condition with non-matching value should yield delta 16. + score=0 + score_file "filename##!class.badclass" "dest" + echo "score2: $score" + """ + run = runner(command=["bash"], inp=script) + assert run.success + output = run.out.strip().splitlines() + assert output[0] == "score: 0" + assert output[1] == "score2: 1016" diff --git a/yadm b/yadm index f0c1403..0a529d6 100755 --- a/yadm +++ b/yadm @@ -179,6 +179,13 @@ function score_file() { local value=${field#*.} [ "$field" = "$label" ] && value="" # when .value is omitted + # Check for negative condition prefix (e.g., "!