Skip to content

Commit 9391b09

Browse files
Adapt code to more recent Julia versions
1 parent 03f0d4d commit 9391b09

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

src/Curl/utils.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
if !@isdefined(contains)
2-
contains(haystack, needle) = occursin(needle, haystack)
3-
export contains
4-
end
5-
61
# basic C stuff
72

83
puts(s::Union{String,SubString{String}}) = ccall(:puts, Cint, (Ptr{Cchar},), s)

test/runtests.jl

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ include("setup.jl")
44
@testset "libcurl configuration" begin
55
julia = "$(VERSION.major).$(VERSION.minor)"
66
@test Curl.USER_AGENT == "curl/$(Curl.CURL_VERSION) julia/$julia"
7-
if VERSION > v"1.6-"
8-
@test Curl.SYSTEM_SSL == Sys.iswindows() | Sys.isapple()
9-
end
7+
@test Curl.SYSTEM_SSL == Sys.iswindows() | Sys.isapple()
108
end
119

1210
@testset "API coverage" begin
@@ -20,7 +18,7 @@ include("setup.jl")
2018
@test value == read(path, String)
2119
rm(path)
2220
# with headers
23-
path = download(url, headers=headers)
21+
path = download(url; headers)
2422
@test isfile(path)
2523
@test value == read(path, String)
2624
rm(path)
@@ -34,7 +32,7 @@ include("setup.jl")
3432
rm(path)
3533
# with headers
3634
@arg_test output begin
37-
@test output == download(url, output, headers=headers)
35+
@test output == download(url, output; headers)
3836
end
3937
@test isfile(path)
4038
@test value == read(path, String)
@@ -65,7 +63,7 @@ include("setup.jl")
6563
@testset "head request" begin
6664
url = server * "/image/jpeg"
6765
output = IOBuffer()
68-
resp = request(url; method="HEAD", output=output)
66+
resp = request(url; method="HEAD", output)
6967
@test resp isa Response
7068
@test resp.proto == "https"
7169
@test resp.status == 200
@@ -74,7 +72,7 @@ include("setup.jl")
7472

7573
# when we make a `GET` instead of a `HEAD`, we get a body with the content-length
7674
# returned from the `HEAD` request.
77-
resp = request(url; method="GET", output=output)
75+
resp = request(url; method="GET", output)
7876
bytes = take!(output)
7977
@test length(bytes) == len
8078
end
@@ -114,7 +112,7 @@ include("setup.jl")
114112
open(file) do io
115113
events = Pair{String,String}[]
116114
debug(type, msg) = push!(events, type => msg)
117-
resp, json = request_json(url, input=io, debug=debug, headers=headers)
115+
resp, json = request_json(url; input=io, debug, headers)
118116
@test json["url"] == url
119117
@test json["data"] == read(file, String)
120118
header_out(hdr::String) = any(events) do (type, msg)
@@ -172,7 +170,7 @@ include("setup.jl")
172170

173171
@testset "set headers" begin
174172
headers = ["Foo" => "123", "Header" => "VaLuE", "Empty" => ""]
175-
json = download_json(url, headers = headers)
173+
json = download_json(url; headers)
176174
for (key, value) in headers
177175
@test header(json["headers"], key) == value
178176
end
@@ -185,7 +183,7 @@ include("setup.jl")
185183
"Accept" => "application/tar"
186184
"User-Agent" => "MyUserAgent/1.0"
187185
]
188-
json = download_json(url, headers = headers)
186+
json = download_json(url; headers)
189187
@test header(json["headers"], "Accept") == "application/tar"
190188
@test header(json["headers"], "User-Agent") == "MyUserAgent/1.0"
191189
end
@@ -195,7 +193,7 @@ include("setup.jl")
195193
"Accept" => ""
196194
"User-Agent" => ""
197195
]
198-
json = download_json(url, headers = headers)
196+
json = download_json(url; headers)
199197
@test header(json["headers"], "Accept") == ""
200198
@test header(json["headers"], "User-Agent") == ""
201199
end
@@ -205,7 +203,7 @@ include("setup.jl")
205203
"Accept" => nothing
206204
"User-Agent" => nothing
207205
]
208-
json = download_json(url, headers = headers)
206+
json = download_json(url; headers)
209207
@test !("Accept" in keys(json["headers"]))
210208
@test !("User-Agent" in keys(json["headers"]))
211209
end
@@ -243,13 +241,13 @@ include("setup.jl")
243241

244242
# This url will redirect to /cookies, which echoes the set cookies as json
245243
set_cookie_url = "$server/cookies/set?k1=v1&k2=v2"
246-
cookies = download_json(set_cookie_url, downloader=downloader)
244+
cookies = download_json(set_cookie_url; downloader)
247245
@test get(cookies, "k1", "") == "v1"
248246
@test get(cookies, "k2", "") == "v2"
249247

250248
# As the handle is destroyed, subsequent requests have no cookies
251249
cookie_url = "$server/cookies"
252-
cookies = download_json(cookie_url, downloader=downloader)
250+
cookies = download_json(cookie_url; downloader)
253251
@test isempty(cookies)
254252
end
255253

@@ -299,7 +297,7 @@ include("setup.jl")
299297
downloader.easy_hook = (easy, info) ->
300298
Curl.setopt(easy, Curl.CURLOPT_NETRC_FILE, netrc)
301299

302-
resp = request(auth_url, throw=false, downloader=downloader)
300+
resp = request(auth_url; downloader, throw=false)
303301
@test resp isa Response
304302
@test resp.status == 200 # succesful authentication
305303

@@ -315,7 +313,7 @@ include("setup.jl")
315313
temp = download("file://$path")
316314
@test data == read(temp)
317315
output = IOBuffer()
318-
resp = request("file://$path", output = output)
316+
resp = request("file://$path"; output)
319317
@test resp isa Response
320318
@test resp.proto == "file"
321319
@test resp.status == 0
@@ -327,7 +325,7 @@ include("setup.jl")
327325
@test_throws RequestError download("file://$path")
328326
@test_throws RequestError request("file://$path")
329327
output = IOBuffer()
330-
resp = request("file://$path", output = output, throw = false)
328+
resp = request("file://$path"; output, throw = false)
331329
@test resp isa RequestError
332330
end
333331
end
@@ -404,7 +402,7 @@ include("setup.jl")
404402
url = "$server/delay/$delay"
405403
t = @elapsed @sync for id = 1:count
406404
@async begin
407-
json = download_json("$url?id=$id", downloader = downloader)
405+
json = download_json("$url?id=$id"; downloader)
408406
@test get(json["args"], "id", nothing) == ["$id"]
409407
end
410408
end
@@ -479,7 +477,7 @@ include("setup.jl")
479477
@testset "interrupt" begin
480478
url = "$server/delay/10"
481479
interrupt = Base.Event()
482-
download_task = @async request(url; interrupt=interrupt)
480+
download_task = @async request(url; interrupt)
483481
sleep(0.1)
484482
@test !istaskdone(download_task)
485483
notify(interrupt)
@@ -490,7 +488,7 @@ include("setup.jl")
490488
interrupt = Base.Event()
491489
url = "$server/put"
492490
input=`sh -c 'sleep 15; echo "hello"'`
493-
download_task = @async request(url; interrupt=interrupt, input=input)
491+
download_task = @async request(url; interrupt, input)
494492
sleep(0.1)
495493
@test !istaskdone(download_task)
496494
notify(interrupt)
@@ -505,7 +503,7 @@ include("setup.jl")
505503
dl_funcs = [
506504
download,
507505
(url; progress) ->
508-
request(url, output=devnull, progress=progress)
506+
request(url; progress, output=devnull)
509507
]
510508
p_funcs = [
511509
(prog...) -> push!(progress, prog),
@@ -553,7 +551,7 @@ include("setup.jl")
553551
downloader = Downloader()
554552
downloader.easy_hook = easy_hook
555553
for outer url in urls
556-
resp = request(url, throw=false, downloader=downloader)
554+
resp = request(url; downloader, throw=false)
557555
@test resp isa Response
558556
@test resp.status == 200
559557
end

test/setup.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end
2121
function request_body(url::AbstractString; kwargs...)
2222
resp = nothing
2323
body = sprint() do output
24-
resp = request(url; output=output, kwargs...)
24+
resp = request(url; output, kwargs...)
2525
end
2626
return resp, body
2727
end

0 commit comments

Comments
 (0)