-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
pkg.jl
284 lines (257 loc) · 9.62 KB
/
pkg.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# This file is a part of Julia. License is MIT: http://julialang.org/license
import Base.Pkg.PkgError
function temp_pkg_dir(fn::Function, remove_tmp_dir::Bool=true)
# Used in tests below to setup and teardown a sandboxed package directory
const tmpdir = ENV["JULIA_PKGDIR"] = joinpath(tempdir(),randstring())
@test !isdir(Pkg.dir())
try
Pkg.init()
@test isdir(Pkg.dir())
Pkg.resolve()
fn()
finally
remove_tmp_dir && rm(tmpdir, recursive=true)
end
end
# Test basic operations: adding or removing a package, status, free
#Also test for the existence of REQUIRE and META_Branch
temp_pkg_dir() do
@test isfile(joinpath(Pkg.dir(),"REQUIRE"))
@test isfile(joinpath(Pkg.dir(),"META_BRANCH"))
@test isempty(Pkg.installed())
@test sprint(io -> Pkg.status(io)) == "No packages installed\n"
@test !isempty(Pkg.available())
@test_throws PkgError Pkg.installed("MyFakePackage")
@test Pkg.installed("Example") == nothing
# check that versioninfo(io, true) doesn't error and produces some output
# (done here since it calls Pkg.status which might error or clone metadata)
buf = PipeBuffer()
versioninfo(buf, true)
ver = readstring(buf)
@test startswith(ver, "Julia Version $VERSION")
@test contains(ver, "Environment:")
# Check that setprotocol! works.
begin
try
Pkg.setprotocol!("notarealprotocol")
Pkg.add("Example")
error("unexpected")
catch ex
if isa(ex, CompositeException)
ex = ex.exceptions[1]
if isa(ex, CapturedException)
ex = ex.ex
end
end
@test isa(ex,Pkg.PkgError)
@test contains(ex.msg, "Cannot clone Example from notarealprotocol://github.com/JuliaLang/Example.jl.git")
end
end
Pkg.setprotocol!("")
@test Pkg.Cache.rewrite_url_to == nothing
Pkg.setprotocol!("https")
Pkg.add("Example")
@test [keys(Pkg.installed())...] == ["Example"]
iob = IOBuffer()
Pkg.checkout("Example")
Pkg.status("Example", iob)
str = chomp(takebuf_string(iob))
@test startswith(str, " - Example")
@test endswith(str, "master")
Pkg.free("Example")
Pkg.status("Example", iob)
str = chomp(takebuf_string(iob))
@test endswith(str, string(Pkg.installed("Example")))
Pkg.checkout("Example")
Pkg.free(("Example",))
Pkg.status("Example", iob)
str = chomp(takebuf_string(iob))
@test endswith(str, string(Pkg.installed("Example")))
Pkg.rm("Example")
@test isempty(Pkg.installed())
@test !isempty(Pkg.available("Example"))
@test !in("Example", keys(Pkg.installed()))
Pkg.rm("Example")
@test isempty(Pkg.installed())
@test !isempty(Pkg.available("Example"))
@test !in("Example", keys(Pkg.installed()))
Pkg.clone("https://github.com/JuliaLang/Example.jl.git")
@test [keys(Pkg.installed())...] == ["Example"]
Pkg.status("Example", iob)
str = chomp(takebuf_string(iob))
@test startswith(str, " - Example")
@test endswith(str, "master")
Pkg.free("Example")
Pkg.status("Example", iob)
str = chomp(takebuf_string(iob))
@test endswith(str, string(Pkg.installed("Example")))
Pkg.checkout("Example")
Pkg.free(("Example",))
Pkg.status("Example", iob)
str = chomp(takebuf_string(iob))
@test endswith(str, string(Pkg.installed("Example")))
@test isempty(Pkg.dependents("Example"))
# adding a package with unsatisfiable julia version requirements (REPL.jl) errors
try
Pkg.add("REPL")
error("unexpected")
catch err
@test isa(err.exceptions[1].ex, PkgError)
@test err.exceptions[1].ex.msg == "REPL can't be installed because " *
"it has no versions that support $VERSION of julia. You may " *
"need to update METADATA by running `Pkg.update()`"
end
# trying to add, check availability, or pin a nonexistent package errors
try
Pkg.add("NonexistentPackage")
error("unexpected")
catch err
@test isa(err.exceptions[1].ex, PkgError)
@test err.exceptions[1].ex.msg == "unknown package NonexistentPackage"
end
try
Pkg.available("NonexistentPackage")
error("unexpected")
catch err
@test isa(err, PkgError)
@test err.msg == "NonexistentPackage is not a package (not registered or installed)"
end
try
Pkg.pin("NonexistentPackage", v"1.0.0")
error("unexpected")
catch err
@test isa(err, PkgError)
@test err.msg == "NonexistentPackage is not a git repo"
end
# trying to pin a git repo under Pkg.dir that is not an installed package errors
try
Pkg.pin("METADATA", v"1.0.0")
error("unexpected")
catch err
@test isa(err, PkgError)
@test err.msg == "METADATA cannot be pinned – not an installed package"
end
# trying to pin an installed, registered package to an unregistered version errors
try
Pkg.pin("Example", v"2147483647.0.0")
error("unexpected")
catch err
@test isa(err, PkgError)
@test err.msg == "Example – 2147483647.0.0 is not a registered version"
end
# PR #13572, handling of versions with untagged detached heads
LibGit2.with(LibGit2.GitRepo, Pkg.dir("Example")) do repo
LibGit2.checkout!(repo, "72f09c7d0099793378c645929a9961155faae6d2")
end
@test Pkg.installed()["Example"] > v"0.0.0"
# issue #13583
begin
try
Pkg.test("IDoNotExist")
error("unexpected")
catch ex
@test isa(ex,Pkg.PkgError)
@test ex.msg == "IDoNotExist is not an installed package"
end
try
Pkg.test("IDoNotExist1", "IDoNotExist2")
error("unexpected")
catch ex
@test isa(ex,Pkg.PkgError)
@test ex.msg == "IDoNotExist1 and IDoNotExist2 are not installed packages"
end
end
begin
Pkg.pin("Example")
Pkg.free("Example")
Pkg.pin("Example", v"0.4.0")
Pkg.update()
Pkg.installed()["Example"] == v"0.4.0"
end
# add a directory that is not a git repository
begin
mkdir(joinpath(Pkg.dir(), "NOTGIT"))
Pkg.installed("NOTGIT") == typemin(VersionNumber)
Pkg.installed()["NOTGIT"] == typemin(VersionNumber)
end
begin
# don't bork when a Pkg repo is bare, issue #13804
pth = joinpath(Pkg.dir(), "BAREGIT")
mkdir(pth)
# create a bare repo (isbare = true)
repo = LibGit2.init(pth, true)
@test repo.ptr != C_NULL
finalize(repo)
Pkg.update()
end
#test PkgDev redirects
begin
try
Pkg.register("IDoNotExist")
error("unexpected")
catch ex
@test ex.msg == "Pkg.register(pkg,[url]) has been moved to the package PkgDev.jl.\nRun Pkg.add(\"PkgDev\") to install PkgDev on Julia v0.5-"
end
try
Pkg.tag("IDoNotExist")
error("unexpected")
catch ex
@test ex.msg == "Pkg.tag(pkg, [ver, [commit]]) has been moved to the package PkgDev.jl.\nRun Pkg.add(\"PkgDev\") to install PkgDev on Julia v0.5-"
end
try
Pkg.generate("IDoNotExist","MIT")
error("unexpected")
catch ex
@test ex.msg == "Pkg.generate(pkg, license) has been moved to the package PkgDev.jl.\nRun Pkg.add(\"PkgDev\") to install PkgDev on Julia v0.5-"
end
try
Pkg.publish()
error("unexpected")
catch ex
@test ex.msg == "Pkg.publish() has been moved to the package PkgDev.jl.\nRun Pkg.add(\"PkgDev\") to install PkgDev on Julia v0.5-"
end
try
Pkg.license()
error("unexpected")
catch ex
@test ex.msg == "Pkg.license([lic]) has been moved to the package PkgDev.jl.\nRun Pkg.add(\"PkgDev\") to install PkgDev on Julia v0.5-"
end
try
Pkg.submit("IDoNotExist")
error("unexpected")
catch ex
@test ex.msg == "Pkg.submit(pkg[, commit]) has been moved to the package PkgDev.jl.\nRun Pkg.add(\"PkgDev\") to install PkgDev on Julia v0.5-"
end
try
Pkg.submit("IDoNotExist", "nonexistentcommit")
error("unexpected")
catch ex
@test ex.msg == "Pkg.submit(pkg[, commit]) has been moved to the package PkgDev.jl.\nRun Pkg.add(\"PkgDev\") to install PkgDev on Julia v0.5-"
end
end
# Test Pkg.Read.url works
@test Pkg.Read.url("Example") == "git://github.com/JuliaLang/Example.jl.git"
# issue #15789, build failure warning are printed correctly.
# Also makes sure `Pkg.build()` works even for non-git repo
begin
pth = joinpath(Pkg.dir(), "BuildFail")
mkdir(pth)
depspath = joinpath(pth, "deps")
mkdir(depspath)
depsbuild = joinpath(depspath, "build.jl")
touch(depsbuild)
# Pkg.build works without the src directory now
# but it's probably fine to require it.
msg = readstring(`$(Base.julia_cmd()) -f -e 'redirect_stderr(STDOUT); Pkg.build("BuildFail")'`)
@test contains(msg, "Building BuildFail")
@test !contains(msg, "ERROR")
open(depsbuild, "w") do fd
println(fd, "error(\"Throw build error\")")
end
msg = readstring(`$(Base.julia_cmd()) -f -e 'redirect_stderr(STDOUT); Pkg.build("BuildFail")'`)
@test contains(msg, "Building BuildFail")
@test contains(msg, "ERROR")
@test contains(msg, "Pkg.build(\"BuildFail\")")
@test contains(msg, "Throw build error")
end
end