From 3d5d5820bc42cbd6b05273ce2b43188012cccf6d Mon Sep 17 00:00:00 2001 From: jgotoh <18658140+jgotoh@users.noreply.github.com> Date: Mon, 3 Apr 2023 08:08:15 +0200 Subject: [PATCH] Add optional-packages test --- .../ProjectConfig/ParsecTests.hs | 22 +++++++++++++++---- .../files/optional-packages/cabal.project | 1 + .../files/packages/packages.project | 1 - 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 cabal-install/tests/IntegrationTests2/ProjectConfig/files/optional-packages/cabal.project delete mode 100644 cabal-install/tests/IntegrationTests2/ProjectConfig/files/packages/packages.project diff --git a/cabal-install/tests/IntegrationTests2/ProjectConfig/ParsecTests.hs b/cabal-install/tests/IntegrationTests2/ProjectConfig/ParsecTests.hs index 025093af37c..62a80fe03e1 100644 --- a/cabal-install/tests/IntegrationTests2/ProjectConfig/ParsecTests.hs +++ b/cabal-install/tests/IntegrationTests2/ProjectConfig/ParsecTests.hs @@ -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 @@ -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" @@ -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 diff --git a/cabal-install/tests/IntegrationTests2/ProjectConfig/files/optional-packages/cabal.project b/cabal-install/tests/IntegrationTests2/ProjectConfig/files/optional-packages/cabal.project new file mode 100644 index 00000000000..37e21016d6a --- /dev/null +++ b/cabal-install/tests/IntegrationTests2/ProjectConfig/files/optional-packages/cabal.project @@ -0,0 +1 @@ +optional-packages: . packages/packages.cabal diff --git a/cabal-install/tests/IntegrationTests2/ProjectConfig/files/packages/packages.project b/cabal-install/tests/IntegrationTests2/ProjectConfig/files/packages/packages.project deleted file mode 100644 index 6d9d4728a55..00000000000 --- a/cabal-install/tests/IntegrationTests2/ProjectConfig/files/packages/packages.project +++ /dev/null @@ -1 +0,0 @@ -packages: . packages/packages.cabal