diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-11 22:05:12 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-11 22:05:12 +0000 |
commit | 7de330ea4fa17a0e1ba2eb33e4440545dc6be93a (patch) | |
tree | a70bd209ab69883964f8ba1b3c1667b13580758c /server | |
parent | a86e55bbcc6d5b23ab11312d3ca94a745bea5ed9 (diff) | |
download | thermoprint-7de330ea4fa17a0e1ba2eb33e4440545dc6be93a.tar thermoprint-7de330ea4fa17a0e1ba2eb33e4440545dc6be93a.tar.gz thermoprint-7de330ea4fa17a0e1ba2eb33e4440545dc6be93a.tar.bz2 thermoprint-7de330ea4fa17a0e1ba2eb33e4440545dc6be93a.tar.xz thermoprint-7de330ea4fa17a0e1ba2eb33e4440545dc6be93a.zip |
Test for zipper morphisms
Diffstat (limited to 'server')
-rw-r--r-- | server/src/Thermoprint/Server/Queue.hs | 4 | ||||
-rw-r--r-- | server/test/Spec.hs | 1 | ||||
-rw-r--r-- | server/test/Thermoprint/Server/QueueSpec.hs | 34 | ||||
-rw-r--r-- | server/thermoprint-server.cabal | 11 | ||||
-rw-r--r-- | server/thermoprint-server.nix | 10 |
5 files changed, 55 insertions, 5 deletions
diff --git a/server/src/Thermoprint/Server/Queue.hs b/server/src/Thermoprint/Server/Queue.hs index d5ab42b..52e973d 100644 --- a/server/src/Thermoprint/Server/Queue.hs +++ b/server/src/Thermoprint/Server/Queue.hs | |||
@@ -52,7 +52,7 @@ data Queue = Queue | |||
52 | , current :: Maybe QueueEntry | 52 | , current :: Maybe QueueEntry |
53 | , history :: Seq (QueueEntry, Maybe PrintingError) -- ^ Completed jobs, closest first | 53 | , history :: Seq (QueueEntry, Maybe PrintingError) -- ^ Completed jobs, closest first |
54 | } | 54 | } |
55 | deriving (Typeable, Generic, NFData) | 55 | deriving (Typeable, Generic, NFData, Show) |
56 | 56 | ||
57 | class HasQueue a where | 57 | class HasQueue a where |
58 | extractQueue :: a -> TVar Queue | 58 | extractQueue :: a -> TVar Queue |
@@ -71,7 +71,7 @@ data QueueEntry = QueueEntry | |||
71 | { jobId :: JobId | 71 | { jobId :: JobId |
72 | , created :: UTCTime | 72 | , created :: UTCTime |
73 | } | 73 | } |
74 | deriving (Typeable, Generic, NFData, Eq, Ord) | 74 | deriving (Typeable, Generic, NFData, Eq, Ord, Show) |
75 | 75 | ||
76 | data QueueItem = Pending Int QueueEntry | Current QueueEntry | History Int QueueEntry (Maybe PrintingError) | 76 | data QueueItem = Pending Int QueueEntry | Current QueueEntry | History Int QueueEntry (Maybe PrintingError) |
77 | 77 | ||
diff --git a/server/test/Spec.hs b/server/test/Spec.hs new file mode 100644 index 0000000..a824f8c --- /dev/null +++ b/server/test/Spec.hs | |||
@@ -0,0 +1 @@ | |||
{-# OPTIONS_GHC -F -pgmF hspec-discover #-} | |||
diff --git a/server/test/Thermoprint/Server/QueueSpec.hs b/server/test/Thermoprint/Server/QueueSpec.hs new file mode 100644 index 0000000..fd45e1b --- /dev/null +++ b/server/test/Thermoprint/Server/QueueSpec.hs | |||
@@ -0,0 +1,34 @@ | |||
1 | {-# LANGUAGE TypeSynonymInstances, FlexibleInstances, StandaloneDeriving #-} | ||
2 | |||
3 | module Thermoprint.Server.QueueSpec (spec) where | ||
4 | |||
5 | import Test.Hspec | ||
6 | import Test.Hspec.QuickCheck (prop) | ||
7 | |||
8 | import Thermoprint.Server.Queue | ||
9 | import Thermoprint.Server.Database | ||
10 | import Thermoprint.API hiding (JobId) | ||
11 | |||
12 | import Test.QuickCheck.Arbitrary | ||
13 | import Test.QuickCheck.Gen | ||
14 | import Test.QuickCheck.Modifiers | ||
15 | |||
16 | deriving instance (Eq PrintingError) | ||
17 | deriving instance (Eq Queue) | ||
18 | |||
19 | instance Arbitrary Queue where | ||
20 | arbitrary = Queue <$> arbitrary <*> arbitrary <*> arbitrary | ||
21 | |||
22 | instance Arbitrary QueueEntry where | ||
23 | arbitrary = QueueEntry <$> arbitrary <*> arbitrary | ||
24 | |||
25 | instance Arbitrary PrintingError where | ||
26 | arbitrary = oneof [ return UnknownError | ||
27 | ] | ||
28 | |||
29 | instance Arbitrary JobId where | ||
30 | arbitrary = castId . getNonNegative <$> (arbitrary :: Gen (NonNegative Integer)) | ||
31 | |||
32 | spec :: Spec | ||
33 | spec = do | ||
34 | prop "prop_zipper" $ \queue -> queue == toZipper (fromZipper queue) | ||
diff --git a/server/thermoprint-server.cabal b/server/thermoprint-server.cabal index 5e1b0b2..5783f06 100644 --- a/server/thermoprint-server.cabal +++ b/server/thermoprint-server.cabal | |||
@@ -52,6 +52,17 @@ library | |||
52 | hs-source-dirs: src | 52 | hs-source-dirs: src |
53 | default-language: Haskell2010 | 53 | default-language: Haskell2010 |
54 | 54 | ||
55 | Test-Suite tests | ||
56 | type: exitcode-stdio-1.0 | ||
57 | hs-source-dirs: test | ||
58 | main-is: Spec.hs | ||
59 | build-depends: base >=4.8.1 && <5 | ||
60 | , thermoprint-server -any | ||
61 | , thermoprint-spec -any | ||
62 | , hspec >=2.2.1 && <3 | ||
63 | , QuickCheck >=2.8.1 && <3 | ||
64 | , quickcheck-instances >=0.3.11 && <4 | ||
65 | |||
55 | executable thermoprint-server | 66 | executable thermoprint-server |
56 | main-is: Main.hs | 67 | main-is: Main.hs |
57 | build-depends: base >=4.8 && <5 | 68 | build-depends: base >=4.8 && <5 |
diff --git a/server/thermoprint-server.nix b/server/thermoprint-server.nix index 41f7198..a33e6db 100644 --- a/server/thermoprint-server.nix +++ b/server/thermoprint-server.nix | |||
@@ -1,8 +1,9 @@ | |||
1 | { mkDerivation, base, conduit, containers, data-default-class | 1 | { mkDerivation, base, conduit, containers, data-default-class |
2 | , deepseq, dyre, either, exceptions, extended-reals, mmorph | 2 | , deepseq, dyre, either, exceptions, extended-reals, hspec, mmorph |
3 | , monad-control, monad-logger, mtl, persistent, persistent-sqlite | 3 | , monad-control, monad-logger, mtl, persistent, persistent-sqlite |
4 | , persistent-template, resourcet, servant-server, stdenv, stm, text | 4 | , persistent-template, QuickCheck, quickcheck-instances, resourcet |
5 | , thermoprint-spec, time, transformers, wai, warp | 5 | , servant-server, stdenv, stm, text, thermoprint-spec, time |
6 | , transformers, wai, warp | ||
6 | }: | 7 | }: |
7 | mkDerivation { | 8 | mkDerivation { |
8 | pname = "thermoprint-server"; | 9 | pname = "thermoprint-server"; |
@@ -19,6 +20,9 @@ mkDerivation { | |||
19 | executableHaskellDepends = [ | 20 | executableHaskellDepends = [ |
20 | base monad-logger mtl persistent-sqlite resourcet | 21 | base monad-logger mtl persistent-sqlite resourcet |
21 | ]; | 22 | ]; |
23 | testHaskellDepends = [ | ||
24 | base hspec QuickCheck quickcheck-instances | ||
25 | ]; | ||
22 | homepage = "http://dirty-haskell.org/tags/thermoprint.html"; | 26 | homepage = "http://dirty-haskell.org/tags/thermoprint.html"; |
23 | description = "Server for thermoprint-spec"; | 27 | description = "Server for thermoprint-spec"; |
24 | license = stdenv.lib.licenses.publicDomain; | 28 | license = stdenv.lib.licenses.publicDomain; |