|
1 | 1 | # This file is a part of Julia. License is MIT: https://julialang.org/license |
2 | 2 |
|
3 | | -# Test that `Base.download_url()` is altered by `Base.DOWNLOAD_HOOKS`. |
4 | | -let urls = ["http://httpbin.julialang.org/ip", "https://httpbin.julialang.org/ip"] |
5 | | - for url in urls |
6 | | - @test Base.download_url(url) == url |
7 | | - end |
8 | | - push!(Base.DOWNLOAD_HOOKS, url->replace(url, r"^http://" => "https://")) |
9 | | - for url in urls |
10 | | - @test Base.download_url(url) == urls[end] |
11 | | - end |
12 | | - pop!(Base.DOWNLOAD_HOOKS) |
13 | | - for url in urls |
14 | | - @test Base.download_url(url) == url |
15 | | - end |
16 | | -end |
17 | | - |
18 | | -mktempdir() do temp_dir |
19 | | - # Download a file |
20 | | - file = joinpath(temp_dir, "ip") |
21 | | - @test download("https://httpbin.julialang.org/ip", file) == file |
22 | | - @test isfile(file) |
23 | | - @test !isempty(read(file)) |
24 | | - ip = read(file, String) |
25 | | - |
26 | | - # Test download rewrite hook |
27 | | - push!(Base.DOWNLOAD_HOOKS, url->replace(url, r"/status/404$" => "/ip")) |
28 | | - @test download("https://httpbin.julialang.org/status/404", file) == file |
29 | | - @test isfile(file) |
30 | | - @test !isempty(read(file)) |
31 | | - @test ip == read(file, String) |
32 | | - pop!(Base.DOWNLOAD_HOOKS) |
33 | | - |
34 | | - # Download an empty file |
35 | | - empty_file = joinpath(temp_dir, "empty") |
36 | | - @test download("https://httpbin.julialang.org/status/200", empty_file) == empty_file |
37 | | - |
38 | | - # Windows and older versions of curl do not create the empty file (https://github.com/curl/curl/issues/183) |
39 | | - @test !isfile(empty_file) || isempty(read(empty_file)) |
40 | | - |
41 | | - # Make sure that failed downloads do not leave files around |
42 | | - missing_file = joinpath(temp_dir, "missing") |
43 | | - @test_throws ErrorException download("https://httpbin.julialang.org/status/404", missing_file) |
44 | | - @test !isfile(missing_file) |
45 | | - |
46 | | - # Use a TEST-NET (192.0.2.0/24) address which shouldn't be bound |
47 | | - invalid_host_file = joinpath(temp_dir, "invalid_host") |
48 | | - @test_throws ErrorException download("http://192.0.2.1", invalid_host_file) |
49 | | - @test !isfile(invalid_host_file) |
| 3 | +cmd = `$(Base.julia_cmd()) --depwarn=no --startup-file=no download_exec.jl` |
| 4 | +if !success(pipeline(cmd; stdout=stdout, stderr=stderr)) |
| 5 | + error("download test failed, cmd : $cmd") |
50 | 6 | end |
0 commit comments