Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions src/Hpack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Owner

Choose a reason for hiding this comment

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

I think you are right that as far as the hpack executable is concerned this is indeed dead code. However, it is exposed through the API, so as I understand it a user of the API could still use it to force pre-0.34 behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so maybe phase this out slowly, or deprecate it in the API first.

deriving (Eq, Show)

getOptions :: FilePath -> [String] -> IO (Maybe (Verbose, Options))
Expand Down Expand Up @@ -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
5 changes: 0 additions & 5 deletions test/HpackSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down