niv 0.2.5 → 0.2.6
raw patch · 4 files changed
+55/−14 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Niv.Git.Cmd: gitUpdate' :: Update () ()
- Niv.Git.Cmd: gitUpdate :: Update () ()
+ Niv.Git.Cmd: gitUpdate :: (Text -> Text -> IO Text) -> (Text -> IO (Text, Text)) -> Update () ()
Files
- README.md +1/−1
- niv.cabal +2/−2
- src/Niv/Git/Cmd.hs +18/−10
- src/Niv/Git/Test.hs +34/−1
README.md view
@@ -199,7 +199,7 @@ ``` niv - dependency manager for Nix projects -version: 0.2.5+version: 0.2.6 Usage: niv COMMAND
niv.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 1ac84ff519add5882ca1d6c741f446494a48afecec42767401d1f7410d2b713d+-- hash: 1778e623a05d7f0677b3d7e3c3153a46827f792edf3cd623e7675ceef8298aae name: niv-version: 0.2.5+version: 0.2.6 synopsis: Easy dependency management for Nix projects description: Easy dependency management for Nix projects. category: Development
src/Niv/Git/Cmd.hs view
@@ -29,7 +29,7 @@ { description = describeGit , parseCmdShortcut = parseGitShortcut , parsePackageSpec = parseGitPackageSpec- , updateCmd = gitUpdate+ , updateCmd = gitUpdate' , name = "git" } @@ -108,21 +108,29 @@ " niv add git --repo /my/custom/repo --name custom --ref foobar" ] -gitUpdate :: Update () ()-gitUpdate = proc () -> do+gitUpdate+ :: (T.Text -> T.Text -> IO T.Text) -- ^ latest rev+ -> (T.Text -> IO (T.Text, T.Text)) -- ^ latest rev and default ref+ -> Update () ()+gitUpdate latestRev' defaultRefAndHEAD' = proc () -> do useOrSet "type" -< ("git" :: Box T.Text) repository <- load "repo" -< ()- refAndRev <- (discoverRev <+> discoverRefAndRev) -< repository- update "ref" -< fst <$> refAndRev- update "rev" -< snd <$> refAndRev- returnA -< ()+ discoverRev <+> discoverRefAndRev -< repository where discoverRefAndRev = proc repository -> do- run defaultRefAndHEAD -< repository+ refAndRev <- run defaultRefAndHEAD' -< repository+ update "ref" -< fst <$> refAndRev+ update "rev" -< snd <$> refAndRev+ returnA -< () discoverRev = proc repository -> do ref <- load "ref" -< ()- rev <- run (\(r1,r2) -> latestRev r1 r2)-< (,) <$> repository <*> ref- returnA -< (,) <$> ref <*> rev+ rev <- run' (uncurry latestRev') -< (,) <$> repository <*> ref+ update "rev" -< rev+ returnA -< ()++-- | The "real" (IO) update+gitUpdate' :: Update () ()+gitUpdate' = gitUpdate latestRev defaultRefAndHEAD latestRev :: T.Text -- ^ the repository
src/Niv/Git/Test.hs view
@@ -1,16 +1,23 @@ {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE Arrows #-} module Niv.Git.Test (tests) where +import Control.Monad+import Data.Bifunctor import Niv.Git.Cmd import Niv.Sources+import Niv.Update import Test.Tasty.HUnit ((@=?)) import qualified Data.HashMap.Strict as HMS import qualified Test.Tasty as Tasty import qualified Test.Tasty.HUnit as Tasty tests :: [Tasty.TestTree]-tests = pure $ Tasty.testGroup "repository parse"+tests = [ test_repositoryParse , test_gitUpdates ]++test_repositoryParse :: Tasty.TestTree+test_repositoryParse = Tasty.testGroup "repository parse" [ Tasty.testCase "goo" $ parseGitShortcut "goo" @=? Nothing , Tasty.testCase "git@github.com:nmattia/niv" $@@ -28,3 +35,29 @@ parseGitShortcut "~/path/to/repo.git" @=? Just (PackageName "repo", HMS.singleton "repo" "~/path/to/repo.git") ]++test_gitUpdates :: Tasty.TestTree+test_gitUpdates = Tasty.testGroup "updates"+ [ Tasty.testCase "rev is updated" test_gitUpdateRev+ ]++test_gitUpdateRev :: IO ()+test_gitUpdateRev = do+ interState <- evalUpdate initialState $ proc () ->+ gitUpdate (error "should be def") defaultRefAndHEAD' -< ()+ let interState' = HMS.map (first (\_ -> Free)) interState+ actualState <- evalUpdate interState' $ proc () ->+ gitUpdate latestRev' (error "should update") -< ()+ unless ((snd <$> actualState) == expectedState) $+ error $ "State mismatch: " <> show actualState+ where+ latestRev' _ _ = pure "some-other-rev"+ defaultRefAndHEAD' _ = pure ("some-ref", "some-rev")+ initialState = HMS.fromList+ [ ("repo", (Free, "git@github.com:nmattia/niv")) ]+ expectedState = HMS.fromList+ [ ("repo", "git@github.com:nmattia/niv")+ , ("ref", "some-ref")+ , ("rev", "some-other-rev")+ , ("type", "git")+ ]