Commit e9056b16 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Remove the #ifdef'ed unit test code from several modules

They have all been moved to tests/UnitTest/
So we don't need so much CPP in the ordinary modules now.
parent f7d0f9c1
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -cpp #-}
{-# OPTIONS_NHC98 -cpp #-}
{-# OPTIONS_JHC -fcpp #-}
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Configuration
......@@ -75,11 +71,6 @@ import Data.Maybe ( catMaybes, maybeToList )
import Data.List ( nub )
import Data.Monoid
#ifdef DEBUG
import Data.List ( (\\) )
import Distribution.ParseUtils
#endif
------------------------------------------------------------------------------
-- | Simplify the condition and return its free variables.
......@@ -450,72 +441,3 @@ biFillInDefaults bi =
bug :: String -> a
bug msg = error $ msg ++ ". Consider this a bug."
------------------------------------------------------------------------------
-- Testing
#ifdef DEBUG
tstTree :: CondTree ConfVar [Int] String
tstTree = CondNode "A" [0]
[ (CNot (Var (Flag (ConfFlag "a"))),
CondNode "B" [1] [],
Nothing)
, (CAnd (Var (Flag (ConfFlag "b"))) (Var (Flag (ConfFlag "c"))),
CondNode "C" [2] [],
Just $ CondNode "D" [3]
[ (Lit True,
CondNode "E" [4] [],
Just $ CondNode "F" [5] []) ])
]
test_simplify = simplifyWithSysParams i386 darwin ("ghc",Version [6,6] []) tstCond
where
tstCond = COr (CAnd (Var (Arch ppc)) (Var (OS darwin)))
(CAnd (Var (Flag (ConfFlag "debug"))) (Var (OS darwin)))
[ppc,i386] = ["ppc","i386"]
[darwin,windows] = ["darwin","windows"]
test_parseCondition = map (runP 1 "test" parseCondition) testConditions
where
testConditions = [ "os(darwin)"
, "arch(i386)"
, "!os(linux)"
, "! arch(ppc)"
, "os(windows) && arch(i386)"
, "os(windows) && arch(i386) && flag(debug)"
, "true && false || false && true" -- should be same
, "(true && false) || (false && true)" -- as this
, "(os(darwin))"
, " ( os ( darwin ) ) "
, "true && !(false || os(plan9))"
, "flag( foo_bar )"
, "flag( foo_O_-_O_bar )"
, "impl ( ghc )"
, "impl( ghc >= 6.6.1 )"
]
test_ppCondTree = render $ ppCondTree tstTree (text . show)
test_simpCondTree = simplifyCondTree env tstTree
where
env x = maybe (Left x) Right (lookup x flags)
flags = [(mkFlag "a",False), (mkFlag "b",False), (mkFlag "c", True)]
mkFlag = Flag . ConfFlag
test_resolveWithFlags = resolveWithFlags dom "os" "arch" ("ghc",Version [6,6] []) [tstTree] check
where
dom = [("a", [False,True]), ("b", [True,False]), ("c", [True,False])]
check ds = let missing = ds \\ avail in
case missing of
[] -> DepOk
_ -> MissingDeps missing
avail = [0,1,3,4]
test_ignoreConditions = ignoreConditions tstTree
#endif
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -cpp #-}
{-# OPTIONS_NHC98 -cpp #-}
{-# OPTIONS_JHC -fcpp #-}
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.ParseUtils
......@@ -77,13 +73,6 @@ import Data.Char (isSpace, isUpper, toLower, isAlphaNum, isSymbol, isDigit)
import Data.Maybe (fromMaybe)
import Data.Tree as Tree (Tree(..), flatten)
#ifdef DEBUG
import Test.HUnit (Test(..), assertBool, Assertion, runTestTT, Counts, assertEqual)
import IO
import System.Environment ( getArgs )
import Control.Monad ( zipWithM_ )
#endif
-- -----------------------------------------------------------------------------
type LineNo = Int
......@@ -625,160 +614,3 @@ showDependency (Dependency name ver) = text name <+> text (showVersionRange ver)
-- and with blank lines replaced by dots for correct re-parsing.
showFreeText :: String -> Doc
showFreeText s = vcat [text (if null l then "." else l) | l <- lines s]
------------------------------------------------------------------------------
-- TESTING
#ifdef DEBUG
test_readFields = case
readFields testFile
of
ParseOk _ x -> x == expectedResult
_ -> False
where
testFile = unlines $
[ "Cabal-version: 3"
, ""
, "Description: This is a test file "
, " with a description longer than two lines. "
, "if os(windows) {"
, " License: You may not use this software"
, " ."
, " If you do use this software you will be seeked and destroyed."
, "}"
, "if os(linux) {"
, " Main-is: foo1 "
, "}"
, ""
, "if os(vista) {"
, " executable RootKit {"
, " Main-is: DRMManager.hs"
, " }"
, "} else {"
, " executable VistaRemoteAccess {"
, " Main-is: VCtrl"
, "}}"
, ""
, "executable Foo-bar {"
, " Main-is: Foo.hs"
, "}"
]
expectedResult =
[ F 1 "cabal-version" "3"
, F 3 "description"
"This is a test file\nwith a description longer than two lines."
, IfBlock 5 "os(windows) "
[ F 6 "license"
"You may not use this software\n\nIf you do use this software you will be seeked and destroyed."
]
[]
, IfBlock 10 "os(linux) "
[ F 11 "main-is" "foo1" ]
[ ]
, IfBlock 14 "os(vista) "
[ Section 15 "executable" "RootKit "
[ F 16 "main-is" "DRMManager.hs"]
]
[ Section 19 "executable" "VistaRemoteAccess "
[F 20 "main-is" "VCtrl"]
]
, Section 23 "executable" "Foo-bar "
[F 24 "main-is" "Foo.hs"]
]
test_readFieldsCompat' = case test_readFieldsCompat of
ParseOk _ fs -> mapM_ (putStrLn . show) fs
x -> putStrLn $ "Failed: " ++ show x
test_readFieldsCompat = readFields testPkgDesc
where
testPkgDesc = unlines [
"-- Required",
"Name: Cabal",
"Version: 0.1.1.1.1-rain",
"License: LGPL",
"License-File: foo",
"Copyright: Free Text String",
"Cabal-version: >1.1.1",
"-- Optional - may be in source?",
"Author: Happy Haskell Hacker",
"Homepage: http://www.haskell.org/foo",
"Package-url: http://www.haskell.org/foo",
"Synopsis: a nice package!",
"Description: a really nice package!",
"Category: tools",
"buildable: True",
"CC-OPTIONS: -g -o",
"LD-OPTIONS: -BStatic -dn",
"Frameworks: foo",
"Tested-with: GHC",
"Stability: Free Text String",
"Build-Depends: haskell-src, HUnit>=1.0.0-rain",
"Other-Modules: Distribution.Package, Distribution.Version,",
" Distribution.Simple.GHCPackageConfig",
"Other-files: file1, file2",
"Extra-Tmp-Files: file1, file2",
"C-Sources: not/even/rain.c, such/small/hands",
"HS-Source-Dirs: src, src2",
"Exposed-Modules: Distribution.Void, Foo.Bar",
"Extensions: OverlappingInstances, TypeSynonymInstances",
"Extra-Libraries: libfoo, bar, bang",
"Extra-Lib-Dirs: \"/usr/local/libs\"",
"Include-Dirs: your/slightest, look/will",
"Includes: /easily/unclose, /me, \"funky, path\\\\name\"",
"Install-Includes: /easily/unclose, /me, \"funky, path\\\\name\"",
"GHC-Options: -fTH -fglasgow-exts",
"Hugs-Options: +TH",
"Nhc-Options: ",
"Jhc-Options: ",
"",
"-- Next is an executable",
"Executable: somescript",
"Main-is: SomeFile.hs",
"Other-Modules: Foo1, Util, Main",
"HS-Source-Dir: scripts",
"Extensions: OverlappingInstances",
"GHC-Options: ",
"Hugs-Options: ",
"Nhc-Options: ",
"Jhc-Options: "
]
{-
test' = do h <- openFile "../Cabal.cabal" ReadMode
s <- hGetContents h
let r = readFields s
case r of
ParseOk _ fs -> mapM_ (putStrLn . show) fs
x -> putStrLn $ "Failed: " ++ show x
putStrLn "==================="
mapM_ (putStrLn . show) $
merge . zip [1..] . lines $ s
hClose h
-}
-- ghc -DDEBUG --make Distribution/ParseUtils.hs -o test
main :: IO ()
main = do
inputFiles <- getArgs
ok <- mapM checkResult inputFiles
zipWithM_ summary inputFiles ok
putStrLn $ show (length (filter not ok)) ++ " out of " ++ show (length ok) ++ " failed"
where summary f True = return ()
summary f False = putStrLn $ f ++ " failed :-("
checkResult :: FilePath -> IO Bool
checkResult inputFile = do
file <- readTextFile inputFile
case readFields file of
ParseOk _ result -> do
hPutStrLn stderr $ inputFile ++ " parses ok :-)"
return True
ParseFailed err -> do
hPutStrLn stderr $ inputFile ++ " parse failed:"
hPutStrLn stderr $ show err
return False
--
#endif
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -cpp #-}
{-# OPTIONS_NHC98 -cpp #-}
{-# OPTIONS_JHC -fcpp #-}
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Version
......@@ -63,9 +59,6 @@ module Distribution.Version (
-- * Dependencies
Dependency(..),
#ifdef DEBUG
hunitTests
#endif
) where
import Data.Version ( Version(..), showVersion )
......@@ -76,10 +69,6 @@ import Data.Maybe ( listToMaybe )
import Distribution.Compat.ReadP
#ifdef DEBUG
import Test.HUnit
#endif
-- -----------------------------------------------------------------------------
-- Version utils
......@@ -203,76 +192,3 @@ parseVersionRange = do
(">", LaterVersion),
(">=", orLaterVersion),
("==", ThisVersion) ]
#ifdef DEBUG
-- ------------------------------------------------------------
-- * Testing
-- ------------------------------------------------------------
-- |Simple version parser wrapper
doVersionParse :: String -> Either String Version
doVersionParse input = case results of
[y] -> Right y
[] -> Left "No parse"
_ -> Left "Ambigous parse"
where results = [ x | (x,"") <- readP_to_S parseVersion input ]
branch1 :: [Int]
branch1 = [1]
branch2 :: [Int]
branch2 = [1,2]
branch3 :: [Int]
branch3 = [1,2,3]
release1 :: Version
release1 = Version{versionBranch=branch1, versionTags=[]}
release2 :: Version
release2 = Version{versionBranch=branch2, versionTags=[]}
release3 :: Version
release3 = Version{versionBranch=branch3, versionTags=[]}
hunitTests :: [Test]
hunitTests
= [
"released version 1" ~: "failed"
~: (Right $ release1) ~=? doVersionParse "1",
"released version 3" ~: "failed"
~: (Right $ release3) ~=? doVersionParse "1.2.3",
"range comparison LaterVersion 1" ~: "failed"
~: True
~=? release3 `withinRange` (LaterVersion release2),
"range comparison LaterVersion 2" ~: "failed"
~: False
~=? release2 `withinRange` (LaterVersion release3),
"range comparison EarlierVersion 1" ~: "failed"
~: True
~=? release3 `withinRange` (LaterVersion release2),
"range comparison EarlierVersion 2" ~: "failed"
~: False
~=? release2 `withinRange` (LaterVersion release3),
"range comparison orLaterVersion 1" ~: "failed"
~: True
~=? release3 `withinRange` (orLaterVersion release3),
"range comparison orLaterVersion 2" ~: "failed"
~: True
~=? release3 `withinRange` (orLaterVersion release2),
"range comparison orLaterVersion 3" ~: "failed"
~: False
~=? release2 `withinRange` (orLaterVersion release3),
"range comparison orEarlierVersion 1" ~: "failed"
~: True
~=? release2 `withinRange` (orEarlierVersion release2),
"range comparison orEarlierVersion 2" ~: "failed"
~: True
~=? release2 `withinRange` (orEarlierVersion release3),
"range comparison orEarlierVersion 3" ~: "failed"
~: False
~=? release3 `withinRange` (orEarlierVersion release2)
]
#endif
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