-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathruntests.jl
142 lines (130 loc) · 5.09 KB
/
runtests.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using ArtifactUtils, Pkg.Artifacts
using Base: SHA1
using Test
using TOML
import Pkg
import Git
function _artifact(name, loc)
eval(Expr(:macrocall, Symbol("@artifact_str"), LineNumberNode(1, Symbol(loc)), name))
end
expected_artifacts = Dict{String,Any}(
"JuliaMono" => Dict{String,Any}(
"git-tree-sha1" => "65279f9c8a3dd1e2cb654fdedbe8cd58889ae1bc",
"download" => Any[
Dict{String,Any}(
"sha256" => "f1ab65231cda7981531398644a58fd5fde8f367b681e1b8e9c35d9b2aacfcb1c",
"url" => "https://github.com/cormullion/juliamono/releases/download/v0.007/JuliaMono.tar.gz",
"size" => UInt64(5752883),
),
],
),
)
expected_artifacts_nosize = deepcopy(expected_artifacts)
delete!(expected_artifacts_nosize["JuliaMono"]["download"][1], "size")
@testset "ArtifactUtils.jl" begin
mktempdir() do tempdir
artifact_file = joinpath(tempdir, "Artifacts.toml")
add_artifact!(
artifact_file,
"JuliaMono",
"https://github.com/cormullion/juliamono/releases/download/v0.007/JuliaMono.tar.gz",
force=true,
)
artifacts = TOML.parsefile(artifact_file)
@test artifacts == expected_artifacts || artifacts == expected_artifacts_nosize
ensure_artifact_installed("JuliaMono", artifact_file)
@test ispath(_artifact("JuliaMono", tempdir))
hash = ArtifactUtils.sha256sum(joinpath(_artifact("JuliaMono", tempdir), "JuliaMono-Regular.ttf"))
@test hash == "dc0af40e8bc944a5d38c049b9a5b33e80b1e7a9621ac30fb440e5a2b6a4192d7"
end
end
@testset "add_artifact!(_, _, ::GistUploadResult)" begin
# Dummy `gist` result object
gist = ArtifactUtils.GistUploadResult(
SHA1("65279f9c8a3dd1e2cb654fdedbe8cd58889ae1bc"),
"JuliaMono.tar.gz",
"<localpath>",
"https://github.com/cormullion/juliamono/releases/download/v0.007/JuliaMono.tar.gz",
"f1ab65231cda7981531398644a58fd5fde8f367b681e1b8e9c35d9b2aacfcb1c",
UInt64(5752883),
false,
)
mktempdir() do tempdir
artifact_file = joinpath(tempdir, "Artifacts.toml")
add_artifact!(artifact_file, "JuliaMono", gist)
artifacts = TOML.parsefile(artifact_file)
@test artifacts == expected_artifacts || artifacts == expected_artifacts_nosize
end
str = sprint(show, "text/plain", gist)
@test occursin("upload_to_gist(", str)
@test occursin("; private = false)", str)
@test occursin("url =", str)
end
@testset "artifact_from_directory" begin
mktempdir() do tempdir
file = joinpath(tempdir, "hello.txt")
open(file, write = true) do io
println(io, "Hello, world.")
end
chmod(file, 0o644)
@test SHA1(Pkg.GitTools.tree_hash(tempdir)) ==
SHA1("0a890bd10328d68f6d85efd2535e3a4c588ee8e6")
@test artifact_from_directory(tempdir) ==
SHA1("0a890bd10328d68f6d85efd2535e3a4c588ee8e6")
chmod(file, 0o744) # user x bit matters
@test SHA1(Pkg.GitTools.tree_hash(tempdir)) ==
SHA1("952cfce0fb589c02736482fa75f9f9bb492242f8")
@test artifact_from_directory(tempdir) ==
SHA1("952cfce0fb589c02736482fa75f9f9bb492242f8")
end
end
# Hashes taken from:
# https://github.com/JuliaLang/Pkg.jl/blob/89286eac216164c43cc996f1f31a9fa1f1dacf87/test/new.jl#L2553-L2572
@testset "git_empty_history" begin
mktempdir() do git_dir
git(args) = run(`$(Git.git()) --no-pager -C $git_dir $args`)
git(`init`)
# Setup repository-local user name and email so that it works on CI
git(`config user.email "test@example.com"`)
git(`config user.name "tester"`)
git(`checkout -b new-branch`)
write(joinpath(git_dir, "file-1"), "content")
git(`add file-1`)
git(`commit --message "Add file-1"`)
history = strip(read(`git -C $git_dir --no-pager log`, String))
@test occursin("Add file-1", history)
ArtifactUtils.git_empty_history(git_dir)
@test !isfile("file-1")
branch =
strip(read(`git -C $git_dir --no-pager rev-parse --abbrev-ref HEAD`, String))
@test branch == "new-branch"
history = strip(read(`git -C $git_dir --no-pager log`, String))
@test !occursin("Add file-1", history)
end
end
@testset "open_atomic_write" begin
mktemp() do path, io
close(io)
ArtifactUtils.open_atomic_write(path) do io
println(io, "Hello, world.")
end
@test read(path, String) == "Hello, world.\n"
end
mktempdir() do tempdir
path = joinpath(tempdir, "hello.txt")
err = ErrorException("error from callback")
@test_throws err ArtifactUtils.open_atomic_write(path) do io
throw(err)
end
@test readdir(tempdir) == []
end
end
@testset "threaded_progress_foreach" begin
@testset for n in [10, 1000]
hits = zeros(Int, n)
ArtifactUtils.threaded_progress_foreach(eachindex(hits)) do i
hits[i] += 1
end
@test all(==(1), hits)
end
end