diff --git a/CHANGES.txt b/CHANGES.txt
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,8 @@
 Changelog for HLint
 
+2.0.5
+    If the datadir is missing use data/ relative to the executable
+    Fix test mode to obey --datadir
 2.0.4
     --default adds ignores for any warnings it finds
 2.0.3
diff --git a/hlint.cabal b/hlint.cabal
--- a/hlint.cabal
+++ b/hlint.cabal
@@ -1,7 +1,7 @@
 cabal-version:      >= 1.18
 build-type:         Simple
 name:               hlint
-version:            2.0.4
+version:            2.0.5
 license:            BSD3
 license-file:       LICENSE
 category:           Development
diff --git a/src/CmdLine.hs b/src/CmdLine.hs
--- a/src/CmdLine.hs
+++ b/src/CmdLine.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE PatternGuards, RecordWildCards, DeriveDataTypeable #-}
+{-# LANGUAGE PatternGuards, DeriveDataTypeable #-}
 {-# OPTIONS_GHC -fno-warn-missing-fields -fno-cse -O0 #-}
 
 module CmdLine(
@@ -21,7 +21,7 @@
 import Language.Haskell.Exts(defaultParseMode, baseLanguage)
 import Language.Haskell.Exts.Extension
 import Data.Maybe
-import System.Environment
+import System.Environment.Extra
 import System.Info.Extra
 
 import Util
@@ -35,19 +35,22 @@
 
 
 automatic :: Cmd -> IO Cmd
-automatic CmdMain{..} = do
-    cmdDataDir <- if cmdDataDir == "" then getDataDir else return cmdDataDir
-    cmdPath <- return $ if null cmdPath then ["."] else cmdPath
-    cmdExtension <- return $ if null cmdExtension then ["hs", "lhs"] else cmdExtension
-    return CmdMain{..}
-automatic CmdGrep{..} = do
-    cmdPath <- return $ if null cmdPath then ["."] else cmdPath
-    cmdExtension <- return $ if null cmdExtension then ["hs", "lhs"] else cmdExtension
-    return CmdGrep{..}
-automatic CmdTest{..} = do
-    cmdDataDir <- if cmdDataDir == "" then getDataDir else return cmdDataDir
-    return CmdTest{..}
-automatic x = return x
+automatic cmd = case cmd of
+    CmdMain{} -> dataDir $ path $ extension cmd
+    CmdGrep{} -> return $ path $ extension cmd
+    CmdTest{} -> dataDir cmd
+    _ -> return cmd
+    where
+        path cmd = if null $ cmdPath cmd then cmd{cmdPath=["."]} else cmd
+        extension cmd = if null $ cmdExtension cmd then cmd{cmdExtension=["hs","lhs"]} else cmd
+        dataDir cmd
+            | cmdDataDir cmd  /= "" = return cmd
+            | otherwise = do
+                x <- getDataDir
+                b <- doesDirectoryExist x
+                if b then return cmd{cmdDataDir=x} else do
+                    exe <- getExecutablePath
+                    return cmd{cmdDataDir = takeDirectory exe </> "data"}
 
 
 exitWithHelp :: IO a
diff --git a/src/Test/All.hs b/src/Test/All.hs
--- a/src/Test/All.hs
+++ b/src/Test/All.hs
@@ -49,9 +49,9 @@
     wrap "Hint names" $ mapM_ (\x -> do progress; testNames $ snd x) testFiles
     wrap "Hint annotations" $ forM_ testFiles $ \(file,h) -> do progress; testAnnotations h file
     when cmdTypeCheck $ wrap "Hint typechecking" $
-        progress >> testTypeCheck cmdTempDir [h | (file, h) <- testFiles, takeFileName file /= "Test.hs"]
+        progress >> testTypeCheck cmdDataDir cmdTempDir [h | (file, h) <- testFiles, takeFileName file /= "Test.hs"]
     when cmdQuickCheck $ wrap "Hint QuickChecking" $
-        progress >> testQuickCheck cmdTempDir [h | (file, h) <- testFiles, takeFileName file /= "Test.hs"]
+        progress >> testQuickCheck cmdDataDir cmdTempDir [h | (file, h) <- testFiles, takeFileName file /= "Test.hs"]
 
     when (null files && not hasSrc) $ putStrLn "Warning, couldn't find source code, so non-hint tests skipped"
 
diff --git a/src/Test/Translate.hs b/src/Test/Translate.hs
--- a/src/Test/Translate.hs
+++ b/src/Test/Translate.hs
@@ -10,14 +10,13 @@
 import System.Exit
 import System.FilePath
 
-import Paths_hlint
 import Config.Type
 import HSE.All
 import Test.Util
 
 
-runMains :: FilePath -> [String] -> IO ()
-runMains tmpdir xs = (if tmpdir == "" then withTempDir else ($ tmpdir)) $ \dir -> do
+runMains :: FilePath -> FilePath -> [String] -> IO ()
+runMains datadir tmpdir xs = (if tmpdir == "" then withTempDir else ($ tmpdir)) $ \dir -> do
     ms <- forM (zip [1..] xs) $ \(i,x) -> do
         let m = "I" ++ show i
         writeFile (dir </> m <.> "hs") $ replace "module Main" ("module " ++ m) x
@@ -26,21 +25,20 @@
         ["import qualified " ++ m | m <- ms] ++
         ["main = do"] ++
         ["    " ++ m ++ ".main" | m <- ms]
-    dat <- getDataDir
-    res <- system $ "runhaskell -i" ++ dir ++ " -i" ++ dat ++ " Main"
+    res <- system $ "runhaskell -i" ++ dir ++ " -i" ++ datadir ++ " Main"
     replicateM_ (length xs) $ tested $ res == ExitSuccess
 
 
 -- | Given a set of hints, do all the HintRule hints type check
-testTypeCheck :: FilePath -> [[Setting]] -> IO ()
+testTypeCheck :: FilePath -> FilePath -> [[Setting]] -> IO ()
 testTypeCheck = wrap toTypeCheck
 
 -- | Given a set of hints, do all the HintRule hints satisfy QuickCheck
-testQuickCheck :: FilePath -> [[Setting]] -> IO ()
+testQuickCheck :: FilePath -> FilePath -> [[Setting]] -> IO ()
 testQuickCheck = wrap toQuickCheck
 
-wrap :: ([HintRule] -> [String]) -> FilePath -> [[Setting]] -> IO ()
-wrap f tmpdir hints = runMains tmpdir [unlines $ body [x | SettingMatchExp x <- xs] | xs <- hints]
+wrap :: ([HintRule] -> [String]) -> FilePath -> FilePath -> [[Setting]] -> IO ()
+wrap f datadir tmpdir hints = runMains datadir tmpdir [unlines $ body [x | SettingMatchExp x <- xs] | xs <- hints]
     where
         body xs =
             ["{-# LANGUAGE NoMonomorphismRestriction, ExtendedDefaultRules, ScopedTypeVariables, DeriveDataTypeable #-}"
