Skip to content

Commit

Permalink
Fix integ test gen (#31)
Browse files Browse the repository at this point in the history
Fixes #30
  • Loading branch information
AntonReinhard authored May 6, 2024
1 parent 08613ad commit 2e11cd5
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 42 deletions.
30 changes: 17 additions & 13 deletions .ci/integTestGen/src/integTestGen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Return a list of packages, which have the package `package_name` as a dependency
"""
function depending_projects(
package_name::String,
package_filter,
package_filter::AbstractVector{<:AbstractString},
project_tree=PkgDependency.builddict(Pkg.project().uuid, Pkg.project()),
)::AbstractVector{String}
packages::AbstractVector{String} = []
Expand All @@ -148,6 +148,11 @@ function depending_projects(
return packages
end

function clean_pkg_name(pkg_name::AbstractString)
# remove color tags (?) from the package names
return replace(pkg_name, r"\{[^}]*\}" => "")
end

"""
traverse_tree!(package_name::String, package_filter, project_tree, packages::AbstractVector{String}, visited_packages::AbstractVector{String})
Expand All @@ -157,40 +162,39 @@ See [`depending_projects`](@ref)
"""
function traverse_tree!(
package_name::String,
package_filter,
project_tree,
package_filter::AbstractVector{<:AbstractString},
project_tree::AbstractVector{<:PkgDependency.PkgTree},
packages::AbstractVector{String},
visited_packages::AbstractVector{String},
)
for project_name_version in keys(project_tree)
for pkg_tree in project_tree
project_name_version = clean_pkg_name(pkg_tree.name)

# remove project version from string -> usual shape: `packageName.jl version`
project_name = split(project_name_version)[1]
# fullfil the requirements
# - package starts with the prefix
# - the dependency is not nothing (I think this representate, that the package was already set as dependency of a another package and therefore do not repead the dependencies)
# - has dependency
# - was not already checked

if project_name in package_filter &&
project_tree[project_name_version] !== nothing &&
!isempty(project_tree[project_name_version]) &&
!isempty(pkg_tree.children) &&
!(project_name in visited_packages)
# only investigate each package one time
# assumption: package name with it's dependency is unique
push!(visited_packages, project_name)
for dependency_name_version in keys(project_tree[project_name_version])
for dependency in pkg_tree.children
dependency_name_version = clean_pkg_name(dependency.name)
# dependency matches, add to packages
if startswith(dependency_name_version, package_name)
push!(packages, project_name)
break
end
end
# independent of a match, under investigate all dependencies too, because they can also have the package as dependency
# independent of a match, investigate all dependencies too, because they can also have the package as dependency
traverse_tree!(
package_name,
package_filter,
project_tree[project_name_version],
packages,
visited_packages,
package_name, package_filter, pkg_tree.children, packages, visited_packages
)
end
end
Expand Down
1 change: 1 addition & 0 deletions .ci/integTestGen/test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[deps]
PkgDependency = "9eb5382b-762c-48ca-8139-e736883fe800"
Term = "22787eb5-b846-44ae-b979-8e399b8463ab"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
102 changes: 73 additions & 29 deletions .ci/integTestGen/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
using integTestGen
using Test
using PkgDependency

import Term.Trees: Tree
import PkgDependency.PkgTree

# set environment variable PRINTTREE=on to visualize the project trees of the testsets
printTree::Bool = haskey(ENV, "PRINTTREE")

@testset "direct dependency to main" begin
project_tree = Dict("MyMainProject.jl 1.0.0" => Dict("MyDep1.jl 1.0.0" => Dict()))
project_tree = [PkgTree("MyMainProject.jl 1.0.0", [PkgTree("MyDep1.jl 1.0.0", [])])]

if printTree
print(Tree(project_tree; name="direct dependency to main"))
display(
PkgDependency.Tree(
PkgTree("Direct dependency to main tree", project_tree);
printkeys=false,
print_node_function=PkgDependency.writenode,
),
)
end

# dependency exist and prefix is correct
Expand All @@ -33,23 +41,48 @@ end

@testset "complex dependencies" begin
#! format: off
project_tree = Dict("MyMainProject.jl 1.0.0" =>
Dict("MyDep1.jl 1.0.0" => Dict(),
"MyDep2.jl 1.0.0" => Dict("MyDep3.jl 1.0.0" => Dict(),
"ForeignDep1.jl 1.0.0" => Dict()),
"ForeignDep2.jl 1.0.0" => Dict("ForeignDep3.jl 1.0.0" => Dict(),
"ForeignDep4.jl 1.0.0" => Dict()),
"MyDep4.jl 1.0.0" => Dict("MyDep5.jl 1.0.0" => Dict("MyDep3.jl 1.0.0" => Dict())),
"ForeignDep2.jl 1.0.0" => Dict("MyDep5.jl 1.0.0" => Dict("MyDep3.jl 1.0.0" => Dict()),
"MyDep3.jl 1.0.0" => Dict(),
"MyDep6.jl 1.0.0" => Dict("MyDep3.jl 1.0.0" => Dict())),
"MyDep7.jl 1.0.0" => Dict("MyDep5.jl 1.0.0" => Dict("MyDep3.jl 1.0.0" => Dict()),
"MyDep3.jl 1.0.0" => Dict()),
)
)
project_tree = [
PkgTree("MyMainProject.jl 1.0.0", [
PkgTree("MyDep1.jl 1.0.0", []),
PkgTree("MyDep2.jl 1.0.0", [
PkgTree("MyDep3.jl 1.0.0", []),
PkgTree("ForeignDep1.jl 1.0.0", [])
]),
PkgTree("ForeignDep2.jl 1.0.0", [
PkgTree("ForeignDep3.jl 1.0.0", []),
PkgTree("ForeignDep4.jl 1.0.0", [])
]),
PkgTree("MyDep4.jl 1.0.0", [
PkgTree("MyDep5.jl 1.0.0", [
PkgTree("MyDep3.jl 1.0.0", [])
])
]),
PkgTree("ForeignDep2.jl 1.0.0", [
PkgTree("MyDep5.jl 1.0.0", [
PkgTree("MyDep3.jl 1.0.0", [])
]),
PkgTree("MyDep3.jl 1.0.0", []),
PkgTree("MyDep6.jl 1.0.0", [
PkgTree("MyDep3.jl 1.0.0", [])
])
]),
PkgTree("MyDep7.jl 1.0.0", [
PkgTree("MyDep5.jl 1.0.0", [
PkgTree("MyDep3.jl 1.0.0", [])
]),
PkgTree("MyDep3.jl 1.0.0", [])
])
])
]
#! format: on
if printTree
print(Tree(project_tree; name="complex dependencies"))
display(
PkgDependency.Tree(
PkgTree("Complex dependency tree", project_tree);
printkeys=false,
print_node_function=PkgDependency.writenode,
),
)
end

package_filter = [
Expand Down Expand Up @@ -86,20 +119,31 @@ end

@testset "circular dependency" begin
# I cannot create a real circular dependency with this data structur, but if Circulation appears in an output, we passed MyDep1.jl and MyDep2.jl two times, which means it is a circle
project_tree = Dict(
"MyMainProject.jl 1.0.0" => Dict(
"MyDep1.jl 1.0.0" => Dict(
"MyDep2.jl 1.0.0" => Dict(
"MyDep1.jl 1.0.0" => Dict(
"MyDep2.jl 1.0.0" => Dict("Circulation" => Dict())
),
),
),
),
)

#! format: off
project_tree = [
PkgTree("MyMainProject.jl 1.0.0", [
PkgTree("MyDep1.jl 1.0.0", [
PkgTree("MyDep2.jl 1.0.0", [
PkgTree("MyDep1.jl 1.0.0", [
PkgTree("MyDep2.jl 1.0.0", [
PkgTree("Circulation", [])
])
])
])
])
])
]
#! format: on

if printTree
print(Tree(project_tree; name="circular dependencies"))
display(
PkgDependency.Tree(
PkgTree("Circular dependency tree", project_tree);
printkeys=false,
print_node_function=PkgDependency.writenode,
),
)
end

package_filter = ["MyMainProject.jl", "MyDep1.jl", "MyDep2.jl"]
Expand Down

0 comments on commit 2e11cd5

Please sign in to comment.