-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a unit test failing on windows due to illegal filename
Resolves #149
- Loading branch information
Showing
3 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-- | | ||
-- Copyright: © 2018-2020 IOHK | ||
-- License: Apache-2.0 | ||
-- | ||
-- File path related test utilities. | ||
|
||
module Test.Utils.FilePath | ||
( PathElement (..) | ||
) where | ||
|
||
import Prelude | ||
|
||
import System.FilePath.Windows | ||
( makeValid ) | ||
import Test.QuickCheck | ||
( Arbitrary (..), elements, listOf1, scale ) | ||
import Test.Utils.Windows | ||
( isWindows ) | ||
|
||
-- | A file or directory name. The 'Arbitrary' instance will generate values | ||
-- which are valid on Windows and POSIX. | ||
-- | ||
-- <https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file> | ||
newtype PathElement = PathElement FilePath deriving (Show, Eq) | ||
|
||
instance Arbitrary PathElement where | ||
arbitrary = PathElement . makeValid' <$> limitLen genName | ||
where | ||
genName = listOf1 (elements ['a'..'z']) | ||
limitLen = scale (max 250) | ||
|
||
makeValid' :: FilePath -> FilePath | ||
makeValid' = if isWindows then makeValid else id |