diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-17 01:05:57 +0000 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-17 01:05:57 +0000 |
| commit | fff9cbfc9e7919723349e18c4b9aea89bcc48c1a (patch) | |
| tree | 8256a7c6a8e77d01446e70c5692c868c24a18b1f | |
| parent | e3068de72434d6152c40df691f26943c88327406 (diff) | |
| download | thermoprint-fff9cbfc9e7919723349e18c4b9aea89bcc48c1a.tar thermoprint-fff9cbfc9e7919723349e18c4b9aea89bcc48c1a.tar.gz thermoprint-fff9cbfc9e7919723349e18c4b9aea89bcc48c1a.tar.bz2 thermoprint-fff9cbfc9e7919723349e18c4b9aea89bcc48c1a.tar.xz thermoprint-fff9cbfc9e7919723349e18c4b9aea89bcc48c1a.zip | |
Harness for tests of Thermoprint.Server
| -rw-r--r-- | server/test/Thermoprint/ServerSpec.hs | 59 | ||||
| -rw-r--r-- | server/thermoprint-server.cabal | 14 | ||||
| -rw-r--r-- | server/thermoprint-server.nix | 11 | ||||
| -rw-r--r-- | shell.nix | 1 |
4 files changed, 78 insertions, 7 deletions
diff --git a/server/test/Thermoprint/ServerSpec.hs b/server/test/Thermoprint/ServerSpec.hs new file mode 100644 index 0000000..aa654b1 --- /dev/null +++ b/server/test/Thermoprint/ServerSpec.hs | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | {-# LANGUAGE OverloadedStrings #-} | ||
| 2 | {-# LANGUAGE ImpredicativeTypes #-} | ||
| 3 | |||
| 4 | module Thermoprint.ServerSpec (spec) where | ||
| 5 | |||
| 6 | import Test.HUnit | ||
| 7 | import Test.Hspec | ||
| 8 | import Test.Hspec.Contrib.HUnit | ||
| 9 | |||
| 10 | import Thermoprint.API | ||
| 11 | import Thermoprint.Server | ||
| 12 | |||
| 13 | import Control.Monad | ||
| 14 | import Control.Monad.Logger | ||
| 15 | import Control.Monad.Reader | ||
| 16 | import Control.Monad.Trans.Identity | ||
| 17 | import Control.Monad.Trans.Resource | ||
| 18 | |||
| 19 | import Database.Persist.Sqlite | ||
| 20 | |||
| 21 | import Control.Concurrent | ||
| 22 | import Control.Concurrent.STM | ||
| 23 | |||
| 24 | import System.IO | ||
| 25 | import System.IO.Temp | ||
| 26 | |||
| 27 | import qualified Data.Text as T | ||
| 28 | |||
| 29 | data TestPrinter = TestPrinter | ||
| 30 | { outputChan :: TChan Printout | ||
| 31 | , failSwitch :: TMVar PrintingError | ||
| 32 | } | ||
| 33 | |||
| 34 | data TestManager = TestManager | ||
| 35 | { manage :: TMVar (QueueManager IdentityT) | ||
| 36 | } | ||
| 37 | |||
| 38 | setup :: IO (ThreadId, TestPrinter, TestManager) | ||
| 39 | setup = withSystemTempFile "thermoprint.sqlite" $ \fp h -> hClose h >> do | ||
| 40 | tPrinter <- TestPrinter <$> newTChanIO <*> newEmptyTMVarIO | ||
| 41 | tManager <- TestManager <$> newEmptyTMVarIO | ||
| 42 | let | ||
| 43 | runSqlite :: ReaderT ConnectionPool (LoggingT IO) a -> IO a | ||
| 44 | runSqlite = runStderrLoggingT . withSqlitePool (T.pack fp) 1 . runReaderT | ||
| 45 | |||
| 46 | printers = [ ( pure $ PM tPM | ||
| 47 | , QMConfig (join . lift $ takeTMVar (manage tManager)) (Nat $ liftIO . runIdentityT) | ||
| 48 | ) | ||
| 49 | ] | ||
| 50 | |||
| 51 | tPM :: MonadIO m => Printout -> m (Maybe PrintingError) | ||
| 52 | tPM printout = liftIO . atomically $ writeTChan (outputChan tPrinter) printout >> tryTakeTMVar (failSwitch tPrinter) | ||
| 53 | (,,) <$> forkIO (thermoprintServer (Nat runSqlite) $ def `withPrinters` printers) <*> pure tPrinter <*> pure tManager | ||
| 54 | |||
| 55 | spec :: Spec | ||
| 56 | spec = do | ||
| 57 | fromHUnitTest . test . ("blub" ~:) $ do | ||
| 58 | putStrLn "Blub." | ||
| 59 | return True | ||
diff --git a/server/thermoprint-server.cabal b/server/thermoprint-server.cabal index 1ad4d4d..849d35a 100644 --- a/server/thermoprint-server.cabal +++ b/server/thermoprint-server.cabal | |||
| @@ -36,16 +36,16 @@ library | |||
| 36 | , exceptions >=0.8.0 && <1 | 36 | , exceptions >=0.8.0 && <1 |
| 37 | , monad-control >=1.0.0 && <2 | 37 | , monad-control >=1.0.0 && <2 |
| 38 | , monad-logger >=0.3.13 && <1 | 38 | , monad-logger >=0.3.13 && <1 |
| 39 | , resourcet >=1.1.7 && <2 | ||
| 39 | , mtl >=2.2.1 && <3 | 40 | , mtl >=2.2.1 && <3 |
| 41 | , transformers >=0.3.0 && <1 | ||
| 40 | , persistent >=2.2 && <3 | 42 | , persistent >=2.2 && <3 |
| 41 | , persistent-template >=2.1.4 && <3 | 43 | , persistent-template >=2.1.4 && <3 |
| 42 | , resourcet >=1.1.7 && <2 | ||
| 43 | , servant-server >=0.4.4 && <1 | 44 | , servant-server >=0.4.4 && <1 |
| 44 | , stm >=2.4.4 && <3 | 45 | , stm >=2.4.4 && <3 |
| 45 | , text >=1.2.1 && <2 | 46 | , text >=1.2.1 && <2 |
| 46 | , thermoprint-spec ==3.0.* | 47 | , thermoprint-spec ==3.0.* |
| 47 | , time >=1.5.0 && <2 | 48 | , time >=1.5.0 && <2 |
| 48 | , transformers >=0.3.0 && <1 | ||
| 49 | , wai >=3.0.4 && <4 | 49 | , wai >=3.0.4 && <4 |
| 50 | , warp >=3.1.9 && <4 | 50 | , warp >=3.1.9 && <4 |
| 51 | , mmorph >=1.0.4 && <2 | 51 | , mmorph >=1.0.4 && <2 |
| @@ -65,8 +65,18 @@ Test-Suite tests | |||
| 65 | , thermoprint-server -any | 65 | , thermoprint-server -any |
| 66 | , thermoprint-spec -any | 66 | , thermoprint-spec -any |
| 67 | , hspec >=2.2.1 && <3 | 67 | , hspec >=2.2.1 && <3 |
| 68 | , hspec-contrib >=0.3.0 && <1 | ||
| 69 | , HUnit >=1.2.5 && <2 | ||
| 68 | , QuickCheck >=2.8.1 && <3 | 70 | , QuickCheck >=2.8.1 && <3 |
| 69 | , quickcheck-instances >=0.3.11 && <4 | 71 | , quickcheck-instances >=0.3.11 && <4 |
| 72 | , temporary >=1.2.0 && <2 | ||
| 73 | , monad-logger >=0.3.13 && <1 | ||
| 74 | , resourcet >=1.1.7 && <2 | ||
| 75 | , mtl >=2.2.1 && <3 | ||
| 76 | , transformers >=0.3.0 && <1 | ||
| 77 | , persistent-sqlite >=2.2 && <3 | ||
| 78 | , text >=1.2.1 && <2 | ||
| 79 | , stm >=2.4.4 && <3 | ||
| 70 | 80 | ||
| 71 | executable thermoprint-server | 81 | executable thermoprint-server |
| 72 | main-is: Main.hs | 82 | main-is: Main.hs |
diff --git a/server/thermoprint-server.nix b/server/thermoprint-server.nix index 77911a8..737f571 100644 --- a/server/thermoprint-server.nix +++ b/server/thermoprint-server.nix | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | { mkDerivation, base, binary, bytestring, conduit, containers | 1 | { mkDerivation, base, binary, bytestring, conduit, containers |
| 2 | , data-default-class, deepseq, dyre, either, encoding, exceptions | 2 | , data-default-class, deepseq, dyre, either, encoding, exceptions |
| 3 | , extended-reals, filelock, hspec, mmorph, monad-control | 3 | , extended-reals, filelock, hspec, hspec-contrib, HUnit, mmorph |
| 4 | , monad-logger, mtl, persistent, persistent-sqlite | 4 | , monad-control, monad-logger, mtl, persistent, persistent-sqlite |
| 5 | , persistent-template, QuickCheck, quickcheck-instances, resourcet | 5 | , persistent-template, QuickCheck, quickcheck-instances, resourcet |
| 6 | , servant-server, stdenv, stm, text, thermoprint-spec, time | 6 | , servant-server, stdenv, stm, temporary, text, thermoprint-spec |
| 7 | , transformers, wai, warp | 7 | , time, transformers, wai, warp |
| 8 | }: | 8 | }: |
| 9 | mkDerivation { | 9 | mkDerivation { |
| 10 | pname = "thermoprint-server"; | 10 | pname = "thermoprint-server"; |
| @@ -23,7 +23,8 @@ mkDerivation { | |||
| 23 | base monad-logger mtl persistent-sqlite resourcet | 23 | base monad-logger mtl persistent-sqlite resourcet |
| 24 | ]; | 24 | ]; |
| 25 | testHaskellDepends = [ | 25 | testHaskellDepends = [ |
| 26 | base hspec QuickCheck quickcheck-instances thermoprint-spec | 26 | base hspec hspec-contrib HUnit QuickCheck quickcheck-instances |
| 27 | temporary thermoprint-spec | ||
| 27 | ]; | 28 | ]; |
| 28 | homepage = "http://dirty-haskell.org/tags/thermoprint.html"; | 29 | homepage = "http://dirty-haskell.org/tags/thermoprint.html"; |
| 29 | description = "Server for thermoprint-spec"; | 30 | description = "Server for thermoprint-spec"; |
| @@ -6,6 +6,7 @@ let | |||
| 6 | packages = ps: with ps; [ | 6 | packages = ps: with ps; [ |
| 7 | cabal-install hlint cabal2nix | 7 | cabal-install hlint cabal2nix |
| 8 | hspec QuickCheck quickcheck-instances | 8 | hspec QuickCheck quickcheck-instances |
| 9 | hspec-contrib temporary | ||
| 9 | ] ++ (builtins.attrValues (import ./default.nix { inherit pkgs; })); | 10 | ] ++ (builtins.attrValues (import ./default.nix { inherit pkgs; })); |
| 10 | ghc = pkgs.haskell.packages.${compilerName}.ghcWithPackages packages; | 11 | ghc = pkgs.haskell.packages.${compilerName}.ghcWithPackages packages; |
| 11 | in | 12 | in |
