Skip to content

Commit

Permalink
Fix a unit test failing on windows due to illegal filename
Browse files Browse the repository at this point in the history
Resolves #149
  • Loading branch information
rvl committed Sep 18, 2020
1 parent efa96ce commit a570411
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import Test.QuickCheck
)
import Test.QuickCheck.Monadic
( assert, monadicIO, monitor, run )
import Test.Utils.FilePath
( PathElement (..) )
import Test.Utils.Paths
( getTestData )
import Test.Utils.StaticServer
Expand Down Expand Up @@ -362,11 +364,6 @@ instance Arbitrary PoolOwner where
arbitrary = PoolOwner . B8.pack <$> vectorOf 32 c
where c = elements ['a'..'z']

newtype PathElement = PathElement FilePath deriving (Show, Eq)

instance Arbitrary PathElement where
arbitrary = PathElement <$> listOf1 (elements ['a'..'z'])

{-------------------------------------------------------------------------------
Utils
-------------------------------------------------------------------------------}
Expand Down
1 change: 1 addition & 0 deletions lib/test-utils/cardano-wallet-test-utils.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ library
src
exposed-modules:
Test.Hspec.Extra
Test.Utils.FilePath
Test.Utils.Paths
Test.Utils.Roundtrip
Test.Utils.StaticServer
Expand Down
33 changes: 33 additions & 0 deletions lib/test-utils/src/Test/Utils/FilePath.hs
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

0 comments on commit a570411

Please sign in to comment.