diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,3 +1,12 @@
 #!/usr/bin/env runhaskell
 import Distribution.Simple
-main = defaultMain
+import System.Cmd
+import System.Directory
+
+main = defaultMainWithHooks simpleUserHooks{ runTests = \_ _ _ _ -> rt }
+
+rt :: IO ()
+rt = do system "ghc --make -threaded test.hs -o test"
+        system "./test"
+        mapM_ removeFile ["test","test.hi","test.o"]
+        return ()
diff --git a/network-fancy.cabal b/network-fancy.cabal
--- a/network-fancy.cabal
+++ b/network-fancy.cabal
@@ -1,5 +1,5 @@
 Name:                network-fancy
-Version:             0.1.1
+Version:             0.1.2
 Synopsis:            Networking support with a cleaner API
 Description:         Networking support with a cleaner API
 License:             BSD3
@@ -10,25 +10,6 @@
 Maintainer:          taruti@taruti.net
 Build-Type:          Simple
 Cabal-version:       >= 1.6
-
-Executable network-fancy-test
-    Main-Is:             test.hs
-    Other-Modules:       Network.Fancy
-    GHC-Options:         -threaded
-    C-Sources:           cbits.c
-    Build-depends:	 base == 4.*, bytestring, random, directory
-    Extensions:          TypeSynonymInstances, ForeignFunctionInterface, CPP, DeriveDataTypeable
-    if os(windows) {
-      CPP-Options:       -DWINDOWS=WINDOWS -DCALLCONV=stdcall -DSAFE_ON_WIN=safe
-      CC-Options:        -DWINDOWS=WINDOWS -DCALLCONV=stdcall -DSAFE_ON_WIN=safe
-      Extra-Libraries:   ws2_32
-    } else {
-      if os(solaris) {
-        Extra-Libraries: socket
-      }
-      CPP-Options:       -DCALLCONV=ccall -DSAFE_ON_WIN=unsafe
-      CC-Options:        -DCALLCONV=ccall -DSAFE_ON_WIN=unsafe
-    }
 
 Library
     Build-Depends:       base == 4.*, bytestring
diff --git a/test.hs b/test.hs
deleted file mode 100644
--- a/test.hs
+++ /dev/null
@@ -1,60 +0,0 @@
-import Control.Exception
-import Data.Typeable
-import Network.Fancy
-import System.IO
-import System.Directory
-import System.Random
-
-main = do
-  ipv4_test
-  ipv6_test
-  unix_test
-  putStrLn "> connect tests"
-  tryE $ connectStream $ IPv4 "google.com" 80
-  tryE $ connectStream $ IPv4 "foobarbaz.invalid" 0
-  tryE $ connectDgram  $ IPv4 "foobarbaz.invalid" 0
-  tryE $ connectStream $ IP   "foobarbaz.invalid" 0
-  putStrLn "> done"
-  print =<< getCurrentHost
-  putStrLn ">testing instances"
-  let a = IP "" 0
-  print a
-  print (a == a)
-  print (a < a)
-  putStrLn "> dgram server"
-  tryE $ do
-    addr <- IPv4 "127.0.0.1" `fmap` rport
-    let rev :: String -> String
-        rev = reverse
-    dgramServer (serverSpec { address = addr, reverseAddress = ReverseName }) (\s sa -> putStrLn ("< connect from "++show sa) >> return [rev s])
-    withDgram addr $ \s -> do
-    send s "PING"
-    "GNIP" <- recv s 99
-    return ()
-
-rport = randomRIO (2000,50000)
-
-ipv4_test = server_test =<< (IPv4 "127.0.0.1" `fmap` rport)
-ipv6_test = server_test =<< (IPv6 "::1" `fmap` rport)
-
-unix_test = do
-  tryE $ removeFile "/tmp/unix_test"
-  server_test $ Unix "/tmp/unix_test"
-
-server_test adr = tryE $ do
-  putStrLn ("> running server_test "++show adr)
-  streamServer (serverSpec { address = adr }) (\h sa -> putStrLn ("< connect from "++show sa) >> hGetLine h >>= hPutStrLn h . reverse)
-  putStrLn "> starting client"
-  withStream adr $ \h -> do
-  putStrLn ("> client to "++show adr)
-  hPutStrLn h "PING"
-  hFlush h
-  "GNIP" <- hGetLine h
-  putStrLn "> ok"
-
-tryE :: IO a -> IO ()
-tryE x = try x >>= eh
-eh :: Either SomeException a -> IO ()
-eh (Left e) = print e
-eh _        = return ()
-
