Skip to content

Commit

Permalink
test: add unit test for conditional tools
Browse files Browse the repository at this point in the history
  • Loading branch information
jkloetzke committed Aug 2, 2024
1 parent 370b01e commit 6955f6a
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions test/unit/test_input_recipeset.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def writeDefault(self, content, layer=[]):
with open(os.path.join(path, "default.yaml"), "w") as f:
f.write(yaml.dump(content))

def generate(self, sandboxEnabled=False):
def generate(self, sandboxEnabled=False, env={}):
recipes = RecipeSet()
recipes.parse()
recipes.parse(env)
return recipes.generatePackages(lambda x,y: "unused", sandboxEnabled)


Expand Down Expand Up @@ -1622,6 +1622,50 @@ def testStrongOverride(self):
r2 = packages.walkPackagePath("r2").getPackageStep()
self.assertNotEqual(r1.getVariantId(), r2.getVariantId())

class TestConditionalTools(RecipesTmp, TestCase):
"""Test behaviour of conditional tools"""

def setUp(self):
super().setUp()
self.writeConfig({
"bobMinimumVersion" : "0.24",
})
self.writeRecipe("tool", """\
multiPackage:
"1":
provideTools:
tool-foo: "."
packageScript: "foo"
"2":
provideTools:
tool-bar: "."
packageScript: "bar"
""")

def testConditional(self):
self.writeRecipe("root", """\
root: True
depends:
- name: tool-1
use: [tools]
- name: tool-2
use: [tools]
packageTools:
- tool-foo
- name: tool-bar
if: "${BAR:-}"
""")

packages = self.generate()
r = packages.walkPackagePath("root").getPackageStep()
self.assertEqual(set(r.getTools().keys()), { "tool-foo" },
"By default, 'tool-bar' is not used")

packages = self.generate(env = { "BAR" : "1" })
r = packages.walkPackagePath("root").getPackageStep()
self.assertEqual(set(r.getTools().keys()), { "tool-foo", "tool-bar" },
"If enabled, 'tool-bar' is used")

class TestScmIgnoreUserPolicy(RecipesTmp, TestCase):
""" Test behaviour of scmIgnoreUser policy"""

Expand Down

0 comments on commit 6955f6a

Please sign in to comment.