From b55c1b623c8a53900b99ead410e3eedffd96f0b9 Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Mon, 21 Nov 2022 09:52:39 +0100 Subject: [PATCH] Fix #29: use / in filepaths even under Windows `System.FilePath.normalise` replaces slashes by backslashes. We implement a simplified version of `normalise` that does the opposite. This should make (relative) file path printed in test output more portable across OSs. --- src/Goldplate.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Goldplate.hs b/src/Goldplate.hs index 6b36484..cf2d409 100644 --- a/src/Goldplate.hs +++ b/src/Goldplate.hs @@ -230,7 +230,7 @@ specExecutions specPath spec = do inputFiles <- Dir.withCurrentDirectory workDirectory $ do matches <- globCurrentDir glob length matches `seq` return matches - return (map (Just . FP.normalise) inputFiles) + return (map (Just . normalise) inputFiles) -- Create an execution for every concrete input. forM concreteInputFiles $ \mbInputFile -> do @@ -257,6 +257,15 @@ specExecutions specPath spec = do hoistEither :: Either MissingEnvVar a -> IO a hoistEither = either throwIO return + -- A version of FP.normalise that uses slash as 'pathSeparator' even under Windows. + -- Drops "." directories in the path. + -- Should make test outputs that contain filepaths more portable. + -- Assumes that the argument is a file rather than a directory. + -- This frees us from corner cases such as "." and "./". + normalise :: FilePath -> FilePath + normalise = List.intercalate "/" . dropDots . FP.splitDirectories + where + dropDots = filter ("." /=) executionHeader :: Execution -> String executionHeader execution =