Skip to content

Commit

Permalink
Add optional-packages test
Browse files Browse the repository at this point in the history
  • Loading branch information
jgotoh committed Apr 3, 2023
1 parent 66a94a8 commit 3d5d582
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions cabal-install/tests/IntegrationTests2/ProjectConfig/ParsecTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ parserTests :: [TestTree]
parserTests = [
-- testCase "read with legacy parser" testLegacyRead
testCase "read packages" testPackages
, testCase "read optional-packages" testOptionalPackages
]

-- Currently I compare the results of legacy parser with the new parser
Expand Down Expand Up @@ -54,8 +55,13 @@ testPackages = do
-- Note that I currently also run the legacy parser to make sure my expected values
-- do not differ from the non-Parsec implementation, this will be removed in the future
(config, legacy) <- readConfigDefault "packages"
assertConfig expected config (projectPackages . condTreeData)
assertConfig expected legacy (projectPackages . condTreeData)
assertConfig expected config legacy (projectPackages . condTreeData)

testOptionalPackages :: Assertion
testOptionalPackages = do
let expected = [".", "packages/packages.cabal"]
(config, legacy) <- readConfigDefault "optional-packages"
assertConfig expected config legacy (projectPackagesOptional . condTreeData)

readConfigDefault :: FilePath -> IO (ProjectConfigSkeleton, ProjectConfigSkeleton)
readConfigDefault rootFp = readConfig rootFp "cabal.project"
Expand All @@ -79,10 +85,18 @@ readConfig rootFp projectFileName = do
readProjectFileSkeletonLegacy verbosity httpTransport distDirLayout extensionName extensionDescription
return (parsec, legacy)

assertConfig :: (Eq a, Show a) => a -> ProjectConfigSkeleton -> (ProjectConfigSkeleton -> a) -> IO ()
assertConfig expected config access = expected @=? actual
assertConfig' :: (Eq a, Show a) => a -> ProjectConfigSkeleton -> (ProjectConfigSkeleton -> a) -> IO ()
assertConfig' expected config access = expected @=? actual
where
actual = access config

assertConfig :: (Eq a, Show a) => a -> ProjectConfigSkeleton -> ProjectConfigSkeleton -> (ProjectConfigSkeleton -> a) -> IO ()
assertConfig expected config configLegacy access = do
expected @=? actualLegacy
expected @=? actual
where
actual = access config
actualLegacy = access configLegacy

-- | Test Utilities
emptyProjectConfig :: ProjectConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
optional-packages: . packages/packages.cabal

This file was deleted.

0 comments on commit 3d5d582

Please sign in to comment.