|
2 | 2 | import Base: SHA1
|
3 | 3 |
|
4 | 4 | using Artifacts, Test, Base.BinaryPlatforms
|
5 |
| -using Artifacts: with_artifacts_directory, pack_platform!, unpack_platform |
| 5 | +using Artifacts: with_artifacts_directory, pack_platform!, unpack_platform, load_overrides |
| 6 | +using TOML |
6 | 7 |
|
7 | 8 | # prepare for the package tests by ensuring the required artifacts are downloaded now
|
8 | 9 | artifacts_dir = mktempdir()
|
9 | 10 | run(addenv(`$(Base.julia_cmd()) --color=no $(joinpath(@__DIR__, "refresh_artifacts.jl")) $(artifacts_dir)`, "TERM"=>"dumb"))
|
10 | 11 |
|
| 12 | +@testset "Load Overrides" begin |
| 13 | + """ |
| 14 | + create_test_overrides_toml(temp_dir::String) |
| 15 | +
|
| 16 | + Create "Overrides.toml" in the given `temp_dir`. |
| 17 | + """ |
| 18 | + function create_test_overrides_toml(temp_dir::String) |
| 19 | + # Define the overrides |
| 20 | + overrides = Dict( |
| 21 | + "78f35e74ff113f02274ce60dab6e92b4546ef806" => "/path/to/replacement", |
| 22 | + "c76f8cda85f83a06d17de6c57aabf9e294eb2537" => "fb886e813a4aed4147d5979fcdf27457d20aa35d", |
| 23 | + "d57dbccd-ca19-4d82-b9b8-9d660942965b" => Dict( |
| 24 | + "c_simple" => "/path/to/c_simple_dir", |
| 25 | + "libfoo" => "fb886e813a4aed4147d5979fcdf27457d20aa35d" |
| 26 | + ) |
| 27 | + ) |
| 28 | + |
| 29 | + # Get the artifacts directory |
| 30 | + artifacts_dir = joinpath(temp_dir, "artifacts") |
| 31 | + |
| 32 | + # Ensure the artifacts directory exists |
| 33 | + isdir(artifacts_dir) || mkdir(artifacts_dir) |
| 34 | + |
| 35 | + # Get the path to the Overrides.toml file |
| 36 | + overrides_path = joinpath(artifacts_dir, "Overrides.toml") |
| 37 | + |
| 38 | + # Create the Overrides.toml file |
| 39 | + open(overrides_path, "w") do io |
| 40 | + TOML.print(io, overrides) |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + # Specify the expected test result when depot path does not exist or no overriding happened |
| 45 | + empty_output = Dict{Symbol, Any}( |
| 46 | + :UUID => Dict{Base.UUID, Dict{String, Union{SHA1, String}}}(), |
| 47 | + :hash => Dict{SHA1, Union{SHA1, String}}() |
| 48 | + ) |
| 49 | + |
| 50 | + # Specify the expected test result when overriding happened |
| 51 | + expected_output = Dict{Symbol, Any}( |
| 52 | + :UUID => Dict{Base.UUID, Dict{String, Union{SHA1, String}}}(Base.UUID("d57dbccd-ca19-4d82-b9b8-9d660942965b") => Dict("c_simple" => "/path/to/c_simple_dir", "libfoo" => SHA1("fb886e813a4aed4147d5979fcdf27457d20aa35d"))), |
| 53 | + :hash => Dict{SHA1, Union{SHA1, String}}(SHA1("78f35e74ff113f02274ce60dab6e92b4546ef806") => "/path/to/replacement", SHA1("c76f8cda85f83a06d17de6c57aabf9e294eb2537") => SHA1("fb886e813a4aed4147d5979fcdf27457d20aa35d")) |
| 54 | + ) |
| 55 | + |
| 56 | + # Test `load_overrides()` works with *no* "Overrides.toml" file |
| 57 | + @test load_overrides() == empty_output |
| 58 | + |
| 59 | + # Create a temporary directory |
| 60 | + mktempdir() do temp_dir |
| 61 | + # Back up the old `DEPOT_PATH`` |
| 62 | + old_depot_path = copy(Base.DEPOT_PATH) |
| 63 | + |
| 64 | + # Set `DEPOT_PATH` to that directory |
| 65 | + empty!(Base.DEPOT_PATH) |
| 66 | + push!(Base.DEPOT_PATH, temp_dir) |
| 67 | + |
| 68 | + try |
| 69 | + # Create "Overrides.toml" for the test |
| 70 | + create_test_overrides_toml(temp_dir) |
| 71 | + |
| 72 | + # Test `load_overrides()` works *with* "Overrides.toml" file but non-nothing ARTIFACT_OVERRIDES[] |
| 73 | + @test load_overrides() == empty_output |
| 74 | + |
| 75 | + # Test `load_overrides()` works *with* "Overrides.toml" file with force parameter, which overrides even when `ARTIFACT_OVERRIDES[] !== nothing`` |
| 76 | + @test load_overrides(force=true) == expected_output |
| 77 | + finally # Make sure `DEPOT_PATH` will be restored to the status quo in the event of a bug |
| 78 | + # Restore the old `DEPOT_PATH` to avoid messing with any other code |
| 79 | + empty!(Base.DEPOT_PATH) |
| 80 | + append!(Base.DEPOT_PATH, old_depot_path) |
| 81 | + end |
| 82 | + end |
| 83 | + # Temporary directory and test "Overrides.toml" file will be automatically deleted when out of scope |
| 84 | + # This means after this block, the system *should* behave like this test never happened. |
| 85 | + |
| 86 | + # Test the "Overrides.toml" file is cleared back to the status quo |
| 87 | + @test load_overrides(force=true) == empty_output |
| 88 | +end |
| 89 | + |
11 | 90 | @testset "Artifact Paths" begin
|
12 | 91 | mktempdir() do tempdir
|
13 | 92 | with_artifacts_directory(tempdir) do
|
|
0 commit comments