Skip to content

Commit aad06a4

Browse files
authored
CI: add downstream Plots test (#201)
1 parent 14aba95 commit aad06a4

File tree

4 files changed

+158
-6
lines changed

4 files changed

+158
-6
lines changed

test/Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
[deps]
22
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3+
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
34
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
5+
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
6+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
47
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
58
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
69

710
[compat]
811
Aqua = "0.8"
12+
Downloads = "1"
913
JET = "0.9 - 0.10"
14+
JSON = "1"
15+
Pkg = "1"
1016
Preferences = "1"
1117
Test = "1"

test/downstream.jl

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using Downloads, JSON, Test
2+
3+
function available_channels()
4+
juliaup = "https://julialang-s3.julialang.org/juliaup"
5+
for i 1:6
6+
buf = PipeBuffer()
7+
Downloads.download("$juliaup/DBVERSION", buf)
8+
dbversion = VersionNumber(readline(buf))
9+
dbversion.major == 1 || continue
10+
buf = PipeBuffer()
11+
Downloads.download(
12+
"$juliaup/versiondb/versiondb-$dbversion-x86_64-unknown-linux-gnu.json",
13+
buf,
14+
)
15+
json = JSON.parse(buf)
16+
haskey(json, "AvailableChannels") || continue
17+
return json["AvailableChannels"]
18+
sleep(10i)
19+
end
20+
return
21+
end
22+
23+
"""
24+
julia> is_latest(:lts)
25+
julia> is_latest(:release)
26+
"""
27+
function is_latest(variant)
28+
channels = available_channels()
29+
ver = let var::String = (
30+
release = "release",
31+
rel = "release",
32+
lts = "lts",
33+
release_candidate = "rc",
34+
alpha = "alpha",
35+
beta = "beta",
36+
rc = "rc",
37+
)[variant]
38+
VersionNumber(split(channels[var]["Version"], '+') |> first)
39+
end
40+
dev = occursin("DEV", string(VERSION)) # or length(VERSION.prerelease) < 2
41+
return !dev && (
42+
VersionNumber(ver.major, ver.minor, 0, ("",)) VERSION < VersionNumber(ver.major, ver.minor + 1)
43+
)
44+
end
45+
46+
(is_ci() && Sys.islinux() && is_latest(:release)) && @testset "downstream" begin
47+
tmpd = mktempdir()
48+
Plots_jl = joinpath(tmpd, "Plots.jl")
49+
@test Cmd(`$(Base.julia_cmd()) $(joinpath(@__DIR__, "downstream_dev.jl")) $tmpd`) |> run |> success
50+
script = tempname()
51+
write(
52+
script,
53+
"""
54+
using Pkg
55+
56+
Pkg.activate(joinpath("$Plots_jl", "PlotsBase"))
57+
Pkg.develop(path="$(joinpath(@__DIR__, ".."))")
58+
59+
import Gaston # trigger `PlotsBase` extension
60+
Pkg.status(["Gaston", "PlotsBase"])
61+
62+
# test basic plots creation and bitmap or vector exports
63+
using PlotsBase, Test
64+
65+
prefix = tempname()
66+
@time for i ∈ 1:length(PlotsBase._examples)
67+
i ∈ PlotsBase._backend_skips[:gaston] && continue # skip unsupported examples
68+
PlotsBase._examples[i].imports ≡ nothing || continue # skip examples requiring optional test deps
69+
pl = PlotsBase.test_examples(:gaston, i; disp = false)
70+
for ext in (".png", ".pdf") # TODO: maybe more ?
71+
fn = string(prefix, i, ext)
72+
PlotsBase.savefig(pl, fn)
73+
@test filesize(fn) > 1_000
74+
end
75+
end
76+
"""
77+
)
78+
@test Cmd(`$(Base.julia_cmd()) --project=@. $script`; dir = Plots_jl) |> run |> success
79+
end

test/downstream_dev.jl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Pkg
2+
3+
LibGit2 = Pkg.GitTools.LibGit2
4+
TOML = Pkg.TOML
5+
6+
failsafe_clone_checkout(path, url, pkg = nothing; stable = true) = begin
7+
local repo
8+
for i in 1:6
9+
try
10+
repo = Pkg.GitTools.ensure_clone(stdout, path, url)
11+
break
12+
catch err
13+
@warn err
14+
sleep(20i)
15+
end
16+
end
17+
18+
name, _ = splitext(basename(url))
19+
registries = joinpath(first(DEPOT_PATH), "registries")
20+
general = joinpath(registries, "General")
21+
versions = joinpath(general, name[1:1], name, "Versions.toml")
22+
if !isfile(versions)
23+
mkpath(general)
24+
run(setenv(`tar xf $general.tar.gz`; dir = general))
25+
end
26+
@assert isfile(versions)
27+
28+
if stable
29+
v_stable = maximum(VersionNumber.(keys(TOML.parse(read(versions, String)))))
30+
obj = LibGit2.GitObject(repo, "v$v_stable")
31+
hash = if isa(obj, LibGit2.GitTag)
32+
LibGit2.target(obj)
33+
else
34+
LibGit2.GitHash(obj)
35+
end |> string
36+
LibGit2.checkout!(repo, hash)
37+
end
38+
39+
toml = if pkg nothing && (fn = joinpath(path, pkg, "Project.toml")) |> isfile # monorepo layout
40+
fn
41+
elseif (fn = joinpath(path, "Project.toml")) |> isfile # single package toplevel
42+
fn
43+
end
44+
@assert isfile(toml) "$toml does not exist, bailing out !"
45+
toml
46+
end
47+
48+
fake_supported_version!(toml) = begin
49+
# fake the supported Gaston version for testing (for `Pkg.develop`)
50+
Gaston_version = Pkg.Types.read_package(normpath(@__DIR__, "..", "Project.toml")).version
51+
parsed_toml = TOML.parse(read(toml, String))
52+
parsed_toml["compat"]["Gaston"] = string(Gaston_version)
53+
open(toml, "w") do io
54+
TOML.print(io, parsed_toml)
55+
end
56+
nothing
57+
end
58+
59+
dn = joinpath(ARGS[1], "Plots.jl")
60+
toml = failsafe_clone_checkout(dn, "https://github.com/JuliaPlots/Plots.jl", "PlotsBase"; stable = false)
61+
docs = joinpath(dn, "docs")
62+
isdir(docs) && rm(docs; recursive=true) # ERROR: LoadError: empty intersection between Gaston@2.0.1 and project compatibility ∅
63+
fake_supported_version!(toml)

test/runtests.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ gh = Gaston.gethandles
1010
reset = Gaston.reset
1111
null() = Gaston.config.output = :null
1212

13+
is_pkgeval() = Base.get_bool_env("JULIA_PKGEVAL", false)
14+
is_ci() = Base.get_bool_env("CI", false)
15+
1316
@testset "Gnuplot version" begin
1417
@test Gaston.GNUPLOT_VERSION[] v"6"
1518
end
@@ -25,8 +28,8 @@ end
2528
end
2629

2730
@testset "AQUA" begin
28-
#Aqua.test_all(Gaston)
29-
#Aqua.test_ambiguities(Gaston) # disabled -- fails with ambiguities from StatsBase
31+
# Aqua.test_all(Gaston)
32+
# Aqua.test_ambiguities(Gaston) # disabled -- fails with ambiguities from StatsBase
3033
Aqua.test_unbound_args(Gaston)
3134
Aqua.test_undefined_exports(Gaston)
3235
Aqua.test_project_extras(Gaston)
@@ -94,9 +97,9 @@ end
9497
f4 = Figure()
9598
@test f4.handle == 1
9699
closeall()
97-
p1 = plot(1:10, handle = :a);
98-
p2 = plot(1:10, handle = :b);
99-
p3 = plot(1:10, handle = :c);
100+
p1 = plot(1:10, handle = :a)
101+
p2 = plot(1:10, handle = :b)
102+
p3 = plot(1:10, handle = :c)
100103
@test begin
101104
closefigure(:b)
102105
gh()
@@ -725,11 +728,12 @@ end
725728
if Gaston.state.enabled
726729
@test Gaston.gp_exec("set grid") == ""
727730
null()
728-
t = Gaston.terminals();
731+
t = Gaston.terminals()
729732
@test isnothing(t)
730733
end
731734
end
732735

733736
closeall()
734737

735738
include("preferences.jl")
739+
include("downstream.jl")

0 commit comments

Comments
 (0)