Skip to content

Commit

Permalink
Fix #29: use / in filepaths even under Windows
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
andreasabel committed Aug 3, 2023
1 parent 318cecd commit c15eb4d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,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
Expand All @@ -246,6 +246,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 =
Expand Down

0 comments on commit c15eb4d

Please sign in to comment.