Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add showFullInstalledPackageInfo #4979

Merged
merged 2 commits into from
Dec 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Cabal/Distribution/InstalledPackageInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module Distribution.InstalledPackageInfo (
emptyInstalledPackageInfo,
parseInstalledPackageInfo,
showInstalledPackageInfo,
showFullInstalledPackageInfo,
showInstalledPackageInfoField,
showSimpleInstalledPackageInfoField,
fieldsInstalledPackageInfo,
Expand Down Expand Up @@ -359,8 +360,16 @@ parseInstalledPackageInfo =
-- -----------------------------------------------------------------------------
-- Pretty-printing

-- | Pretty print 'InstalledPackageInfo'.
--
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/it' s/it/

-- @pkgRoot@ isn't printed, as ghc-pkg prints it's manually (as GHC-8.4).
showInstalledPackageInfo :: InstalledPackageInfo -> String
showInstalledPackageInfo = showFields fieldsInstalledPackageInfo
showInstalledPackageInfo ipi =
showFullInstalledPackageInfo ipi { pkgRoot = Nothing }

-- | The variant of 'showInstalledPackageInfo' which outputs @pkgroot@ field too.
showFullInstalledPackageInfo :: InstalledPackageInfo -> String
showFullInstalledPackageInfo = showFields fieldsInstalledPackageInfo

showInstalledPackageInfoField :: String -> Maybe (InstalledPackageInfo -> String)
showInstalledPackageInfoField = showSingleNamedField fieldsInstalledPackageInfo
Expand Down Expand Up @@ -505,8 +514,8 @@ installedFieldDescrs = [
showFilePath parseFilePathQ
haddockHTMLs (\xs pkg -> pkg{haddockHTMLs=xs})
, simpleField "pkgroot"
(const Disp.empty) parseFilePathQ
(fromMaybe "" . pkgRoot) (\xs pkg -> pkg{pkgRoot=Just xs})
(maybe mempty showFilePath) (fmap Just parseFilePathQ)
pkgRoot (\xs pkg -> pkg{pkgRoot=xs})
]

deprecatedFieldDescrs :: [FieldDescr InstalledPackageInfo]
Expand Down
14 changes: 10 additions & 4 deletions Cabal/tests/ParserTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Test.Tasty.HUnit

import Control.Monad (void)
import Data.Algorithm.Diff (Diff (..), getGroupedDiff)
import Data.Maybe (isJust)
import Data.Maybe (isJust, isNothing)
import Distribution.License (License (..))
import Distribution.PackageDescription (GenericPackageDescription)
import Distribution.PackageDescription.Parsec (parseGenericPackageDescription)
Expand Down Expand Up @@ -205,11 +205,17 @@ ipiFormatRoundTripTest fp = testCase "roundtrip" $ do
let contents' = IPI.showInstalledPackageInfo x
y <- parse contents'

-- TODO: pkgRoot doesn't seem to be shown!
-- ghc-pkg prints pkgroot itself, based on cli arguments!
let x' = x { IPI.pkgRoot = Nothing }
let y' = y { IPI.pkgRoot = Nothing }

let y' = y
assertBool "pkgRoot isn't shown" (isNothing (IPI.pkgRoot y))
assertEqual "re-parsed doesn't match" x' y'

-- Complete round-trip
let contents2 = IPI.showFullInstalledPackageInfo x
z <- parse contents2
assertEqual "re-parsed doesn't match" x z

where
parse :: String -> IO IPI.InstalledPackageInfo
parse c = do
Expand Down