From e05566695067274d8317601ea5a6ae466dc65893 Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Wed, 14 Jul 2021 16:53:52 +0200 Subject: [PATCH] Removed dead constructor PreferHash The constructor PreferHash of GenerateHashStrategy is never used, removing it clarifies the logic to the reader of the code. --- src/Hpack.hs | 10 ++++++---- test/HpackSpec.hs | 5 ----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Hpack.hs b/src/Hpack.hs index e9676943..bdf10744 100644 --- a/src/Hpack.hs +++ b/src/Hpack.hs @@ -88,7 +88,10 @@ data Options = Options { , optionsOutputStrategy :: OutputStrategy } -data GenerateHashStrategy = ForceHash | ForceNoHash | PreferHash | PreferNoHash +data GenerateHashStrategy + = ForceHash -- ^ Option @--hash@ given. + | ForceNoHash -- ^ Option @--no-hash given. + | PreferNoHash -- ^ None of these option given, default behavior. deriving (Eq, Show) getOptions :: FilePath -> [String] -> IO (Maybe (Verbose, Options)) @@ -292,10 +295,9 @@ shouldGenerateHash :: Maybe ExistingCabalFile -> GenerateHashStrategy -> Bool shouldGenerateHash mExistingCabalFile strategy = case (strategy, mExistingCabalFile) of (ForceHash, _) -> True (ForceNoHash, _) -> False - (PreferHash, Nothing) -> True (PreferNoHash, Nothing) -> False - (_, Just CabalFile {cabalFileHash = Nothing}) -> False - (_, Just CabalFile {cabalFileHash = Just _}) -> True + (PreferNoHash, Just CabalFile {cabalFileHash = Nothing}) -> False + (PreferNoHash, Just CabalFile {cabalFileHash = Just _}) -> True renderCabalFile :: FilePath -> NewCabalFile -> [String] renderCabalFile file (CabalFile cabalVersion hpackVersion hash body _) = cabalVersion ++ header file hpackVersion hash ++ body diff --git a/test/HpackSpec.hs b/test/HpackSpec.hs index f2a4d109..fe974bd1 100644 --- a/test/HpackSpec.hs +++ b/test/HpackSpec.hs @@ -102,32 +102,27 @@ spec = do context "without an existing cabal file" $ do with ForceHash generatesHash - with PreferHash generatesHash with ForceNoHash doesNotGenerateHash with PreferNoHash doesNotGenerateHash context "with an existing cabal file" $ do context "without a hash" $ before_ (hpackWithStrategy ForceNoHash >> modifyPackageConfig) $ do with ForceHash generatesHash - with PreferHash doesNotGenerateHash with ForceNoHash doesNotGenerateHash with PreferNoHash doesNotGenerateHash context "with a hash" $ before_ (hpackWithStrategy ForceHash >> modifyPackageConfig) $ do with ForceHash generatesHash - with PreferHash generatesHash with ForceNoHash doesNotGenerateHash with PreferNoHash generatesHash context "with manual modifications" $ before_ modifyCabalFile $ do with ForceHash doesNotOverwrite - with PreferHash doesNotOverwrite with ForceNoHash doesNotGenerateHash with PreferNoHash doesNotOverwrite context "when created manually" $ before_ manuallyCreateCabalFile $ do with ForceHash doesNotOverwrite - with PreferHash doesNotOverwrite with ForceNoHash doesNotOverwrite with PreferNoHash doesNotOverwrite