summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFraser Tweedale <frase@frase.id.au>2022-05-12 18:32:52 +1000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-05-26 06:14:51 -0400
commitafde42761f509a93a70e8997bd8bbf38e7b70209 (patch)
treeb5c0631963a67deb1b8ad740b376d05a5fd33ad0
parentb22979fb8d84efa21cc0b9dd56a8d9ef8e3693b6 (diff)
downloadhaskell-afde42761f509a93a70e8997bd8bbf38e7b70209.tar.gz
fix executablePath test for NetBSD
executablePath support for NetBSD was added in a172be07e3dce758a2325104a3a37fc8b1d20c9c, but the test was not updated. Update the test so that it works for NetBSD. This requires handling some quirks: - The result of getExecutablePath could include "./" segments. Therefore use System.FilePath.equalFilePath to compare paths. - The sysctl(2) call returns the original executable name even after it was deleted. Add `canQueryAfterDelete :: [FilePath]` and adjust expectations for the post-delete query accordingly. Also add a note to the `executablePath` haddock to advise that NetBSD behaves differently from other OSes when the file has been deleted. Also accept a decrease in memory usage for T16875. On Windows, the metric is -2.2% of baseline, just outside the allowed ±2%. I don't see how this commit could have influenced this metric, so I suppose it's something in the CI environment. Metric Decrease: T16875
-rw-r--r--libraries/base/System/Environment/ExecutablePath.hsc4
-rw-r--r--testsuite/tests/lib/base/executablePath.hs27
2 files changed, 23 insertions, 8 deletions
diff --git a/libraries/base/System/Environment/ExecutablePath.hsc b/libraries/base/System/Environment/ExecutablePath.hsc
index 923d61883c..1bee1122e8 100644
--- a/libraries/base/System/Environment/ExecutablePath.hsc
+++ b/libraries/base/System/Environment/ExecutablePath.hsc
@@ -102,6 +102,10 @@ getExecutablePath :: IO FilePath
-- Note that for scripts and interactive sessions, the result is the path to
-- the interpreter (e.g. ghci.)
--
+-- Note also that while most operating systems return @Nothing@ if the
+-- executable file was deleted/unlinked, some (including NetBSD) return the
+-- original path.
+--
-- @since 4.17.0.0
executablePath :: Maybe (IO (Maybe FilePath))
diff --git a/testsuite/tests/lib/base/executablePath.hs b/testsuite/tests/lib/base/executablePath.hs
index 180f423cc2..27758531a9 100644
--- a/testsuite/tests/lib/base/executablePath.hs
+++ b/testsuite/tests/lib/base/executablePath.hs
@@ -1,12 +1,14 @@
import Control.Monad (unless)
import System.Environment (executablePath, getArgs)
import System.Directory (removeFile, getCurrentDirectory)
-import System.FilePath ((</>), dropExtension)
+import System.FilePath ((</>), dropExtension, equalFilePath)
import System.Exit (exitSuccess, die)
-canQuery, canDelete :: [String]
-canQuery = ["mingw32", "freebsd", "linux", "darwin"]
-canDelete = ["freebsd", "linux", "darwin"]
+canQuery, canDelete, canQueryAfterDelete :: [String]
+canQuery = ["mingw32", "freebsd", "linux", "darwin", "netbsd"]
+canDelete = ["freebsd", "linux", "darwin", "netbsd"]
+canQueryAfterDelete = ["netbsd"]
+
main :: IO ()
main = do
@@ -33,7 +35,7 @@ main = do
-- (e.g. ".exe" on Windows). Drop the extension when comparing.
expected = cwd </> "executablePath"
actual = dropExtension before
- unless (actual == expected) $
+ unless (equalFilePath actual expected) $
die $ "executablePath query returned `" <> actual <> "`; expected `" <> expected <> "`"
unless (os `elem` canDelete)
@@ -44,7 +46,16 @@ main = do
-- Remove the file
removeFile before
- -- Now query should return Nothing
+ -- Now query again, after deletion
after <- query
- unless (after == Nothing) $ die $
- "executablePath expected to return Nothing, returned " <> show after
+ case after of
+ Nothing
+ | os `elem` canQueryAfterDelete
+ -> die "query failed after deletion, but expected success"
+ | otherwise
+ -> pure ()
+ Just _
+ | os `elem` canQueryAfterDelete
+ -> pure ()
+ | otherwise
+ -> die $ "query succeeded after deleted (result: " <> show after <> "), but expected failure"