summaryrefslogtreecommitdiff
path: root/testsuite/tests/lib
diff options
context:
space:
mode:
authorFraser Tweedale <frase@frase.id.au>2022-05-11 19:53:59 +1000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-05-26 06:14:51 -0400
commitb22979fb8d84efa21cc0b9dd56a8d9ef8e3693b6 (patch)
treef168ac458e0b7ababef4247c673bb4059d66e6bf /testsuite/tests/lib
parent3bd975b48d56815405da934a2331d9f9aa884ad7 (diff)
downloadhaskell-b22979fb8d84efa21cc0b9dd56a8d9ef8e3693b6.tar.gz
executablePath test: fix file extension treatment
The executablePath test strips the file extension (if any) when comparing the query result with the expected value. This is to handle platforms where GHC adds a file extension to the output program file (e.g. .exe on Windows). After the initial check, the file gets deleted (if supported). However, it tries to delete the *stripped* filename, which is incorrect. The test currently passes only because Windows does not allow deleting the program while any process created from it is alive. Make the test program correct in general by deleting the *non-stripped* executable filename.
Diffstat (limited to 'testsuite/tests/lib')
-rw-r--r--testsuite/tests/lib/base/executablePath.hs21
1 files changed, 11 insertions, 10 deletions
diff --git a/testsuite/tests/lib/base/executablePath.hs b/testsuite/tests/lib/base/executablePath.hs
index f60227e0ed..180f423cc2 100644
--- a/testsuite/tests/lib/base/executablePath.hs
+++ b/testsuite/tests/lib/base/executablePath.hs
@@ -10,8 +10,6 @@ canDelete = ["freebsd", "linux", "darwin"]
main :: IO ()
main = do
- cwd <- getCurrentDirectory
-
-- If executablePath = Nothing, then this platform
-- cannot return the executable path. So just exit
-- with a success value.
@@ -22,19 +20,22 @@ main = do
(True, Nothing) -> die "executablePath unexpected not defined"
(True, Just k) -> pure k
- -- At this point, the query should return the path to the
- -- test program. On some platforms this may have a file
- -- extension (e.g. ".exe" on Windows). Drop the extension
- -- and compare to the expected path.
- let expected = cwd </> "executablePath"
- before <- fmap (fmap dropExtension) query >>= \r -> case r of
+ -- At this point, the query should return the path to the test program.
+ before <- query >>= \r -> case r of
Nothing
-> die "executablePath query unexpected returned Nothing"
- Just path | path /= expected
- -> die $ "executablePath query returned `" <> path <> "`; expected `" <> expected <> "`"
Just path
-> pure path
+ cwd <- getCurrentDirectory
+ let
+ -- On some platforms the executable has a file extension
+ -- (e.g. ".exe" on Windows). Drop the extension when comparing.
+ expected = cwd </> "executablePath"
+ actual = dropExtension before
+ unless (actual == expected) $
+ die $ "executablePath query returned `" <> actual <> "`; expected `" <> expected <> "`"
+
unless (os `elem` canDelete)
-- This OS cannot delete the executable file while it is
-- still being executed. There is nothing left to test.