1
1
mirror of https://github.com/sol/hpack.git synced 2024-10-04 03:38:00 +03:00

Refactoring

This commit is contained in:
Simon Hengel 2017-09-26 19:14:53 +08:00
parent a0a41e2af9
commit 0402a445cb
6 changed files with 7 additions and 29 deletions

View File

@ -93,10 +93,9 @@ test-suite spec
build-depends:
Cabal
, Glob
, HUnit
, HUnit >=1.6.0.0
, QuickCheck
, aeson >=0.11
, aeson-qq
, base >=4.7 && <5
, base-compat >=0.8
, bytestring

View File

@ -55,4 +55,3 @@ tests:
- temporary
- mockery >= 0.3
- interpolate
- aeson-qq

View File

@ -8,10 +8,6 @@ module Hpack.Dependency (
, GitRef
, GitUrl
, githubBaseUrl
, parseDependency
#ifdef TEST
, Dependency(..)
#endif
) where
import Prelude ()

View File

@ -17,7 +17,6 @@ import Control.Arrow
import System.Directory (createDirectory)
import Data.Yaml
import Data.Either.Compat
import Data.String
import qualified Data.Map.Lazy as Map
import Hpack.Util
@ -25,9 +24,6 @@ import Hpack.Dependency
import Hpack.Config hiding (package)
import qualified Hpack.Config as Config
instance IsString Dependency where
fromString name = Dependency name AnyVersion
deps :: [String] -> Dependencies
deps = Dependencies . Map.fromList . map (flip (,) AnyVersion)

View File

@ -133,10 +133,3 @@ spec = do
name: inner-name
path: somewhere
|] `parsesAs` Right [("outer-name", SourceDependency (Local "somewhere"))]
describe "parseDependency" $ do
it "parses a dependency" $ do
parseDependency "foo" `shouldBe` Just ("foo", AnyVersion)
it "parses a dependency with version range" $ do
parseDependency "foo == 1.0" `shouldBe` Just ("foo", VersionRange "==1.0")

View File

@ -3,12 +3,10 @@
module Hpack.UtilSpec (main, spec) where
import Data.Aeson
import Data.Aeson.QQ
import Data.Aeson.Types
import Helper
import System.Directory
import Hpack.Dependency
import Hpack.Util
main :: IO ()
@ -72,26 +70,23 @@ spec = do
getModuleFilesRecursive "foo" `shouldReturn` empty
describe "List" $ do
let invalid = [aesonQQ|{
name: "hpack",
gi: "sol/hpack",
ref: "master"
}|]
parseError :: String -> Either String (List Dependency)
parseError prefix = Left (prefix ++ ": neither key \"git\" nor key \"github\" present")
let
parseError :: String -> Either String (List Int)
parseError prefix = Left (prefix ++ ": expected Int, encountered String")
context "when parsing single values" $ do
it "returns the value in a singleton list" $ do
fromJSON (toJSON $ Number 23) `shouldBe` Success (List [23 :: Int])
it "returns error messages from element parsing" $ do
parseEither parseJSON invalid `shouldBe` parseError "Error in $"
parseEither parseJSON (String "foo") `shouldBe` parseError "Error in $"
context "when parsing a list of values" $ do
it "returns the list" $ do
fromJSON (toJSON [Number 23, Number 42]) `shouldBe` Success (List [23, 42 :: Int])
it "propagates parse error messages of invalid elements" $ do
parseEither parseJSON (toJSON [String "foo", invalid]) `shouldBe` parseError "Error in $[1]"
parseEither parseJSON (toJSON [Number 23, String "foo"]) `shouldBe` parseError "Error in $[1]"
describe "tryReadFile" $ do
it "reads file" $ do