diff --git a/haskell-docs.cabal b/haskell-docs.cabal
--- a/haskell-docs.cabal
+++ b/haskell-docs.cabal
@@ -1,5 +1,5 @@
 name:                haskell-docs
-version:             3.0.2
+version:             3.0.3
 synopsis:            A program to find and display the docs of a name from a
                      given module.
 description:         Given a module name and a name, it will find and display
@@ -8,6 +8,7 @@
                      /EXAMPLE USAGE/
                      .
                      > $ haskell-docs Data.List.Split split
+                     > split :: forall a. Splitter a -> [a] -> [[a]]
                      > Split a list according to the given splitting strategy. This is
                      >  how to "run" a Splitter that has been built using the other
                      >  combinators.
@@ -81,6 +82,13 @@
                        ghc > 7.2 && < 7.9,
                        haskell-docs,
                        optparse-applicative
+
+test-suite test
+    type: exitcode-stdio-1.0
+    main-is: Main.hs
+    hs-source-dirs: src/test
+    build-depends: base,
+                   haskell-docs
 
 source-repository head
   type:        git
diff --git a/src/Documentation/Haddock/Docs.hs b/src/Documentation/Haddock/Docs.hs
--- a/src/Documentation/Haddock/Docs.hs
+++ b/src/Documentation/Haddock/Docs.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE DeriveDataTypeable #-}
 {-# OPTIONS -Wall -fno-warn-missing-signatures #-}
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE CPP #-}
@@ -6,9 +7,15 @@
 -- | Lookup the documentation of a name in a module (and in a specific
 -- package in the case of ambiguity).
 
-module Documentation.Haddock.Docs where
+module Documentation.Haddock.Docs
+  (withInitializedPackages
+  ,printDocumentation
+  ,mkModuleName
+  ,getType)
+  where
 
 import           Control.Arrow
+import           Control.Exception
 import           Control.Monad
 import           Control.Monad.Loops
 import           Data.Char
@@ -16,6 +23,7 @@
 import           Data.List
 import           Data.Map (Map)
 import qualified Data.Map as M
+import           Data.Typeable
 import           Documentation.Haddock
 import           GHC hiding (verbosity)
 import           GHC.Paths (libdir)
@@ -33,6 +41,11 @@
 import           DynFlags (defaultFlushOut, defaultFatalMessager)
 #endif
 
+data DocsException
+  = Couldn'tFindModule
+  deriving (Typeable,Show)
+instance Exception DocsException
+
 -- | Print documentation with an initialized package set.
 printDocumentationInitialized :: String -> ModuleName -> Maybe String -> [String] -> IO Bool
 printDocumentationInitialized x y z ghcopts =
@@ -83,7 +96,7 @@
 printWithInterface df printPackage package name mname interface = do
   case find ((==name).getOccString) (instExports interface) of
     Nothing -> bail
-    Just qname ->
+    Just{} ->
       case M.lookup name docMap of
         Nothing -> do
           case lookup name (map (getOccString &&& id) (instExports interface)) of
@@ -94,7 +107,7 @@
         Just d ->
           do liftIO (when printPackage $
                        putStrLn $ "Package: " ++ showPackageName (sourcePackageId package))
-             printType df mname qname name
+             printType df mname name
              liftIO (putStrLn (formatDoc d))
              printArgs interface name
              return True
@@ -105,19 +118,39 @@
                              moduleNameString (moduleName (instMod interface)))
           return False
 
-printType d mname _qname name =
-  do _graph <- depanal [] False
-     _loaded <- load LoadAllTargets
-#if __GLASGOW_HASKELL__ == 702
-#else
-     setContext [IIDecl (simpleImportDecl mname)]
-#endif
+-- | Print the type of the given identifier from the given module.
+printType :: DynFlags -> ModuleName -> String -> Ghc ()
+printType d mname name =
+  do _ <- depanal [] False
+     _ <- load LoadAllTargets
+     portableSetContext mname
      names <- getNamesInScope
      mty <- lookupName (head (filter ((==name).getOccString) names))
      case mty of
        Just (AnId i) -> liftIO (do putStr (showppr d i ++ " :: ")
                                    putStrLn (showppr d (idType i)))
        _ -> liftIO (putStrLn "Unable to find type for identifier.")
+
+
+-- | Get the type of the given identifier from the given module.
+getType :: DynFlags -> ModuleName -> String -> Ghc String
+getType d mname name =
+  do _ <- depanal [] False
+     _ <- load LoadAllTargets
+     portableSetContext mname
+     names <- getNamesInScope
+     mty <- lookupName (head (filter ((==name).getOccString) names))
+     case mty of
+       Just (AnId i) -> return (showppr d (idType i))
+       _ -> error "Unable to find type for identifier."
+
+-- | Set the import context.
+portableSetContext :: ModuleName -> Ghc ()
+#if __GLASGOW_HASKELL__ == 702
+portableSetContext mname = setContext [] [simpleImportDecl mname]
+#else
+portableSetContext mname = setContext [IIDecl (simpleImportDecl mname)]
+#endif
 
 -- | Print the documentation of the arguments.
 printArgs :: InstalledInterface -> String -> Ghc ()
diff --git a/src/test/Main.hs b/src/test/Main.hs
new file mode 100644
--- /dev/null
+++ b/src/test/Main.hs
@@ -0,0 +1,75 @@
+-- | Main test suite.
+
+module Main where
+
+import qualified Control.Exception as E
+import           Control.Monad
+import           Documentation.Haddock.Docs
+import           System.Exit
+import           System.IO
+
+-- | Main entry point.
+main :: IO ()
+main =
+  do hSetBuffering stdout NoBuffering
+     spec
+
+-- | Test suite.
+spec :: IO ()
+spec =
+  do describe "initialization" initialization
+     describe "docs" docs
+     describe "types" types
+
+-- | Test GHC initialization.
+initialization :: IO ()
+initialization =
+  do it "withInitializedPackages"
+        (withInitializedPackages [] (\dflags -> return ()))
+
+-- | Test GHC docs.
+docs :: IO ()
+docs =
+  do it "printDocumentation"
+        (withInitializedPackages
+           []
+           (\d ->
+              void (printDocumentation
+                     d
+                     "hSetBuffering"
+                     (mkModuleName "System.IO")
+                     Nothing
+                     Nothing)))
+
+-- | Test GHC types.
+types :: IO ()
+types =
+  do it "getType"
+        (withInitializedPackages
+           []
+           (\d ->
+              do void (printDocumentation
+                        d
+                        "hSetBuffering"
+                        (mkModuleName "System.IO")
+                        Nothing
+                        Nothing)
+                 void (getType d
+                               (mkModuleName "System.IO")
+                               "hSetBuffering")))
+
+-- | Describe a test spec.
+describe :: String -> IO () -> IO ()
+describe name m =
+  do putStrLn ("Spec: " ++ name)
+     m
+
+-- | A test.
+it :: String -> IO () -> IO ()
+it name m =
+  do putStr ("Testing: " ++ name)
+     E.catch m
+             (\E.SomeException{} ->
+                do putStrLn ("\nFailed: " ++ name)
+                   exitFailure)
+     putStrLn "OK."
