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

Removed dead constructor PreferHash #446

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -81,7 +81,10 @@ data Options = Options {
, optionsToStdout :: Bool
}

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 @@ -232,10 +235,9 @@ shouldGenerateHash :: Maybe CabalFile -> 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 -> CabalFile -> [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 @@ -99,32 +99,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