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