@@ -6,6 +6,13 @@ using ZipFile
66
77@testset " DataCaches" begin
88
9+ # Redirect Base.DEPOT_PATH to a temporary directory for the entire test suite so
10+ # no test inadvertently creates files in the real production scratchspace.
11+ _test_fake_depot = mktempdir ()
12+ _test_orig_depot_path = copy (Base. DEPOT_PATH )
13+ empty! (Base. DEPOT_PATH )
14+ push! (Base. DEPOT_PATH , _test_fake_depot)
15+
916 @testset " DataCache construction" begin
1017 mktempdir () do dir
1118 c = DataCache (dir)
@@ -351,6 +358,12 @@ using ZipFile
351358 end
352359
353360 @testset " Scratch.jl integration" begin
361+ mktempdir () do _fake_depot
362+ _orig_depot_path = copy (Base. DEPOT_PATH )
363+ empty! (Base. DEPOT_PATH )
364+ push! (Base. DEPOT_PATH , _fake_depot)
365+ try
366+
354367 @testset " default store is in Julia depot scratchspaces" begin
355368 # When no env var is set, the default cache should live under the depot
356369 depot_scratch = joinpath (first (Base. DEPOT_PATH ), " scratchspaces" )
@@ -420,6 +433,12 @@ using ZipFile
420433 c2 = DataCache (:functional_test_store )
421434 @test c2[" named_entry" ] == [10 , 20 , 30 ]
422435 end
436+
437+ finally
438+ empty! (Base. DEPOT_PATH )
439+ append! (Base. DEPOT_PATH , _orig_depot_path)
440+ end
441+ end
423442 end
424443
425444 @testset " movecache!" begin
@@ -799,4 +818,9 @@ using ZipFile
799818
800819 include (" test_migrate_legacy_defaultcache.jl" )
801820
821+ # Restore the original depot path after all tests.
822+ empty! (Base. DEPOT_PATH )
823+ append! (Base. DEPOT_PATH , _test_orig_depot_path)
824+ rm (_test_fake_depot; recursive = true , force = true )
825+
802826end
0 commit comments