|
| 1 | +import Test.Cabal.Prelude |
| 2 | +import System.Directory |
| 3 | + |
| 4 | +-- Test package-local extra-prog-path works. |
| 5 | +main = cabalTest $ do |
| 6 | + env <- getTestEnv |
| 7 | + let |
| 8 | + testDir = testCurrentDir env |
| 9 | + tmpDir = testTmpDir env |
| 10 | + scripts1 = tmpDir </> "scripts" |
| 11 | + scripts2 = tmpDir </> "scripts2" |
| 12 | + |
| 13 | + ------------------------- |
| 14 | + -- Workaround for the fact that, on Windows, Cabal will only look for |
| 15 | + -- .exe files to satisfy executable dependencs. So we have to create |
| 16 | + -- shim alex.exe files (the good one in 'scripts2', the bad one in 'scripts') |
| 17 | + -- with the logic below. |
| 18 | + when isWindows $ do |
| 19 | + mb_sh <- fmap takeDirectory <$> liftIO (findExecutable "sh") |
| 20 | + case mb_sh of |
| 21 | + Nothing -> skip "no sh" |
| 22 | + Just sh -> do |
| 23 | + let escape = concatMap (\c -> case c of '\\' -> "\\\\\\\\"; x -> [x]) |
| 24 | + void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> escape sh <> "/g", escape (scripts1 </> "alex.shim"), escape (scripts2 </> "alex.shim") ] |
| 25 | + void $ shell "sed" [ "-i", "-e", "s/SCRIPTSDIR/" <> escape scripts1 <> "/g", escape (scripts1 </> "alex.shim") ] |
| 26 | + void $ shell "sed" [ "-i", "-e", "s/SCRIPTS2DIR/" <> escape scripts2 <> "/g", escape (scripts2 </> "alex.shim") ] |
| 27 | + |
| 28 | + -- End of Windows workarounds |
| 29 | + ------------------------------ |
| 30 | + |
| 31 | + -- Add the 'scripts' directory to PATH, and add the 'scripts2' directory |
| 32 | + -- to extra-prog-path. |
| 33 | + -- |
| 34 | + -- This checks that the executables in extra-prog-path take priority over |
| 35 | + -- those in PATH: 'scripts/alex' will fail, while 'scripts2/alex' will succeed. |
| 36 | + |
| 37 | + liftIO $ appendFile (testDir </> "cabal.project") $ |
| 38 | + "\npackage client\n extra-prog-path:" ++ scripts2 |
| 39 | + addToPath scripts1 $ cabal "v2-build" ["client"] |
0 commit comments