Commit 32edf8f3 authored by ijones's avatar ijones
Browse files

added unit tests to each module

Added unit tests to everthing
ModuleTest imports them all, runs them
Many of them are empty, however.
Some still export IO [Test] which they should rather export [test].
must fix :)
parent 00aef344
{-# OPTIONS -cpp -DDEBUG #-}
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Distribution.Misc -- Module : Distribution.Misc
...@@ -41,11 +42,19 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ...@@ -41,11 +42,19 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -} OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Misc(License(..), Dependency, Extension, Opt) module Distribution.Misc(License(..), Dependency, Extension, Opt
#ifdef DEBUG
,hunitTests
#endif
)
where where
import Distribution.Version(VersionRange) import Distribution.Version(VersionRange)
#ifdef DEBUG
import HUnit (Test)
#endif
-- ------------------------------------------------------------ -- ------------------------------------------------------------
-- * Misc -- * Misc
-- ------------------------------------------------------------ -- ------------------------------------------------------------
...@@ -64,3 +73,12 @@ data Dependency = Dependency String VersionRange ...@@ -64,3 +73,12 @@ data Dependency = Dependency String VersionRange
data Extension = Foo | Bar deriving Show data Extension = Foo | Bar deriving Show
type Opt = String type Opt = String
-- ------------------------------------------------------------
-- * Testing
-- ------------------------------------------------------------
#ifdef DEBUG
hunitTests :: [Test]
hunitTests = []
#endif
...@@ -46,24 +46,24 @@ module Main where ...@@ -46,24 +46,24 @@ module Main where
-- Import everything, since we want to test the compilation of them: -- Import everything, since we want to test the compilation of them:
import Distribution.Version() import qualified Distribution.Version as D.V (hunitTests)
import Distribution.InstalledPackageInfo() -- import qualified Distribution.InstalledPackageInfo(hunitTests)
import Distribution.Misc() import qualified Distribution.Misc as D.M (hunitTests)
import Distribution.Package() import qualified Distribution.Package as D.P (hunitTests)
import qualified Distribution.Setup(hunitTests) import qualified Distribution.Setup (hunitTests)
import Distribution.Simple() import qualified Distribution.Simple as D.S (simpleHunitTests)
import Distribution.Simple.Install() import qualified Distribution.Simple.Install as D.S.I (hunitTests)
import Distribution.Simple.Build() import qualified Distribution.Simple.Build as D.S.B (hunitTests)
import Distribution.Simple.SrcDist() import qualified Distribution.Simple.SrcDist as D.S.S (hunitTests)
import qualified Distribution.Simple.Utils(hunitTests) import qualified Distribution.Simple.Utils as D.S.U (hunitTests)
import Distribution.Simple.Configure() import qualified Distribution.Simple.Configure as D.S.C (hunitTests)
import Distribution.Simple.Register() import qualified Distribution.Simple.Register as D.S.R (hunitTests)
-- base -- base
import Control.Monad(when) import Control.Monad(when)
import Directory(setCurrentDirectory, doesFileExist, import Directory(setCurrentDirectory, doesFileExist,
doesDirectoryExist, removeDirectory) doesDirectoryExist)
import System.Cmd(system) import System.Cmd(system)
import System.Exit(ExitCode(..)) import System.Exit(ExitCode(..))
...@@ -78,6 +78,7 @@ runTestTT' (TestLabel l t) ...@@ -78,6 +78,7 @@ runTestTT' (TestLabel l t)
= putStrLn (label l) >> runTestTT t = putStrLn (label l) >> runTestTT t
runTestTT' t = runTestTT t runTestTT' t = runTestTT t
tests :: [Test]
tests = [TestCase $ tests = [TestCase $
do setCurrentDirectory "test" do setCurrentDirectory "test"
dirE1 <- doesDirectoryExist ",tmp" dirE1 <- doesDirectoryExist ",tmp"
...@@ -103,11 +104,20 @@ main :: IO () ...@@ -103,11 +104,20 @@ main :: IO ()
main = do putStrLn "compile successful" main = do putStrLn "compile successful"
putStrLn "-= Setup Tests =-" putStrLn "-= Setup Tests =-"
setupTests <- Distribution.Setup.hunitTests setupTests <- Distribution.Setup.hunitTests
confTests <- D.S.C.hunitTests
utilTests <- D.S.U.hunitTests
mapM runTestTT' setupTests mapM runTestTT' setupTests
Distribution.Simple.Utils.hunitTests >>= runTestTT' mapM runTestTT' confTests
runTestTT' utilTests
runTestTT' $ TestList (D.S.R.hunitTests ++ D.V.hunitTests ++
D.S.S.hunitTests ++ D.S.B.hunitTests ++
D.S.I.hunitTests ++ D.S.simpleHunitTests ++
D.P.hunitTests ++ D.M.hunitTests)
runTestTT' $ TestList tests runTestTT' $ TestList tests
return () return ()
-- Local Variables: -- Local Variables:
-- compile-command: "ghc -i../:/usr/local/src/HUnit-1.0 -Wall --make ModuleTest.hs -o moduleTest" -- compile-command: "ghc -i../:/usr/local/src/HUnit-1.0 -Wall --make ModuleTest.hs -o moduleTest"
-- End: -- End:
{-# OPTIONS -cpp -DDEBUG #-}
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Distribution.Package -- Module : Distribution.Package
...@@ -45,13 +46,20 @@ module Distribution.Package ( ...@@ -45,13 +46,20 @@ module Distribution.Package (
PackageIdentifier(..), PackageIdentifier(..),
showPackageId, showPackageId,
PackageDescription(..), PackageDescription(..),
emptyPackageDescription emptyPackageDescription,
#ifdef DEBUG
hunitTests
#endif
) where ) where
import Distribution.Version(Version, showVersion) import Distribution.Version(Version, showVersion)
import Distribution.Misc(License(..), Dependency, Extension) import Distribution.Misc(License(..), Dependency, Extension)
import Distribution.Setup(CompilerFlavor) import Distribution.Setup(CompilerFlavor)
#ifdef DEBUG
import HUnit (Test)
#endif
data PackageIdentifier data PackageIdentifier
= PackageIdentifier {pkgName::String, pkgVersion::Version} = PackageIdentifier {pkgName::String, pkgVersion::Version}
deriving (Read, Show, Eq) deriving (Read, Show, Eq)
...@@ -107,3 +115,10 @@ emptyPackageDescription ...@@ -107,3 +115,10 @@ emptyPackageDescription
includes = [], includes = [],
options = [] options = []
} }
-- ------------------------------------------------------------
-- * Testing
-- ------------------------------------------------------------
#ifdef DEBUG
hunitTests :: [Test]
hunitTests = []
#endif
...@@ -75,9 +75,6 @@ data Compiler = Compiler {compilerFlavor:: CompilerFlavor, ...@@ -75,9 +75,6 @@ data Compiler = Compiler {compilerFlavor:: CompilerFlavor,
compilerPkgTool :: FilePath} compilerPkgTool :: FilePath}
deriving (Show, Read, Eq) deriving (Show, Read, Eq)
emptyCompiler :: Compiler
emptyCompiler = Compiler (OtherCompiler "") "" ""
type CommandLineOpts = (Action, type CommandLineOpts = (Action,
[String]) -- The un-parsed remainder [String]) -- The un-parsed remainder
......
{-# OPTIONS -cpp -DDEBUG #-}
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Distribution.Simple -- Module : Distribution.Simple
...@@ -45,6 +46,9 @@ module Distribution.Simple ( ...@@ -45,6 +46,9 @@ module Distribution.Simple (
module Distribution.Package, module Distribution.Package,
License(..), Version(..), License(..), Version(..),
defaultMain, defaultMain,
#ifdef DEBUG
simpleHunitTests
#endif
) where ) where
-- local -- local
...@@ -70,6 +74,10 @@ import Data.Maybe(isNothing) ...@@ -70,6 +74,10 @@ import Data.Maybe(isNothing)
import Data.List ( intersperse ) import Data.List ( intersperse )
import System.IO (hPutStr, stderr) import System.IO (hPutStr, stderr)
#ifdef DEBUG
import HUnit (Test)
#endif
-- |Reads local build info, executes function -- |Reads local build info, executes function
doBuildInstall :: (PackageDescription -> LocalBuildInfo -> IO ()) -- ^function to apply doBuildInstall :: (PackageDescription -> LocalBuildInfo -> IO ()) -- ^function to apply
-> PackageDescription -> PackageDescription
...@@ -127,3 +135,11 @@ no_extra_flags extra_flags = ...@@ -127,3 +135,11 @@ no_extra_flags extra_flags =
helpprefix :: String helpprefix :: String
helpprefix = "Syntax: ./Setup.hs command [flags]\n" helpprefix = "Syntax: ./Setup.hs command [flags]\n"
-- ------------------------------------------------------------
-- * Testing
-- ------------------------------------------------------------
#ifdef DEBUG
simpleHunitTests :: [Test]
simpleHunitTests = []
#endif
...@@ -42,6 +42,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -} ...@@ -42,6 +42,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Simple.Build ( module Distribution.Simple.Build (
build build
#ifdef DEBUG
,hunitTests
#endif
) where ) where
import Distribution.Misc (Extension) import Distribution.Misc (Extension)
...@@ -56,6 +59,10 @@ import Distribution.Simple.Utils (rawSystemExit, setupMessage, ...@@ -56,6 +59,10 @@ import Distribution.Simple.Utils (rawSystemExit, setupMessage,
import Control.Monad (when) import Control.Monad (when)
import Data.List(intersperse) import Data.List(intersperse)
#ifdef DEBUG
import HUnit (Test)
#endif
-- ----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
-- Build the library -- Build the library
...@@ -125,3 +132,12 @@ dotToSep :: String -> String ...@@ -125,3 +132,12 @@ dotToSep :: String -> String
dotToSep s = concat $ intersperse pathSeperatorStr (split '.' s) dotToSep s = concat $ intersperse pathSeperatorStr (split '.' s)
-- Todo: includes, includeDirs -- Todo: includes, includeDirs
-- ------------------------------------------------------------
-- * Testing
-- ------------------------------------------------------------
#ifdef DEBUG
hunitTests :: [Test]
hunitTests = []
#endif
...@@ -45,12 +45,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -} ...@@ -45,12 +45,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Simple.Configure (writePersistBuildConfig, module Distribution.Simple.Configure (writePersistBuildConfig,
getPersistBuildConfig, getPersistBuildConfig,
LocalBuildInfo(..), LocalBuildInfo(..),
configure) configure,
hunitTests
)
where where
import Distribution.Setup(ConfigFlags,CompilerFlavor(..), Compiler(..)) import Distribution.Setup(ConfigFlags,CompilerFlavor(..), Compiler(..))
import Distribution.Package(PackageDescription(..)) import Distribution.Package(PackageDescription(..))
import Distribution.Simple.Utils import Distribution.Simple.Utils (die, setupMessage,
findBinary, splitFilenameDir)
import Distribution.Package ( PackageIdentifier ) import Distribution.Package ( PackageIdentifier )
import System.IO hiding (catch) import System.IO hiding (catch)
......
{-# OPTIONS -cpp #-} {-# OPTIONS -cpp -DDEBUG #-}
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Distribution.Simple.Install -- Module : Distribution.Simple.Install
...@@ -45,12 +45,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -} ...@@ -45,12 +45,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Simple.Install ( module Distribution.Simple.Install (
install, install,
mkImportDir, mkImportDir,
#ifdef DEBUG
,hunitTests
#endif
) where ) where
import Distribution.Package (PackageDescription(..), showPackageId) import Distribution.Package (PackageDescription(..), showPackageId)
import Distribution.Simple.Configure(LocalBuildInfo(..)) import Distribution.Simple.Configure(LocalBuildInfo(..))
import Distribution.Simple.Utils(setupMessage, moveSources, pathSeperatorStr) import Distribution.Simple.Utils(setupMessage, moveSources, pathSeperatorStr)
#ifdef DEBUG
import HUnit (Test)
#endif
-- |FIX: for now, only works with hugs or sdist-style -- |FIX: for now, only works with hugs or sdist-style
-- installation... must implement for .hi files and such... how do we -- installation... must implement for .hi files and such... how do we
-- know which files to expect? -- know which files to expect?
...@@ -76,3 +83,11 @@ mkImportDir pkg_descr lbi = ...@@ -76,3 +83,11 @@ mkImportDir pkg_descr lbi =
#endif #endif
where where
pkg_name = showPackageId (package pkg_descr) pkg_name = showPackageId (package pkg_descr)
-- ------------------------------------------------------------
-- * Testing
-- ------------------------------------------------------------
#ifdef DEBUG
hunitTests :: [Test]
hunitTests = []
#endif
{-# OPTIONS -cpp -DDEBUG #-}
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Distribution.Simple.Register -- Module : Distribution.Simple.Register
...@@ -44,6 +45,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -} ...@@ -44,6 +45,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Simple.Register ( module Distribution.Simple.Register (
register, register,
unregister, unregister,
#ifdef DEBUG
hunitTests
#endif
) where ) where
import Distribution.Simple.Configure (LocalBuildInfo, compiler) import Distribution.Simple.Configure (LocalBuildInfo, compiler)
...@@ -56,6 +60,10 @@ import System(getEnv) ...@@ -56,6 +60,10 @@ import System(getEnv)
import Control.Monad (when) import Control.Monad (when)
#ifdef DEBUG
import HUnit (Test)
#endif
-- ----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
-- Registration -- Registration
...@@ -89,3 +97,13 @@ unregister pkg_descr lbi = do ...@@ -89,3 +97,13 @@ unregister pkg_descr lbi = do
rawSystemExit (compilerPkgTool (compiler lbi)) rawSystemExit (compilerPkgTool (compiler lbi))
["--remove-package=" ++ showPackageId (package pkg_descr)] ["--remove-package=" ++ showPackageId (package pkg_descr)]
-- ------------------------------------------------------------
-- * Testing
-- ------------------------------------------------------------
#ifdef DEBUG
hunitTests :: [Test]
hunitTests = []
#endif
{-# OPTIONS -cpp -DDEBUG #-}
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Distribution.Simple.SrcDist -- Module : Distribution.Simple.SrcDist
...@@ -41,6 +42,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -} ...@@ -41,6 +42,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Simple.SrcDist ( module Distribution.Simple.SrcDist (
sdist sdist
#ifdef DEBUG
,hunitTests
#endif
) where ) where
import Distribution.Package(PackageDescription(..), showPackageId) import Distribution.Package(PackageDescription(..), showPackageId)
...@@ -49,6 +53,10 @@ import Distribution.Simple.Utils(setupMessage, moveSources, pathSeperatorStr) ...@@ -49,6 +53,10 @@ import Distribution.Simple.Utils(setupMessage, moveSources, pathSeperatorStr)
import System.Cmd (system) import System.Cmd (system)
#ifdef DEBUG
import HUnit (Test)
#endif
-- |Create a source distribution. FIX: Calls tar directly (won't work -- |Create a source distribution. FIX: Calls tar directly (won't work
-- on windows). -- on windows).
sdist :: PackageDescription -> LocalBuildInfo -> IO () sdist :: PackageDescription -> LocalBuildInfo -> IO ()
...@@ -73,3 +81,12 @@ tarBallName p = (nameVersion p) ++ ".tgz" ...@@ -73,3 +81,12 @@ tarBallName p = (nameVersion p) ++ ".tgz"
nameVersion :: PackageDescription -> String nameVersion :: PackageDescription -> String
nameVersion = showPackageId . package nameVersion = showPackageId . package
-- ------------------------------------------------------------
-- * Testing
-- ------------------------------------------------------------
#ifdef DEBUG
hunitTests :: [Test]
hunitTests = []
#endif
...@@ -58,7 +58,7 @@ module Distribution.Simple.Utils ( ...@@ -58,7 +58,7 @@ module Distribution.Simple.Utils (
createIfNotExists createIfNotExists
) where ) where
import Distribution.Package import Distribution.Package (PackageDescription(..), showPackageId)
import Control.Monad(when) import Control.Monad(when)
import Data.List(inits, nub, intersperse, findIndices) import Data.List(inits, nub, intersperse, findIndices)
...@@ -284,6 +284,7 @@ moveSources _targetDir sources mains ...@@ -284,6 +284,7 @@ moveSources _targetDir sources mains
-- * Testing -- * Testing
-- ------------------------------------------------------------ -- ------------------------------------------------------------
#ifdef DEBUG
hunitTests :: IO Test hunitTests :: IO Test
hunitTests hunitTests
= do mp1 <- moduleToFilePath "Distribution.Simple.Build" --exists = do mp1 <- moduleToFilePath "Distribution.Simple.Build" --exists
...@@ -301,3 +302,4 @@ hunitTests ...@@ -301,3 +302,4 @@ hunitTests
(Just "Distribution/Simple/Build.hs") ~=? mp1, (Just "Distribution/Simple/Build.hs") ~=? mp1,
"not existing not nothing" ~: "failed" ~: Nothing ~=? mp2 "not existing not nothing" ~: "failed" ~: Nothing ~=? mp2
] ]
#endif
...@@ -55,6 +55,7 @@ module Distribution.Version ( ...@@ -55,6 +55,7 @@ module Distribution.Version (
withinRange, withinRange,
showVersionRange, showVersionRange,
parseVersionRange, parseVersionRange,
hunitTests
) where ) where
import Data.List ( intersperse ) import Data.List ( intersperse )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment