From c11c7f32bbb095771b085d4a8ca25cdf3054ccbe Mon Sep 17 00:00:00 2001 From: Tomas Fiers Date: Fri, 13 Jan 2023 21:58:57 +0100 Subject: [PATCH] Reorganize Internals [close #75] there's different modules now, it's nice. Also reorganize test along with it. and add test/activate_standalone.jl --- .gitignore | 1 + docs/src/bg/related-work.md | 5 +- docs/src/ref/end-user.md | 2 +- docs/src/ref/internals.md | 6 +- src/PkgGraph.jl | 28 ++- .../local.jl => includes/dotcommand.jl} | 0 src/{ => includes}/enduser.jl | 2 +- src/{internals => includes}/options.jl | 4 +- src/{internals => includes}/webapps.jl | 2 +- src/internals/Internals.jl | 63 ------ src/modules/DepGraph.jl | 32 ++++ .../DepGraph}/graphsjl.jl | 10 +- .../depgraph.jl => modules/DepGraph/main.jl} | 4 +- .../DepGraph}/project.jl | 4 +- .../DepGraph}/registry.jl | 0 src/{internals => modules/DepGraph}/stdlib.jl | 0 .../dot.jl => modules/DotString.jl} | 13 +- .../loadtime.jl => modules/LoadTime.jl} | 2 +- src/{internals => modules}/SVG.jl | 2 + standalone/Manifest.toml | 179 ++++++++++++++++++ standalone/Project.toml | 2 + test/ReadMe.md | 25 ++- test/activate_standalone.jl | 29 +++ test/integration.jl | 73 ------- test/integration/all.jl | 8 + test/integration/deps-as-dot.jl | 41 ++++ test/{ => integration}/graphsjl_example.jl | 0 test/runtests.jl | 14 +- test/standalone/Project.toml | 3 + test/unit.jl | 94 --------- test/unit/DepGraph.jl | 64 +++++++ test/unit/DotString.jl | 32 ++++ test/unit/LoadTime.jl | 7 + test/unit/PkgGraph.jl | 30 +++ test/unit/SVG.jl | 16 ++ test/unit/all.jl | 13 ++ test/{ => unit/svg}/simple-dot-output.svg | 0 .../svg}/simple-dot-with-darkmode.svg | 0 38 files changed, 531 insertions(+), 279 deletions(-) rename src/{internals/local.jl => includes/dotcommand.jl} (100%) rename src/{ => includes}/enduser.jl (96%) rename src/{internals => includes}/options.jl (89%) rename src/{internals => includes}/webapps.jl (95%) delete mode 100644 src/internals/Internals.jl create mode 100644 src/modules/DepGraph.jl rename src/{internals => modules/DepGraph}/graphsjl.jl (92%) rename src/{internals/depgraph.jl => modules/DepGraph/main.jl} (97%) rename src/{internals => modules/DepGraph}/project.jl (96%) rename src/{internals => modules/DepGraph}/registry.jl (100%) rename src/{internals => modules/DepGraph}/stdlib.jl (100%) rename src/{internals/dot.jl => modules/DotString.jl} (92%) rename src/{internals/loadtime.jl => modules/LoadTime.jl} (99%) rename src/{internals => modules}/SVG.jl (99%) create mode 100644 standalone/Manifest.toml create mode 100644 standalone/Project.toml create mode 100644 test/activate_standalone.jl delete mode 100644 test/integration.jl create mode 100644 test/integration/all.jl create mode 100644 test/integration/deps-as-dot.jl rename test/{ => integration}/graphsjl_example.jl (100%) create mode 100644 test/standalone/Project.toml delete mode 100644 test/unit.jl create mode 100644 test/unit/DepGraph.jl create mode 100644 test/unit/DotString.jl create mode 100644 test/unit/LoadTime.jl create mode 100644 test/unit/PkgGraph.jl create mode 100644 test/unit/SVG.jl create mode 100644 test/unit/all.jl rename test/{ => unit/svg}/simple-dot-output.svg (100%) rename test/{ => unit/svg}/simple-dot-with-darkmode.svg (100%) diff --git a/.gitignore b/.gitignore index 8c9b75b..04e9f2d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /docs/build/ /docs/src-mod/ /docs/localdev/Manifest.toml +/test/standalone/Manifest.toml diff --git a/docs/src/bg/related-work.md b/docs/src/bg/related-work.md index aeda6e3..482a846 100644 --- a/docs/src/bg/related-work.md +++ b/docs/src/bg/related-work.md @@ -19,7 +19,8 @@ Also has `dependencies(pkg)` and `direct_dependencies(pkg)` functions. #### [Graphviz.jl] -Bundles the graphviz binaries (including `dot`) (via [JuliaBinaryWrappers/Graphviz_jll][Graphviz_jll]), and provides access in Julia to graphviz's C API. +Bundles the graphviz binaries (including `dot`) (via [JuliaBinaryWrappers/Graphviz_jll][Graphviz_jll]), +and provides access in Julia to graphviz's C API. Provides the `@dot_str` macro to render dot strings in a notebook. #### [GraphvizDotLang.jl] @@ -27,7 +28,7 @@ Provides the `@dot_str` macro to render dot strings in a notebook. Recent package, under active development at the time of writing. A beautiful package to generate and render dot-strings. Uses Julia's piping syntax. Had I discovered this package before writing PkgGraph, I might have used it as a dependency. (Replacing things -like [`PkgGraph.Internals.to_dot_str`](@ref)). +like [`PkgGraph.to_dot_str`](@ref)). [PkgDependency.jl]: https://github.com/peng1999/PkgDependency.jl diff --git a/docs/src/ref/end-user.md b/docs/src/ref/end-user.md index 7998cbf..ff8bd2b 100644 --- a/docs/src/ref/end-user.md +++ b/docs/src/ref/end-user.md @@ -23,7 +23,7 @@ PkgGraph.create These are keyword arguments that can be used with [`PkgGraph.open`](@ref) and [`PkgGraph.create`](@ref).\ -(They are also fields to [`PkgGraph.Internals.Options`](@ref)). +(They are also fields to [`PkgGraph.Options`](@ref)). #### `jll` Whether to include binary 'JLL' dependencies in the graph diff --git a/docs/src/ref/internals.md b/docs/src/ref/internals.md index fb48d1e..baa187e 100644 --- a/docs/src/ref/internals.md +++ b/docs/src/ref/internals.md @@ -1,14 +1,10 @@ ```@meta -CurrentModule = PkgGraph.Internals +CurrentModule = PkgGraph ``` # Internals -```@docs -Internals -``` - ## Creating a dependency graph ```@docs diff --git a/src/PkgGraph.jl b/src/PkgGraph.jl index 6c615f0..52d325a 100644 --- a/src/PkgGraph.jl +++ b/src/PkgGraph.jl @@ -5,20 +5,32 @@ Use [`PkgGraph.open`](@ref) to view the graph in the browser, or [`PkgGraph.create`](@ref) to generate an image locally. (Note that these functions are not exported). - -See [`PkgGraph.Internals`](@ref) for more functions. """ module PkgGraph -using TOML -using EzXML -using URIs: escapeuri -include("internals/Internals.jl") + +include("modules/DepGraph.jl") +using .DepGraph + +include("modules/LoadTime.jl") +using .LoadTime + +include("modules/DotString.jl") +using .DotString + +include("modules/SVG.jl") +using .SVG + using DefaultApplication -using .Internals -include("enduser.jl") +using URIs: escapeuri +using Base: @kwdef +include("includes/dotcommand.jl") +include("includes/webapps.jl") +include("includes/options.jl") +include("includes/enduser.jl") # No package exports (no namespace pollution) + end # module diff --git a/src/internals/local.jl b/src/includes/dotcommand.jl similarity index 100% rename from src/internals/local.jl rename to src/includes/dotcommand.jl diff --git a/src/enduser.jl b/src/includes/enduser.jl similarity index 96% rename from src/enduser.jl rename to src/includes/enduser.jl index 13059b6..bca6709 100644 --- a/src/enduser.jl +++ b/src/includes/enduser.jl @@ -38,7 +38,7 @@ function create(pkgname, dir=tempdir(); fmt=:png, bg=bg(fmt), open=true, dryrun= if !is_dot_available() && !dryrun error("`dot` program not found on `PATH`. Get it at https://graphviz.org/download/") end - dotstr = to_dot_str(pkgname, Options(; kw...)) + dotstr = to_dot_str(pkgname, Options(; bg, kw...)) imgpath = output_path(pkgname, dir, fmt) if !dryrun create_dot_image(dotstr, fmt, imgpath) diff --git a/src/internals/options.jl b/src/includes/options.jl similarity index 89% rename from src/internals/options.jl rename to src/includes/options.jl index a8fac38..c0eee59 100644 --- a/src/internals/options.jl +++ b/src/includes/options.jl @@ -17,10 +17,10 @@ See [Settings](@ref) for available properties. bg = "transparent" end -depgraph(pkg, o::Options) = +DepGraph.depgraph(pkg, o::Options) = depgraph(pkg; o.jll, o.stdlib) -to_dot_str(pkg, o::Options) = +DotString.to_dot_str(pkg, o::Options) = to_dot_str( depgraph(pkg, o); o.style, diff --git a/src/internals/webapps.jl b/src/includes/webapps.jl similarity index 95% rename from src/internals/webapps.jl rename to src/includes/webapps.jl index 8778238..0ae139d 100644 --- a/src/internals/webapps.jl +++ b/src/includes/webapps.jl @@ -26,7 +26,7 @@ const webapps = [ @doc( """ A list of websites that can render Graphviz dot-formatted -strings. Used by [`Internals.url`](@ref). +strings. Used by [`url`](@ref). Note that these are 'base URLs', to which url-encoded dot-strings can be directly appended. diff --git a/src/internals/Internals.jl b/src/internals/Internals.jl deleted file mode 100644 index ccef58e..0000000 --- a/src/internals/Internals.jl +++ /dev/null @@ -1,63 +0,0 @@ -""" -Namespace for the non-end-user functions in PkgGraph. - -For ease of experimentation, you can import these with -``` -using PkgGraph.Internals -``` -They are also imported in the main module, so they -can be accessed as `PkgGraph.depgraph`, e.g. -""" -module Internals - -using TOML -using UUIDs -include("stdlib.jl") - -using Base: active_project -include("project.jl") - -using Pkg -include("registry.jl") - -include("depgraph.jl") -export depgraph, - should_be_included, - is_jll, - is_in_stdlib, - STDLIB - -include("graphsjl.jl") -export vertices, - node_index, - adjacency_matrix, - as_graphsjl_input, - as_int_pairs, - EdgeList, - Edge - -include("dot.jl") -export to_dot_str, - default_style - -using EzXML -include("SVG.jl") -using .SVG -export SVG - -include("local.jl") -export is_dot_available, - create_dot_image, - dotcommand, - output_path - -using URIs: escapeuri -include("webapps.jl") -export url, - webapps - -using Base: @kwdef -include("options.jl") -export Options - -end diff --git a/src/modules/DepGraph.jl b/src/modules/DepGraph.jl new file mode 100644 index 0000000..989ab0d --- /dev/null +++ b/src/modules/DepGraph.jl @@ -0,0 +1,32 @@ +module DepGraph + +using Pkg +using TOML +using UUIDs +using Base: active_project + +include("DepGraph/stdlib.jl") +export STDLIB, + STDLIB_NAMES + +include("DepGraph/project.jl") + +include("DepGraph/registry.jl") + +include("DepGraph/main.jl") +export depgraph, + should_be_included, + is_jll, + is_in_stdlib, + STDLIB + +include("DepGraph/graphsjl.jl") +export vertices, + node_index, + adjacency_matrix, + as_graphsjl_input, + as_int_pairs, + EdgeList, + Edge + +end diff --git a/src/internals/graphsjl.jl b/src/modules/DepGraph/graphsjl.jl similarity index 92% rename from src/internals/graphsjl.jl rename to src/modules/DepGraph/graphsjl.jl index 4d001d1..8687e58 100644 --- a/src/internals/graphsjl.jl +++ b/src/modules/DepGraph/graphsjl.jl @@ -33,11 +33,11 @@ Extract the unique nodes from the given list of edges. ## Example: ```jldoctest -julia> using PkgGraph.Internals +julia> using PkgGraph -julia> edges = depgraph(:Test); +julia> edges = PkgGraph.depgraph(:Test); -julia> vertices(edges) +julia> PkgGraph.vertices(edges) 8-element Vector{String}: "Test" "InteractiveUtils" @@ -65,11 +65,11 @@ This is useful because Graphs.jl requires vertices to be integers. ## Example: ```jldoctest -julia> using PkgGraph.Internals +julia> using PkgGraph julia> edges = ["A"=>"B", "B"=>"C"]; -julia> node = node_index(edges); +julia> node = PkgGraph.node_index(edges); julia> node("C") 3 diff --git a/src/internals/depgraph.jl b/src/modules/DepGraph/main.jl similarity index 97% rename from src/internals/depgraph.jl rename to src/modules/DepGraph/main.jl index bf096e7..da419f9 100644 --- a/src/internals/depgraph.jl +++ b/src/modules/DepGraph/main.jl @@ -14,9 +14,9 @@ filtered out from the result by setting `jll` and `stdlib` to `false`. ## Example: ```jldoctest -julia> using PkgGraph.Internals +julia> using PkgGraph -julia> depgraph(:Test) +julia> PkgGraph.depgraph(:Test) 8-element Vector{Pair{String, String}}: "Test" => "InteractiveUtils" "InteractiveUtils" => "Markdown" diff --git a/src/internals/project.jl b/src/modules/DepGraph/project.jl similarity index 96% rename from src/internals/project.jl rename to src/modules/DepGraph/project.jl index 0d6c573..2294a90 100644 --- a/src/internals/project.jl +++ b/src/modules/DepGraph/project.jl @@ -59,9 +59,9 @@ packages would share the same name. ## Example: ```jldoctest; filter = r" => .*\$"m -julia> using PkgGraph.Internals +julia> using PkgGraph -julia> packages = packages_in_active_manifest(); +julia> packages = PkgGraph.packages_in_active_manifest(); julia> only(packages["PkgGraph"]) Dict{String, Any} with 4 entries: diff --git a/src/internals/registry.jl b/src/modules/DepGraph/registry.jl similarity index 100% rename from src/internals/registry.jl rename to src/modules/DepGraph/registry.jl diff --git a/src/internals/stdlib.jl b/src/modules/DepGraph/stdlib.jl similarity index 100% rename from src/internals/stdlib.jl rename to src/modules/DepGraph/stdlib.jl diff --git a/src/internals/dot.jl b/src/modules/DotString.jl similarity index 92% rename from src/internals/dot.jl rename to src/modules/DotString.jl index b6a1fc4..7fb2ee2 100644 --- a/src/internals/dot.jl +++ b/src/modules/DotString.jl @@ -1,4 +1,9 @@ +module DotString + +export to_dot_str, + default_style + """ to_dot_str( edges; @@ -35,9 +40,9 @@ julia> edges = [:A => :B, "yes" => "no"]; julia> style = ["node [color=\\"red\\"]"]; -julia> using PkgGraph.Internals +julia> using PkgGraph -julia> to_dot_str(edges; style, bg=:blue, indent=2) |> println +julia> PkgGraph.to_dot_str(edges; style, bg=:blue, indent=2) |> println digraph { bgcolor = "blue" node [fillcolor="white", fontcolor="black", color="black"] @@ -49,7 +54,7 @@ digraph { julia> emptymsg="(empty graph)"; -julia> to_dot_str([]; emptymsg, mode=:dark, style=[]) |> println +julia> PkgGraph.to_dot_str([]; emptymsg, mode=:dark, style=[]) |> println digraph { bgcolor = "transparent" node [fillcolor="black", fontcolor="white", color="white"] @@ -108,3 +113,5 @@ colourschemes() = Dict( :light => colouring(paper="white", ink="black"), :dark => colouring(paper="black", ink="white"), ) + +end diff --git a/src/internals/loadtime.jl b/src/modules/LoadTime.jl similarity index 99% rename from src/internals/loadtime.jl rename to src/modules/LoadTime.jl index 12d0b95..4c93123 100644 --- a/src/internals/loadtime.jl +++ b/src/modules/LoadTime.jl @@ -35,7 +35,7 @@ function time_imports(pkg) loadtimes = parse_timeimports(output) return loadtimes end -r + timeimports_code(pkgname) = "using InteractiveUtils; @time_imports using $pkgname" diff --git a/src/internals/SVG.jl b/src/modules/SVG.jl similarity index 99% rename from src/internals/SVG.jl rename to src/modules/SVG.jl index ab205a5..059a229 100644 --- a/src/internals/SVG.jl +++ b/src/modules/SVG.jl @@ -3,6 +3,8 @@ module SVG using EzXML +export add_darkmode + """ add_darkmode(path, out = path) diff --git a/standalone/Manifest.toml b/standalone/Manifest.toml new file mode 100644 index 0000000..4dbf40c --- /dev/null +++ b/standalone/Manifest.toml @@ -0,0 +1,179 @@ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.8.1" +manifest_format = "2.0" +project_hash = "43d8833e4ef040b47d43a8186556f15356bcf6cb" + +[[deps.ArgTools]] +uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" +version = "1.1.1" + +[[deps.Artifacts]] +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" + +[[deps.Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[deps.Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[deps.DefaultApplication]] +deps = ["InteractiveUtils"] +git-tree-sha1 = "c0dfa5a35710a193d83f03124356eef3386688fc" +uuid = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85" +version = "1.1.0" + +[[deps.Downloads]] +deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] +uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +version = "1.6.0" + +[[deps.EzXML]] +deps = ["Printf", "XML2_jll"] +git-tree-sha1 = "0fa3b52a04a4e210aeb1626def9c90df3ae65268" +uuid = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615" +version = "1.1.0" + +[[deps.FileWatching]] +uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" + +[[deps.InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[deps.JLLWrappers]] +deps = ["Preferences"] +git-tree-sha1 = "abc9885a7ca2052a736a600f7fa66209f96506e1" +uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" +version = "1.4.1" + +[[deps.LibCURL]] +deps = ["LibCURL_jll", "MozillaCACerts_jll"] +uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" +version = "0.6.3" + +[[deps.LibCURL_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] +uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" +version = "7.84.0+0" + +[[deps.LibGit2]] +deps = ["Base64", "NetworkOptions", "Printf", "SHA"] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[deps.LibSSH2_jll]] +deps = ["Artifacts", "Libdl", "MbedTLS_jll"] +uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" +version = "1.10.2+0" + +[[deps.Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[deps.Libiconv_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "c7cb1f5d892775ba13767a87c7ada0b980ea0a71" +uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531" +version = "1.16.1+2" + +[[deps.Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[deps.Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[deps.MbedTLS_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" +version = "2.28.0+0" + +[[deps.MozillaCACerts_jll]] +uuid = "14a3606d-f60d-562e-9121-12d972cd8159" +version = "2022.2.1" + +[[deps.NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" +version = "1.2.0" + +[[deps.Pkg]] +deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +version = "1.8.0" + +[[deps.PkgGraph]] +deps = ["DefaultApplication", "EzXML", "Pkg", "TOML", "URIs", "UUIDs"] +path = "C:\\Users\\tfiers\\.julia\\dev\\PkgGraph" +uuid = "f9c1b9e4-72e8-4a14-ade5-14f45fc35f11" +version = "0.5.0-dev" + +[[deps.Preferences]] +deps = ["TOML"] +git-tree-sha1 = "47e5f437cc0e7ef2ce8406ce1e7e24d44915f88d" +uuid = "21216c6a-2e73-6563-6e65-726566657250" +version = "1.3.0" + +[[deps.Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[deps.REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[deps.Random]] +deps = ["SHA", "Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[deps.SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" +version = "0.7.0" + +[[deps.Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[deps.Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[deps.TOML]] +deps = ["Dates"] +uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +version = "1.0.0" + +[[deps.Tar]] +deps = ["ArgTools", "SHA"] +uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" +version = "1.10.0" + +[[deps.URIs]] +git-tree-sha1 = "ac00576f90d8a259f2c9d823e91d1de3fd44d348" +uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4" +version = "1.4.1" + +[[deps.UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[deps.Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[deps.XML2_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"] +git-tree-sha1 = "93c41695bc1c08c46c5899f4fe06d6ead504bb73" +uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a" +version = "2.10.3+0" + +[[deps.Zlib_jll]] +deps = ["Libdl"] +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" +version = "1.2.12+3" + +[[deps.nghttp2_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" +version = "1.48.0+0" + +[[deps.p7zip_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" +version = "17.4.0+0" diff --git a/standalone/Project.toml b/standalone/Project.toml new file mode 100644 index 0000000..36cebdb --- /dev/null +++ b/standalone/Project.toml @@ -0,0 +1,2 @@ +[deps] +PkgGraph = "f9c1b9e4-72e8-4a14-ade5-14f45fc35f11" diff --git a/test/ReadMe.md b/test/ReadMe.md index 5d32205..0d1627f 100644 --- a/test/ReadMe.md +++ b/test/ReadMe.md @@ -1,16 +1,29 @@ # Testing `PkgGraph` -To run tests locally, in the project root, do: +## Full suite + +To run all tests locally, in the project root, do: ```julia pkg> activate . pkg> test ``` -Doctests are not run here, but rather when building the docs. -For quick re-tests: -```julia -julia> using Revise +## Selected tests -julia> include("test/main.jl") # e.g. +To run only a subset of the tests, run +```julia +julia> include("test/activate_standalone.jl") +``` +and then, e.g, +```julia +julia> include("test/unit/all.jl") ``` +The `activate_standalone.jl` script loads Revise, so you can do quick +re-tests by running `include("test/unit/all.jl")` again after you've +edited the code in `src/`. + + +## Doctests + +Doctests are not run here, but rather when building the docs. diff --git a/test/activate_standalone.jl b/test/activate_standalone.jl new file mode 100644 index 0000000..93968eb --- /dev/null +++ b/test/activate_standalone.jl @@ -0,0 +1,29 @@ + +""" +Activate the test/ project, _but_ with PkgGraph (and Revise) +loaded too. Useful when running a test file on its own +(and not as part of `(PkgGraph) pkg> test`). + +(Note that PkgGraph can't be part of test/Project.toml, +for some Julia reason). +""" + +using Pkg +using Test + +testdir = @__DIR__ +reporoot = dirname(testdir) + +Pkg.activate("standalone/") +Pkg.develop(path=reporoot) + +if isdefined(Main, :PkgGraph) + @warn """ + PkgGraph is already loaded; loading Revise now will have no effect. + Fix by restarting Julia.""" +end + +using Revise +using PkgGraph + +Pkg.activate(testdir) diff --git a/test/integration.jl b/test/integration.jl deleted file mode 100644 index bd60773..0000000 --- a/test/integration.jl +++ /dev/null @@ -1,73 +0,0 @@ -using PkgGraph -using PkgGraph.Internals -using Test - - -@testset "end-user" begin - - @test isnothing(PkgGraph.open("Test", dryrun = true)) - @test isnothing(PkgGraph.create("Test", dryrun = true)) - @test isnothing(PkgGraph.create("PyPlot", dryrun = true)) -end - - -@testset "svg" begin - - contents(file) = read(file, String) - - infile = joinpath(@__DIR__, "simple-dot-output.svg") - outfile = tempname() - SVG.add_darkmode(infile, outfile) - expected = joinpath(@__DIR__, "simple-dot-with-darkmode.svg") - @test contents(outfile) == contents(expected) -end - - -@testset "graphsjl" begin - - edges = PkgGraph.depgraph("Test") - nt = PkgGraph.as_graphsjl_input(edges) - @test nt.vertices == PkgGraph.vertices(edges) - @test nt.indexof("Base64") == PkgGraph.node_index(edges)("Base64") - @test nt.adjacency_matrix == PkgGraph.adjacency_matrix(edges) -end - - -@testset "deps-as-dot" begin - - @test to_dot_str(:TOML, Options()) == - """ - digraph { - bgcolor = "transparent" - node [fillcolor="white", fontcolor="black", color="black"] - edge [color="black"] - node [fontname="sans-serif", style="filled"] - edge [arrowsize=0.88] - TOML -> Dates - Dates -> Printf - Printf -> Unicode - } - """ - - @test to_dot_str(:TOML, Options(style=[], mode=:dark, bg=:white)) == - """ - digraph { - bgcolor = "white" - node [fillcolor="black", fontcolor="white", color="white"] - edge [color="white"] - TOML -> Dates - Dates -> Printf - Printf -> Unicode - } - """ - - @test to_dot_str(:URIs, Options(style=[])) == - """ - digraph { - bgcolor = "transparent" - node [fillcolor="white", fontcolor="black", color="black"] - edge [color="black"] - onlynode [label=\" (URIs has no dependencies) \", shape=\"plaintext\"] - } - """ -end diff --git a/test/integration/all.jl b/test/integration/all.jl new file mode 100644 index 0000000..1784435 --- /dev/null +++ b/test/integration/all.jl @@ -0,0 +1,8 @@ + +using PkgGraph +using Test + +@testset "integration" begin + include("deps-as-dot.jl") + include("graphsjl_example.jl") +end diff --git a/test/integration/deps-as-dot.jl b/test/integration/deps-as-dot.jl new file mode 100644 index 0000000..58f121d --- /dev/null +++ b/test/integration/deps-as-dot.jl @@ -0,0 +1,41 @@ + +using PkgGraph: Options + +@testset "deps-as-dot" begin + + @test PkgGraph.to_dot_str(:TOML, Options()) == + """ + digraph { + bgcolor = "transparent" + node [fillcolor="white", fontcolor="black", color="black"] + edge [color="black"] + node [fontname="sans-serif", style="filled"] + edge [arrowsize=0.88] + TOML -> Dates + Dates -> Printf + Printf -> Unicode + } + """ + + @test PkgGraph.to_dot_str(:TOML, Options(style=[], mode=:dark, bg=:white)) == + """ + digraph { + bgcolor = "white" + node [fillcolor="black", fontcolor="white", color="white"] + edge [color="white"] + TOML -> Dates + Dates -> Printf + Printf -> Unicode + } + """ + + @test PkgGraph.to_dot_str(:URIs, Options(style=[])) == + """ + digraph { + bgcolor = "transparent" + node [fillcolor="white", fontcolor="black", color="black"] + edge [color="black"] + onlynode [label=\" (URIs has no dependencies) \", shape=\"plaintext\"] + } + """ +end diff --git a/test/graphsjl_example.jl b/test/integration/graphsjl_example.jl similarity index 100% rename from test/graphsjl_example.jl rename to test/integration/graphsjl_example.jl diff --git a/test/runtests.jl b/test/runtests.jl index e88cc73..49e712f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,15 +1,9 @@ + +using PkgGraph using Test @testset "PkgGraph.jl" verbose=true begin # `verbose`, so that timings are always shown - - @testset "unit" verbose=true begin - include("unit.jl") - end - @testset "integration" verbose=true begin - include("integration.jl") - end - @testset "Graphs.jl example" verbose=true begin - include("graphsjl_example.jl") - end + include("unit/all.jl") + include("integration/all.jl") end diff --git a/test/standalone/Project.toml b/test/standalone/Project.toml new file mode 100644 index 0000000..bc51ae6 --- /dev/null +++ b/test/standalone/Project.toml @@ -0,0 +1,3 @@ +[deps] +PkgGraph = "f9c1b9e4-72e8-4a14-ade5-14f45fc35f11" +Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" diff --git a/test/unit.jl b/test/unit.jl deleted file mode 100644 index 9a85c74..0000000 --- a/test/unit.jl +++ /dev/null @@ -1,94 +0,0 @@ -using PkgGraph -using PkgGraph.Internals -using Test - - -@testset "depgraph" begin - - @test depgraph("TOML") == [ - "TOML" => "Dates", - "Dates" => "Printf", - "Printf" => "Unicode" - ] - - if VERSION ≥ v"1.8" # Julia v1.7 does not support error string matching - @test_throws( - "Package `DinnaeExist` not found", - depgraph("DinnaeExist") - ) - end - - @test !is_jll("TOML") - @test is_in_stdlib("TOML") - @test !is_jll("Graphs") - @test !is_in_stdlib("Graphs") - @test is_jll("LibUV_jll") - @test is_in_stdlib("LibUV_jll") - - @test should_be_included("LibUV_jll") - @test !should_be_included("LibUV_jll", include_stdlib = false) - @test !should_be_included("LibUV_jll", include_jll = false) - @test !should_be_included("TOML", include_stdlib = false) - @test should_be_included("TOML", include_jll = false) - - @test depgraph("Graphs"; jll = false, stdlib = false) == [ - "Graphs" => "ArnoldiMethod" - "ArnoldiMethod" => "StaticArrays" - "StaticArrays" => "StaticArraysCore" - "Graphs" => "Compat" - "Graphs" => "DataStructures" - "DataStructures" => "Compat" - "DataStructures" => "OrderedCollections" - "Graphs" => "Inflate" - "Graphs" => "SimpleTraits" - "SimpleTraits" => "MacroTools" - ] -end - - - -@testset "dot" begin - - edges = [:A => :B, "yes" => "no"]; - - style = ["node [color=\"red\"]"]; - - @test to_dot_str(edges; style, bg=:blue, indent = 2) == - """ - digraph { - bgcolor = "blue" - node [fillcolor="white", fontcolor="black", color="black"] - edge [color="black"] - node [color="red"] - A -> B - yes -> no - } - """ - - @test to_dot_str([], mode=:dark, style=[], emptymsg="(empty graph)") == - """ - digraph { - bgcolor = "transparent" - node [fillcolor="black", fontcolor="white", color="white"] - edge [color="white"] - onlynode [label=\" (empty graph) \", shape=\"plaintext\"] - } - """ -end - - -@testset "urls" begin - - base = PkgGraph.webapps[2] - @test PkgGraph.url("digraph {Here->There}", base) == - "http://magjac.com/graphviz-visual-editor/?dot=digraph%20%7BHere-%3EThere%7D" -end - - -@testset "local" begin - - @test is_dot_available() isa Bool - - @test output_path(:Test, ".", :svg) == joinpath(".", "Test-deps.svg") - @test dotcommand(:png, "infile", "outfile") == `dot -Tpng -ooutfile infile` -end diff --git a/test/unit/DepGraph.jl b/test/unit/DepGraph.jl new file mode 100644 index 0000000..023e4bb --- /dev/null +++ b/test/unit/DepGraph.jl @@ -0,0 +1,64 @@ + +using PkgGraph +using Test + +@testset "DepGraph" begin + + @test PkgGraph.depgraph("TOML") == [ + "TOML" => "Dates", + "Dates" => "Printf", + "Printf" => "Unicode" + ] + + if VERSION ≥ v"1.8" # Julia v1.7 does not support error string matching + @test_throws( + "Package `DinnaeExist` not found", + PkgGraph.depgraph("DinnaeExist") + ) + end + + @testset "jll & stdlib exclusion" begin + + using PkgGraph: is_jll, is_in_stdlib, should_be_included + + @test !is_jll("TOML") + @test is_in_stdlib("TOML") + @test !is_jll("Graphs") + @test !is_in_stdlib("Graphs") + @test is_jll("LibUV_jll") + @test is_in_stdlib("LibUV_jll") + + @test should_be_included("LibUV_jll") + @test !should_be_included("LibUV_jll", include_stdlib = false) + @test !should_be_included("LibUV_jll", include_jll = false) + @test !should_be_included("TOML", include_stdlib = false) + @test should_be_included("TOML", include_jll = false) + + # User might run with proj `test` active (`] test`), or project `PkgGraph` (`include("..")`) + # The latter does not have Graphs in its manifest; so it comes from registry, and there + # deps have different order (also on julia 1.6 there's no registry querying). + # Heeence, why `../standalone` exists. + @test PkgGraph.depgraph("Graphs"; jll = false, stdlib = false) == [ + "Graphs" => "ArnoldiMethod" + "ArnoldiMethod" => "StaticArrays" + "StaticArrays" => "StaticArraysCore" + "Graphs" => "Compat" + "Graphs" => "DataStructures" + "DataStructures" => "Compat" + "DataStructures" => "OrderedCollections" + "Graphs" => "Inflate" + "Graphs" => "SimpleTraits" + "SimpleTraits" => "MacroTools" + ] + end + + + @testset "Graphs.jl export" begin + + edges = PkgGraph.depgraph("Test") + nt = PkgGraph.as_graphsjl_input(edges) + @test nt.vertices == PkgGraph.vertices(edges) + @test nt.indexof("Base64") == PkgGraph.node_index(edges)("Base64") + @test nt.adjacency_matrix == PkgGraph.adjacency_matrix(edges) + end +end diff --git a/test/unit/DotString.jl b/test/unit/DotString.jl new file mode 100644 index 0000000..689b268 --- /dev/null +++ b/test/unit/DotString.jl @@ -0,0 +1,32 @@ + +using PkgGraph +using Test + +@testset "DotString" begin + + edges = [:A => :B, "yes" => "no"]; + + style = ["node [color=\"red\"]"]; + + @test PkgGraph.to_dot_str(edges; style, bg=:blue, indent = 2) == + """ + digraph { + bgcolor = "blue" + node [fillcolor="white", fontcolor="black", color="black"] + edge [color="black"] + node [color="red"] + A -> B + yes -> no + } + """ + + @test PkgGraph.to_dot_str([], mode=:dark, style=[], emptymsg="(empty graph)") == + """ + digraph { + bgcolor = "transparent" + node [fillcolor="black", fontcolor="white", color="white"] + edge [color="white"] + onlynode [label=\" (empty graph) \", shape=\"plaintext\"] + } + """ +end diff --git a/test/unit/LoadTime.jl b/test/unit/LoadTime.jl new file mode 100644 index 0000000..70f3493 --- /dev/null +++ b/test/unit/LoadTime.jl @@ -0,0 +1,7 @@ + +using PkgGraph +using Test + +@testset "LoadTime" begin + +end diff --git a/test/unit/PkgGraph.jl b/test/unit/PkgGraph.jl new file mode 100644 index 0000000..5d9a634 --- /dev/null +++ b/test/unit/PkgGraph.jl @@ -0,0 +1,30 @@ + +using PkgGraph +using Test + +@testset "PkgGraph" begin + + @testset "urls" begin + + base = PkgGraph.webapps[2] + @test PkgGraph.url("digraph {Here->There}", base) == + "http://magjac.com/graphviz-visual-editor/?dot=digraph%20%7BHere-%3EThere%7D" + end + + + @testset "local" begin + + @test PkgGraph.is_dot_available() isa Bool + + @test PkgGraph.output_path(:Test, ".", :svg) == joinpath(".", "Test-deps.svg") + @test PkgGraph.dotcommand(:png, "infile", "outfile") == `dot -Tpng -ooutfile infile` + end + + + @testset "end-user" begin + + @test isnothing(PkgGraph.open("Test", dryrun = true)) + @test isnothing(PkgGraph.create("Test", dryrun = true)) + @test isnothing(PkgGraph.create("PyPlot", dryrun = true)) + end +end diff --git a/test/unit/SVG.jl b/test/unit/SVG.jl new file mode 100644 index 0000000..966376e --- /dev/null +++ b/test/unit/SVG.jl @@ -0,0 +1,16 @@ + +using PkgGraph +using Test + +@testset "SVG" begin + + contents(file) = read(file, String) + + infile = joinpath(@__DIR__, "svg", "simple-dot-output.svg") + expected = joinpath(@__DIR__, "svg", "simple-dot-with-darkmode.svg") + outfile = tempname() + + PkgGraph.SVG.add_darkmode(infile, outfile) + + @test contents(outfile) == contents(expected) +end diff --git a/test/unit/all.jl b/test/unit/all.jl new file mode 100644 index 0000000..b502230 --- /dev/null +++ b/test/unit/all.jl @@ -0,0 +1,13 @@ + +using PkgGraph +using Test + +@testset "unit" verbose=true begin + include("DepGraph.jl") + include("DotString.jl") + include("LoadTime.jl") + include("SVG.jl") + include("PkgGraph.jl") +end + +nothing # To not print big "Test.DefaultTestSet(…)" diff --git a/test/simple-dot-output.svg b/test/unit/svg/simple-dot-output.svg similarity index 100% rename from test/simple-dot-output.svg rename to test/unit/svg/simple-dot-output.svg diff --git a/test/simple-dot-with-darkmode.svg b/test/unit/svg/simple-dot-with-darkmode.svg similarity index 100% rename from test/simple-dot-with-darkmode.svg rename to test/unit/svg/simple-dot-with-darkmode.svg