packages feed

test-sandbox 0.1.0 → 0.1.1

raw patch · 4 files changed

+75/−19 lines, 4 filesdep +hspec-expectations-lifteddep +transformers-compatdep ~transformersPVP ok

version bump matches the API change (PVP)

Dependencies added: hspec-expectations-lifted, transformers-compat

Dependency ranges changed: transformers

API changes (from Hackage documentation)

+ Test.Sandbox.Internals: isBindable' :: Port -> IO Bool

Files

ChangeLog.md view
@@ -1,3 +1,8 @@+## 0.1.1++* Fix bugs of both isBindable and sendToPort : I was mistaken about PortNum.+* Support for ghc 7.8.4+ ## 0.1.0  * Change "return value" of both getPort and setPort from PortNumber-type to Port(Int)-type 
src/Test/Sandbox/Internals.hs view
@@ -237,7 +237,7 @@   env <- get   case M.lookup name (ssAllocatedPorts env) of     Nothing -> throwError $ "No such allocated port: " ++ name-    Just port -> do h <- liftIO . withSocketsDo $ connectTo "localhost" $ PortNumber $ PortNum $ fromIntegral port+    Just port -> do h <- liftIO . withSocketsDo $ connectTo "localhost" $ PortNumber $ fromIntegral port                     liftIO $ do B.hPutStr h $ B.pack input                                 hFlush h                     b <- hReadWithTimeout h timeout@@ -258,6 +258,18 @@           return (head pl', tail pl')  +isBindable' :: Port -> IO Bool+isBindable' p = withSocketsDo $ do+  s <- socket AF_INET Stream defaultProtocol+  setSocketOption s ReuseAddr 1+  localhost <- inet_addr "127.0.0.1"+  let sa = SockAddrInet (fromIntegral p) localhost+  r <- (bind s sa >> isBound s)+         `catch` ((\_ -> return False) :: SomeException -> IO Bool)+  close s+  return $! r++ #if defined __LINUX__ isBindable :: Port -> IO Bool isBindable port = do@@ -297,16 +309,7 @@  #else isBindable :: Port -> IO Bool-isBindable p = withSocketsDo $ do-  s <- socket AF_INET Stream defaultProtocol-  setSocketOption s ReuseAddr 1-  localhost <- inet_addr "127.0.0.1"-  let sa = SockAddrInet (PortNum (fromIntegral p)) localhost-  r <- (bind s sa >> isBound s)-         `catch` ((\_ -> return False) :: SomeException -> IO Bool)-  close s-  return $! r-+isBindable = isBindable' #endif  
test-sandbox.cabal view
@@ -1,5 +1,5 @@ Name:           test-sandbox-Version:        0.1.0+Version:        0.1.1 Cabal-Version:  >= 1.14 Category:       Testing Synopsis:       Sandbox for system tests@@ -28,18 +28,34 @@ Source-Repository this     Type:       git     Location:   https://github.com/gree/haskell-test-sandbox-    Tag:        test-sandbox_0.1.0+    Tag:        test-sandbox_0.1.1  Library     Exposed-modules:    Test.Sandbox                         Test.Sandbox.Internals                         Test.Sandbox.Process -    Build-Depends:      base >=4 && <5, bytestring, cereal, containers,-                        data-default, directory, filepath, lifted-base,-                        monad-control, monad-loops, mtl, network, process,-                        random, random-shuffle, temporary, transformers >= 0.4,-                        transformers-base, unix, regex-posix+    Build-Depends:      base >=4 && <5+                      , bytestring+                      , cereal+                      , containers+                      , data-default+                      , directory+                      , filepath+                      , lifted-base+                      , monad-control+                      , monad-loops+                      , mtl+                      , network+                      , process+                      , random+                      , random-shuffle+                      , temporary+                      , transformers             >= 0.2      && < 0.5+                      , transformers-compat      >= 0.3      && < 0.5+                      , transformers-base+                      , unix+                      , regex-posix      Hs-source-dirs:     src     Default-Language:   Haskell2010@@ -54,6 +70,7 @@     build-depends: base                  , test-sandbox                  , hspec+                 , hspec-expectations-lifted                  , template-haskell                  , heredoc                  , hastache@@ -62,6 +79,7 @@                  , unix                  , mtl                  , transformers+                 , transformers-compat                  , regex-posix                  , directory                  , process
test/test.hs view
@@ -2,7 +2,8 @@ {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE CPP #-}-import Test.Hspec+import Test.Hspec hiding (shouldReturn,shouldBe)+import Test.Hspec.Expectations.Lifted import Test.QuickCheck import Test.QuickCheck.Monadic (assert,monadicIO) import Test.Sandbox@@ -37,6 +38,35 @@ main = withSandbox $ \gref -> do   hspec $ do     describe "Basic Test" $ do+      it "Run nc : port 12181" $ do+        runSandbox' gref $ do+          file <- setFile "ncfile1"+                  [str|#!/usr/bin/env bash+                      |echo hoge | nc -l 12181+                      |]+          liftIO $ setExecuteMode file+          start =<< register "ncserver1" file [] def { psCapture = Just CaptureStdout }+      it "isBinable' 12181" $ do+        I.isBindable' 12181 `shouldReturn` False+      it "isBinable' 12180" $ do+        I.isBindable' 12180 `shouldReturn` True+      it "Test isBinable 12181" $ do+        I.isBindable 12181 `shouldReturn` False+      it "Test isBinable 12180" $ do+        I.isBindable 12180 `shouldReturn` True+      it "Test sendTo" $ do+        runSandbox' gref $ do+          p <- getPort "ncport"+          file <- setFile' "ncfile"+                  [("port",p)]+                  [str|#!/usr/bin/env bash+                      |echo hoge | nc -l {{port}}+                      |]+          liftIO $ I.isBindable p `shouldReturn` True+          liftIO $ setExecuteMode file+          start =<< register "ncserver" file [] def { psCapture = Just CaptureStdout }+          liftIO $ I.isBindable p `shouldReturn` False+          sendTo "ncport" "hogehoge\n" 1 `shouldReturn` "hoge\n"       it "interactive Test by sandbox" $ do         sandbox "hogehoge" $ do           start =<< register "sed_regex" "sed" [ "-u", "s/a/b/" ] def { psCapture = Just CaptureStdout }