Commit 770ce717 authored by rubbernecking.trumpet.stephen's avatar rubbernecking.trumpet.stephen
Browse files

Ticket #89 final: Regression tests for new dependency behaviour.

parent cdde4ce4
......@@ -5,7 +5,7 @@ import PackageTests.PackageTester
import Control.Monad
import System.FilePath
import Data.Version
import Data.List (isInfixOf)
import Data.List (isInfixOf, intercalate)
suite :: Version -> Test
......@@ -13,8 +13,8 @@ suite cabalVersion = TestCase $ do
let spec = PackageSpec ("PackageTests" </> "BuildDeps" </> "InternalLibrary0") []
result <- cabal_build spec
assertEqual "cabal build should fail" False (successful result)
{-when (cabalVersion >= Version [1, 7] []) $ do
when (cabalVersion >= Version [1, 7] []) $ do
-- In 1.7 it should tell you how to enable the desired behaviour.
assertEqual "error should say 'refers to an internally defined library'" True $
"refers to an internally defined library" `isInfixOf` (outputText result)-}
assertEqual "error should say 'library which is defined within the same package.'" True $
"library which is defined within the same package." `isInfixOf` (intercalate " " $ lines $ outputText result)
module PackageTests.BuildDeps.InternalLibrary1.Check where
import Test.HUnit
import PackageTests.PackageTester
import System.FilePath
suite :: Test
suite = TestCase $ do
let spec = PackageSpec ("PackageTests" </> "BuildDeps" </> "InternalLibrary1") []
result <- cabal_build spec
assertEqual "cabal build should succeed - see test-log.txt" True (successful result)
module MyLibrary where
import qualified Data.ByteString.Char8 as C
import System.Time
myLibFunc :: IO ()
myLibFunc = do
getClockTime
let text = "myLibFunc"
C.putStrLn $ C.pack text
import Distribution.Simple
main = defaultMain
name: InternalLibrary1
version: 0.1
license: BSD3
cabal-version: >= 1.7.1
author: Stephen Blackheath
stability: stable
category: PackageTests
build-type: Simple
description:
Check for the new (in >= 1.7.1) ability to allow executables to refer to
the library defined in the same module.
---------------------------------------
Library
exposed-modules: MyLibrary
build-depends: base, bytestring, old-time
Executable lemon
main-is: lemon.hs
hs-source-dirs: programs
build-depends: base, bytestring, old-time, InternalLibrary1
import System.Time
import MyLibrary
main = do
getClockTime
myLibFunc
module PackageTests.BuildDeps.InternalLibrary2.Check where
import Test.HUnit
import PackageTests.PackageTester
import System.FilePath
import qualified Data.ByteString.Char8 as C
suite :: Test
suite = TestCase $ do
let spec = PackageSpec ("PackageTests" </> "BuildDeps" </> "InternalLibrary2") []
let specTI = PackageSpec (directory spec </> "to-install") []
unregister "InternalLibrary2"
iResult <- cabal_install specTI
assertEqual "cabal install should succeed - see to-install/test-log.txt" True (successful iResult)
bResult <- cabal_build spec
assertEqual "cabal build should succeed - see test-log.txt" True (successful bResult)
unregister "InternalLibrary2"
(_, _, output) <- run (Just $ directory spec) "dist/build/lemon/lemon" []
C.appendFile (directory spec </> "test-log.txt") (C.pack $ "\ndist/build/lemon/lemon\n"++output)
assertEqual "executable should have linked with the internal library" "myLibFunc internal" (concat $ lines output)
module MyLibrary where
import qualified Data.ByteString.Char8 as C
import System.Time
myLibFunc :: IO ()
myLibFunc = do
getClockTime
let text = "myLibFunc internal"
C.putStrLn $ C.pack text
import Distribution.Simple
main = defaultMain
name: InternalLibrary2
version: 0.1
license: BSD3
cabal-version: >= 1.7.1
author: Stephen Blackheath
stability: stable
category: PackageTests
build-type: Simple
description:
This test is to make sure that the internal library is preferred by ghc to
an installed one of the same name and version.
---------------------------------------
Library
exposed-modules: MyLibrary
build-depends: base, bytestring, old-time
Executable lemon
main-is: lemon.hs
hs-source-dirs: programs
build-depends: base, bytestring, old-time, InternalLibrary2
import System.Time
import MyLibrary
main = do
getClockTime
myLibFunc
module MyLibrary where
import qualified Data.ByteString.Char8 as C
import System.Time
myLibFunc :: IO ()
myLibFunc = do
getClockTime
let text = "myLibFunc installed"
C.putStrLn $ C.pack text
import Distribution.Simple
main = defaultMain
name: InternalLibrary2
version: 0.1
license: BSD3
cabal-version: >= 1.6
author: Stephen Blackheath
stability: stable
category: PackageTests
build-type: Simple
description:
This test is to make sure that the internal library is preferred by ghc to
an installed one of the same name and version.
---------------------------------------
Library
exposed-modules: MyLibrary
build-depends: base, bytestring, old-time
module PackageTests.BuildDeps.InternalLibrary3.Check where
import Test.HUnit
import PackageTests.PackageTester
import System.FilePath
import qualified Data.ByteString.Char8 as C
suite :: Test
suite = TestCase $ do
let spec = PackageSpec ("PackageTests" </> "BuildDeps" </> "InternalLibrary3") []
let specTI = PackageSpec (directory spec </> "to-install") []
unregister "InternalLibrary3"
iResult <- cabal_install specTI
assertEqual "cabal install should succeed - see to-install/test-log.txt" True (successful iResult)
bResult <- cabal_build spec
assertEqual "cabal build should succeed - see test-log.txt" True (successful bResult)
unregister "InternalLibrary3"
(_, _, output) <- run (Just $ directory spec) "dist/build/lemon/lemon" []
C.appendFile (directory spec </> "test-log.txt") (C.pack $ "\ndist/build/lemon/lemon\n"++output)
assertEqual "executable should have linked with the internal library" "myLibFunc internal" (concat $ lines output)
module MyLibrary where
import qualified Data.ByteString.Char8 as C
import System.Time
myLibFunc :: IO ()
myLibFunc = do
getClockTime
let text = "myLibFunc internal"
C.putStrLn $ C.pack text
import Distribution.Simple
main = defaultMain
name: InternalLibrary3
version: 0.1
license: BSD3
cabal-version: >= 1.7.1
author: Stephen Blackheath
stability: stable
category: PackageTests
build-type: Simple
description:
This test is to make sure that the internal library is preferred by ghc to
an installed one of the same name, but a *newer* version.
---------------------------------------
Library
exposed-modules: MyLibrary
build-depends: base, bytestring, old-time
Executable lemon
main-is: lemon.hs
hs-source-dirs: programs
build-depends: base, bytestring, old-time, InternalLibrary3
import System.Time
import MyLibrary
main = do
getClockTime
myLibFunc
module MyLibrary where
import qualified Data.ByteString.Char8 as C
import System.Time
myLibFunc :: IO ()
myLibFunc = do
getClockTime
let text = "myLibFunc installed"
C.putStrLn $ C.pack text
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