diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,2 +1,19 @@
+{-# LANGUAGE CPP #-}
 import Distribution.Simple
-main = defaultMain
+import Distribution.PackageDescription
+import Distribution.Simple.LocalBuildInfo(LocalBuildInfo, buildDir)
+import System.Cmd(system)
+
+ps :: String
+#if mingw32_HOST_OS || mingw32_TARGET_OS
+ps = ['\\']
+#else
+ps = ['/']
+#endif
+
+main = defaultMainWithHooks hooks
+  where hooks = simpleUserHooks { runTests = runTests' }
+
+runTests' :: Args -> Bool -> PackageDescription -> LocalBuildInfo -> IO ()
+runTests' _ _ _ lbi = system testprog >> return ()
+  where testprog = (buildDir lbi) ++ ps ++ "test" ++ ps ++ "test"
diff --git a/bits-extras.cabal b/bits-extras.cabal
--- a/bits-extras.cabal
+++ b/bits-extras.cabal
@@ -1,5 +1,5 @@
 Name:               bits-extras
-Version:            0.1.2
+Version:            0.1.3
 License:            BSD3
 License-File:       License.txt
 Maintainer:         Gabriel Wicke <wicke@wikidev.net>
@@ -30,15 +30,23 @@
  * <http://hackage.haskell.org/trac/ghc/ticket/3563>
  .
  * <http://hackage.haskell.org/trac/ghc/ticket/4102>
+ .
+ /Changes/:
+ .
+ * 0.1.3: Added a first test and tweaked documentation. No functional changes.
+ .
+ * 0.1.2: Moved the 'Data.Bits.Atomic' module to the package @bits-atomic@.
+   Those operations do not depend on libgcc_s and should work wherever GCC 4.X
+   is available.  Link to @bits-atomic@ on hackage:
+   <http://hackage.haskell.org/package/bits-atomic>
 Category:           Data
 Stability:          experimental
 Build-Type:         Simple
 Cabal-Version: >= 1.6
---Extra-Source-Files: cbits/bitops-gcc.c cbits/bitops-gcc.h
+Extra-Source-Files: cbits/bitops-gcc.c cbits/bitops-gcc.h
 Source-Repository head
     type: mercurial
     location: http://dev.wikidev.net/hg/bits-extras/
---extra-tmp-files: cbits/bitops-gcc.h
 library
     Exposed-Modules:  Data.Bits.Extras
     Build-Depends:    base >= 4 && < 6
@@ -58,3 +66,29 @@
     --Includes:       bitops-gcc.h
     --LD-Options:     -flto
     --hs-source-dirs: .
+
+flag test
+    description: Build test program.
+    default:     False
+
+Executable test
+    if flag(test)
+        buildable:  True
+        build-depends:   
+                    base >= 4 && < 6, 
+                    QuickCheck, 
+                    HUnit,
+                    test-framework-quickcheck2,
+                    test-framework-hunit,
+                    test-framework
+    else
+        buildable:  False
+    hs-source-dirs:  ., test
+    other-modules:   Data.Bits.Extras
+    main-is:         test.hs
+    --GHC-Options:      -O2 -threaded -fhpc
+    GHC-Options:      -O2 -threaded
+    GHC-Prof-Options: -auto-all
+
+    Include-Dirs:     cbits
+    C-Sources:        cbits/bitops-gcc.c
diff --git a/test/test.hs b/test/test.hs
new file mode 100644
--- /dev/null
+++ b/test/test.hs
@@ -0,0 +1,55 @@
+{-# LANGUAGE ForeignFunctionInterface, RankNTypes, FlexibleContexts, ExistentialQuantification #-}
+-- Test framework imports
+import Test.Framework (defaultMain, testGroup, Test)
+import Test.Framework.Providers.HUnit
+import Test.HUnit hiding (Test, Testable)
+import Test.Framework.Providers.QuickCheck2
+import Test.QuickCheck
+
+-- Code to test
+import Data.Bits.Extras
+import Data.Word
+import Data.Int
+import Data.Bits
+
+tests :: [Test]
+tests = [ testGroup "Test Cases" 
+          [ testCase "trailingZeros" test_trailingZeros_all
+          ]
+        ]
+
+main :: IO ()
+main = defaultMain tests
+
+-- TODO: Use Quickcheck to produce arbitrary values?
+testPattern :: Integral a => a
+testPattern = 0xdeadbeef
+
+
+type PolyTest = (ExtraBits a, Integral a, Bounded a) => a -> Assertion
+
+testTypes :: PolyTest -> Assertion
+testTypes t = do
+    t (testPattern :: Int)
+    t (testPattern :: Word)
+    t (testPattern :: Int8)
+    t (testPattern :: Int16)
+    t (testPattern :: Int32)
+    t (testPattern :: Int64)
+    t (testPattern :: Word8)
+    t (testPattern :: Word16)
+    t (testPattern :: Word32)
+    t (testPattern :: Word64)
+
+test_trailingZeros :: PolyTest
+test_trailingZeros i = do
+    let t0 = i - i
+    -- No test for 0, as the result would be undefined
+    trailingZeros (t0 + 1) @?= fromIntegral t0
+    trailingZeros (t0 + 3) @?= fromIntegral t0
+    trailingZeros (t0 + 2) @?= fromIntegral t0 + 1
+    let hbitshift = bitSize i - 1
+        hbitset = (t0 + 1) `shiftL` hbitshift
+    assertEqual "High bit set" (fromIntegral hbitset) hbitshift
+test_trailingZeros_all :: Assertion
+test_trailingZeros_all = testTypes test_trailingZeros
