forked from haskell/cabal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testsuite: Add a test for haskell#9334 (attempt 2)
Issue haskell#9334 identifies that `getScriptHash` can return invalid filepaths on certain platforms. This randomised test attempts to check that the filepaths it returns are valid. I have verified that this test readily fails on linux (when the logic about removing `/` is removed from ScriptUtils).
- Loading branch information
1 parent
324d6c9
commit 98cf4a5
Showing
4 changed files
with
52 additions
and
1 deletion.
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
37 changes: 37 additions & 0 deletions
37
cabal-install/tests/UnitTests/Distribution/Client/ScriptUtils.hs
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,37 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module UnitTests.Distribution.Client.ScriptUtils (tests) where | ||
|
||
import Distribution.Client.ScriptUtils | ||
import Distribution.Client.Config | ||
import Test.Tasty | ||
import Test.Tasty.QuickCheck | ||
import Test.QuickCheck.Instances.Cabal | ||
import System.FilePath | ||
|
||
tests :: [TestTree] | ||
tests = | ||
[ testGroup | ||
"ScriptUtils" | ||
[ testProperty "valid_script_path" testScriptPath | ||
] | ||
] | ||
|
||
-- ------------------------------------------------------------ | ||
|
||
-- * Unit tests | ||
|
||
-- ------------------------------------------------------------ | ||
|
||
testScriptPath :: ShortPath -> Property | ||
testScriptPath (ShortPath p) = withMaxSuccess 10000 $ ioProperty $ do | ||
hashed_path <- getScriptCacheDirectory p | ||
script_build_dir <- defaultScriptBuildsDir | ||
return $ and | ||
-- 1. Is it a valid path at all | ||
[ isValid hashed_path | ||
-- 2. Is the computed hashed path in the expected directory? | ||
, (script_build_dir </> takeFileName hashed_path) `equalFilePath` hashed_path | ||
] | ||
|