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

Allow test-only dependencies

This commit is contained in:
Simon Hengel 2015-04-03 17:17:07 +08:00
parent 923670f35a
commit daa23012db
7 changed files with 25 additions and 9 deletions

View File

@ -10,6 +10,7 @@ library
Cabalize
other-modules:
Config
Config.Test
Util
build-depends:
base == 4.*

View File

@ -10,3 +10,5 @@ dependencies:
tests:
spec:
main: test/Spec.hs
dependencies:
- hspec == 2.*

View File

@ -12,7 +12,9 @@ import qualified Data.HashMap.Lazy as Map
import Util
import Config (Config)
import qualified Config
import qualified Config.Test as Test
type Dependency = String
@ -48,8 +50,8 @@ test-suite spec
default-language: Haskell2010
|]
testConfigToTest :: [Dependency] -> String -> Config.Test -> Test
testConfigToTest dependencies name t = Test name (Config.main t) dependencies
testConfigToTest :: [Dependency] -> String -> Test.Test -> Test
testConfigToTest dependencies name t = Test name (Test.main t) (dependencies ++ fromMaybe [] (Test.dependencies t))
configFile :: FilePath
configFile = "package.yaml"

View File

@ -5,6 +5,8 @@ import Data.Yaml
import GHC.Generics
import Data.HashMap.Lazy (HashMap)
import Config.Test (Test)
data Config = Config {
dependencies :: [String]
, tests :: HashMap String Test
@ -12,11 +14,5 @@ data Config = Config {
instance FromJSON Config
data Test = Test {
main :: FilePath
} deriving (Eq, Show, Generic)
instance FromJSON Test
readConfig :: FilePath -> IO (Maybe Config)
readConfig = decodeFile

12
src/Config/Test.hs Normal file
View File

@ -0,0 +1,12 @@
{-# LANGUAGE DeriveGeneric #-}
module Config.Test where
import Data.Yaml
import GHC.Generics
data Test = Test {
main :: FilePath
, dependencies :: Maybe [String]
} deriving (Eq, Show, Generic)
instance FromJSON Test

View File

@ -26,6 +26,7 @@ spec = do
exposed-modules:
Cabalize
Config
Config.Test
Util
build-depends:
base == 4.*
@ -46,6 +47,7 @@ spec = do
, base-compat
, directory
, filepath
, hspec == 2.*
, interpolate
, unordered-containers
, yaml

View File

@ -6,6 +6,7 @@ import Helper
import Data.String.Interpolate
import Config hiding (main)
import Config.Test (Test(Test))
main :: IO ()
main = hspec spec
@ -21,4 +22,4 @@ dependencies:
tests:
spec:
main: test/Spec.hs
|] $ \file -> readConfig file `shouldReturn` Just (Config ["base"] [("spec", Test "test/Spec.hs")])
|] $ \file -> readConfig file `shouldReturn` Just (Config ["base"] [("spec", Test "test/Spec.hs" Nothing)])