From 2e11cd5d340641f9275e866fe255b0af1b28d603 Mon Sep 17 00:00:00 2001 From: Anton Reinhard <23334666+AntonReinhard@users.noreply.github.com> Date: Mon, 6 May 2024 11:08:09 +0200 Subject: [PATCH] Fix integ test gen (#31) Fixes #30 --- .ci/integTestGen/src/integTestGen.jl | 30 ++++---- .ci/integTestGen/test/Project.toml | 1 + .ci/integTestGen/test/runtests.jl | 102 +++++++++++++++++++-------- 3 files changed, 91 insertions(+), 42 deletions(-) diff --git a/.ci/integTestGen/src/integTestGen.jl b/.ci/integTestGen/src/integTestGen.jl index 3c55adb..ffed093 100644 --- a/.ci/integTestGen/src/integTestGen.jl +++ b/.ci/integTestGen/src/integTestGen.jl @@ -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} = [] @@ -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}) @@ -157,12 +162,14 @@ 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 @@ -170,27 +177,24 @@ function traverse_tree!( # - 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 diff --git a/.ci/integTestGen/test/Project.toml b/.ci/integTestGen/test/Project.toml index 1efbf97..6fa13a9 100644 --- a/.ci/integTestGen/test/Project.toml +++ b/.ci/integTestGen/test/Project.toml @@ -1,3 +1,4 @@ [deps] +PkgDependency = "9eb5382b-762c-48ca-8139-e736883fe800" Term = "22787eb5-b846-44ae-b979-8e399b8463ab" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/.ci/integTestGen/test/runtests.jl b/.ci/integTestGen/test/runtests.jl index 0644aab..a561cdb 100644 --- a/.ci/integTestGen/test/runtests.jl +++ b/.ci/integTestGen/test/runtests.jl @@ -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 @@ -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 = [ @@ -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"]