Skip to content

Commit

Permalink
pkg: add initial pkg.intersects(Dep) support
Browse files Browse the repository at this point in the history
  • Loading branch information
radhermit committed Jun 15, 2024
1 parent dae2bbd commit 4c91443
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/pkgcraft/pkg/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def self.release(ptr)
attach_function :pkgcraft_pkg_format, [:pointer], :int
attach_function :pkgcraft_pkg_free, [:pointer], :void
attach_function :pkgcraft_pkg_hash, [Pkg], :uint64
attach_function :pkgcraft_pkg_intersects_dep, [Pkg, Pkgcraft::Dep::Dep], :bool
attach_function :pkgcraft_pkg_repo, [Pkg], :pointer
attach_function :pkgcraft_pkg_restrict, [Pkg], Restrict
attach_function :pkgcraft_pkg_str, [Pkg], String
Expand Down Expand Up @@ -90,6 +91,12 @@ def version
cpv.version
end

def intersects(other)
return C.pkgcraft_pkg_intersects_dep(self, other) if other.is_a? Pkgcraft::Dep::Dep

raise TypeError.new("Invalid type: #{other.class}")
end

def <=>(other)
C.pkgcraft_pkg_cmp(self, other)
end
Expand Down
22 changes: 22 additions & 0 deletions test/pkg/test_ebuild.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ def test_version
assert_equal(Version.new("1"), pkg.version)
end

def test_intersects
repo = EbuildTemp.new(id: "test")
pkg = repo.create_pkg("cat/pkg-1-r2", "SLOT=0/1")
assert(pkg.intersects(Dep.new("cat/pkg")))
refute(pkg.intersects(Dep.new("a/b")))
assert(pkg.intersects(Dep.new("=cat/pkg-1-r2")))
refute(pkg.intersects(Dep.new(">cat/pkg-1-r2")))
assert(pkg.intersects(Dep.new("cat/pkg:0")))
refute(pkg.intersects(Dep.new("cat/pkg:1")))
assert(pkg.intersects(Dep.new("cat/pkg:0/1")))
refute(pkg.intersects(Dep.new("cat/pkg:0/2")))
assert(pkg.intersects(Dep.new("cat/pkg::test")))
refute(pkg.intersects(Dep.new("cat/pkg::repo")))

# invalid types
["", nil].each do |obj|
assert_raises TypeError do
pkg.intersects(obj)
end
end
end

def test_path
repo = EbuildTemp.new
path = repo.create_ebuild("cat/pkg-1")
Expand Down

0 comments on commit 4c91443

Please sign in to comment.