diff --git a/hsimport.cabal b/hsimport.cabal
--- a/hsimport.cabal
+++ b/hsimport.cabal
@@ -1,12 +1,12 @@
 Name:          hsimport
-Version:       0.2.6.5
+Version:       0.2.6.6
 License:       BSD3
 License-file:  LICENSE
 Author:        Daniel Trstenjak
 Maintainer:    daniel.trstenjak@gmail.com
 Build-Type:    Simple
 Category:      Utils
-Cabal-Version: >=1.6
+Cabal-Version: >=1.8
 Synopsis:      A command line program for extending the import list of a Haskell source file.
 Description:   A command line program for extending the import list of a Haskell source file.
 
@@ -57,11 +57,12 @@
                  attoparsec >= 0.10.4.0 && < 0.11,
                  directory >= 1.2.0.1 && < 1.3
 
-Executable hsimport-tests
+test-suite hsimport-tests
   Main-is:       tests/Main.hs
   ghc-options:   -W
+  type:          exitcode-stdio-1.0
   Build-Depends: base >= 3 && < 5,
-                 tasty >= 0.6 && < 0.7,
+                 tasty >= 0.6 && < 0.8,
                  tasty-golden >= 2.2.0.1 && < 2.3,
                  filepath >= 1.3.0.1 && < 1.4,
-                 process >= 1.1.0.2 && < 1.2
+                 hsimport
diff --git a/src/HsImport/Args.hs b/src/HsImport/Args.hs
--- a/src/HsImport/Args.hs
+++ b/src/HsImport/Args.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE DeriveDataTypeable, CPP #-}
 
-module HsImport.Args 
+module HsImport.Args
    ( HsImportArgs(..)
    , hsImportArgs
    ) where
@@ -12,7 +12,7 @@
 import Paths_hsimport (version)
 #endif
 
-data HsImportArgs = HsImportArgs 
+data HsImportArgs = HsImportArgs
    { moduleName    :: String
    , symbolName    :: String
    , qualifiedName :: String
diff --git a/tests/Main.hs b/tests/Main.hs
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -3,9 +3,10 @@
 
 import Test.Tasty
 import Test.Tasty.Golden
-import System.Process
 import System.FilePath
-import Data.List (intercalate)
+import System.IO (hPutStrLn, stderr)
+import HsImport (hsImport, hsImportSpec)
+import qualified HsImport.Args as Args
 
 main = defaultMain tests
 
@@ -73,17 +74,13 @@
    goldenVsFileDiff testName diff goldenFile outputFile command
    where
       command = do
-        handle <- runCommand $ "hsimport " ++ params
-        waitForProcess handle
-        return ()
+         let args = Args.HsImportArgs moduleName symbolName qualifiedName inputFile outputFile
+         spec <- hsImportSpec args
+         case spec of
+              Left error  -> hPutStrLn stderr ("hsimport: " ++ error)
+              Right spec_ -> hsImport spec_
 
       diff ref new = ["diff", "-u", ref, new]
-
-      params      = intercalate " " [moduleParam, symbolParam, qualParam, outputParam, inputFile]
-      moduleParam = "-m '" ++ moduleName ++ "'"
-      symbolParam = if null symbolName then "" else "-s '" ++ symbolName ++ "'"
-      qualParam   = if null qualifiedName then "" else "-q '" ++ qualifiedName ++ "'"
-      outputParam = "-o '" ++ outputFile ++ "'"
 
       goldenFile = "tests" </> "goldenFiles" </> testName <.> "hs"
       outputFile = "tests" </> "outputFiles" </> testName <.> "hs"
