@@ -516,23 +516,45 @@ runWithLockInTempDir tree act = withLock lockForTempDirs $ do
516
516
cleanupTempDir <- lookupEnv " HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP"
517
517
let runTestInDir action = case cleanupTempDir of
518
518
Just val | val /= " 0" -> do
519
- (tempDir, _) <- newTempDirWithin testRoot
520
- a <- action tempDir
519
+ (tempDir, cacheHome, _) <- setupTemporaryTestDirectories testRoot
520
+ a <- withTempCacheHome cacheHome ( action tempDir)
521
521
logWith helperRecorder Debug LogNoCleanup
522
522
pure a
523
523
524
524
_ -> do
525
- (tempDir, cleanup) <- newTempDirWithin testRoot
526
- a <- action tempDir `finally` cleanup
525
+ (tempDir, cacheHome, cleanup) <- setupTemporaryTestDirectories testRoot
526
+ a <- withTempCacheHome cacheHome ( action tempDir) `finally` cleanup
527
527
logWith helperRecorder Debug LogCleanup
528
528
pure a
529
529
runTestInDir $ \ tmpDir' -> do
530
530
-- we canonicalize the path, so that we do not need to do
531
- -- cannibalization during the test when we compare two paths
531
+ -- canonicalization during the test when we compare two paths
532
532
tmpDir <- canonicalizePath tmpDir'
533
533
logWith helperRecorder Info $ LogTestDir tmpDir
534
534
fs <- FS. materialiseVFT tmpDir tree
535
535
act fs
536
+ where
537
+ cache_home_var = " XDG_CACHE_HOME"
538
+ -- Set the dir for "XDG_CACHE_HOME".
539
+ -- When the operation finished, make sure the old value is restored.
540
+ withTempCacheHome tempCacheHomeDir act =
541
+ bracket
542
+ (do
543
+ old_cache_home <- lookupEnv cache_home_var
544
+ setEnv cache_home_var tempCacheHomeDir
545
+ pure old_cache_home)
546
+ (\ old_cache_home ->
547
+ maybe (pure () ) (setEnv cache_home_var) old_cache_home
548
+ )
549
+ (\ _ -> act)
550
+
551
+ -- Set up a temporary directory for the test files and one for the 'XDG_CACHE_HOME'.
552
+ -- The 'XDG_CACHE_HOME' is important for independent test runs, i.e. completely empty
553
+ -- caches.
554
+ setupTemporaryTestDirectories testRoot = do
555
+ (tempTestCaseDir, cleanup1) <- newTempDirWithin testRoot
556
+ (tempCacheHomeDir, cleanup2) <- newTempDirWithin testRoot
557
+ pure (tempTestCaseDir, tempCacheHomeDir, cleanup1 >> cleanup2)
536
558
537
559
runSessionWithServer :: Pretty b => Config -> PluginTestDescriptor b -> FilePath -> Session a -> IO a
538
560
runSessionWithServer config plugin fp act =
0 commit comments