Skip to content

Commit

Permalink
Tests for internal libraries (haskell#269) and separate cabal_macros.h (
Browse files Browse the repository at this point in the history
haskell#1893)

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
  • Loading branch information
ezyang committed Feb 2, 2016
1 parent e8d9b28 commit ccf5d8d
Show file tree
Hide file tree
Showing 22 changed files with 255 additions and 39 deletions.
32 changes: 24 additions & 8 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,30 @@ extra-source-files:
tests/PackageTests/HaddockNewline/A.hs
tests/PackageTests/HaddockNewline/HaddockNewline.cabal
tests/PackageTests/HaddockNewline/Setup.hs
tests/PackageTests/MultipleLibraries/p.cabal
tests/PackageTests/MultipleLibraries/p/P.hs
tests/PackageTests/MultipleLibraries/p/Foo.hs
tests/PackageTests/MultipleLibraries/p/p.cabal
tests/PackageTests/MultipleLibraries/p/p/P.hs
tests/PackageTests/MultipleLibraries/p/q/Q.hs
tests/PackageTests/MultipleLibraries/q/Q.hs
tests/PackageTests/MultipleLibraries/q/q.cabal
tests/PackageTests/InternalLibraries/Executable/dist-test.Dynamic/test.sh
tests/PackageTests/InternalLibraries/Executable/dist-test.Static/test.sh
tests/PackageTests/InternalLibraries/Executable/exe/Main.hs
tests/PackageTests/InternalLibraries/Executable/foo.cabal
tests/PackageTests/InternalLibraries/Executable/src/Foo.hs
tests/PackageTests/InternalLibraries/Library/dist-test/test.sh
tests/PackageTests/InternalLibraries/Library/fooexe/Main.hs
tests/PackageTests/InternalLibraries/Library/fooexe/fooexe.cabal
tests/PackageTests/InternalLibraries/Library/foolib/Foo.hs
tests/PackageTests/InternalLibraries/Library/foolib/foolib.cabal
tests/PackageTests/InternalLibraries/Library/foolib/private/Internal.hs
tests/PackageTests/InternalLibraries/dist-test/test.sh
tests/PackageTests/InternalLibraries/p/Foo.hs
tests/PackageTests/InternalLibraries/p/p.cabal
tests/PackageTests/InternalLibraries/p/p/P.hs
tests/PackageTests/InternalLibraries/p/q/Q.hs
tests/PackageTests/InternalLibraries/q/Q.hs
tests/PackageTests/InternalLibraries/q/q.cabal
tests/PackageTests/Macros/A.hs
tests/PackageTests/Macros/B.hs
tests/PackageTests/Macros/Main.hs
tests/PackageTests/Macros/dist-test/test.sh
tests/PackageTests/Macros/macros.cabal
tests/PackageTests/Macros/src/C.hs
tests/PackageTests/OrderFlags/Foo.hs
tests/PackageTests/OrderFlags/my.cabal
tests/PackageTests/PathsModule/Executable/Main.hs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Foo
main = print (foo 23)
18 changes: 18 additions & 0 deletions Cabal/tests/PackageTests/InternalLibraries/Executable/foo.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: foo
version: 0.1.0.0
license: BSD3
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
build-type: Simple
cabal-version: >=1.23

library foo-internal
exposed-modules: Foo
build-depends: base
hs-source-dirs: src
default-language: Haskell2010

executable foo
main-is: Main.hs
build-depends: base, foo-internal
hs-source-dirs: exe
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Foo where
{-# NOINLINE foo #-}
foo :: Int -> Int
foo x = x + 23
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Foo

main :: IO ()
main = print foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: fooexe
version: 0.1.0.0
license: BSD3
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
build-type: Simple
cabal-version: >=1.10

executable fooexe
main-is: Main.hs
build-depends: base, foolib
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Foo where
import Internal
foo = internal + 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: foolib
version: 0.1.0.0
license: BSD3
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
build-type: Simple
cabal-version: >=1.23

library foolib-internal
exposed-modules: Internal
hs-source-dirs: private
build-depends: base

library
exposed-modules: Foo
build-depends: base, foolib-internal
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Internal where
{-# NOINLINE internal #-}
internal :: Int
internal = 23
10 changes: 10 additions & 0 deletions Cabal/tests/PackageTests/Macros/A.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{-# LANGUAGE CPP #-}
import C
#ifdef VERSION_filepath
#error "Should not see macro from library"
#endif
#ifdef VERSION_containers
#error "Should not see macro from executable macros-b"
#endif
main = do
putStrLn CURRENT_COMPONENT_ID
10 changes: 10 additions & 0 deletions Cabal/tests/PackageTests/Macros/B.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{-# LANGUAGE CPP #-}
import C
#ifdef VERSION_filepath
#error "Should not see macro from library"
#endif
#ifdef VERSION_deepseq
#error "Should not see macro from executable macros-a"
#endif
main = do
putStrLn CURRENT_COMPONENT_ID
4 changes: 4 additions & 0 deletions Cabal/tests/PackageTests/Macros/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = putStrLn "Hello, Haskell!"
23 changes: 23 additions & 0 deletions Cabal/tests/PackageTests/Macros/macros.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: macros
version: 0.1.0.0
license: BSD3
license-file: LICENSE
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
build-type: Simple
cabal-version: >=1.10

library macros
exposed-modules: C
hs-source-dirs: src
build-depends: base, filepath

executable macros-a
main-is: A.hs
build-depends: base, deepseq, macros
default-language: Haskell2010

executable macros-b
main-is: B.hs
build-depends: base, containers, macros
default-language: Haskell2010
10 changes: 10 additions & 0 deletions Cabal/tests/PackageTests/Macros/src/C.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{-# LANGUAGE CPP #-}
module C where
#ifdef VERSION_deepseq
#error "Should not see macro from executable macros-a"
#endif
#ifdef VERSION_containers
#error "Should not see macro from executable macros-b"
#endif
c :: String
c = CURRENT_COMPONENT_ID
29 changes: 21 additions & 8 deletions Cabal/tests/PackageTests/PackageTester.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module PackageTests.PackageTester
, run
, runExe
, runExe'
, runInstalledExe
, runInstalledExe'
, rawRun
, rawCompileSetup
, withPackage
Expand Down Expand Up @@ -66,7 +68,7 @@ import Distribution.Simple.Configure
import Distribution.Verbosity (Verbosity)
import Distribution.Simple.BuildPaths (exeExtension)

#ifndef CURRENT_COMPONENT_ID
#ifndef LOCAL_COMPONENT_ID
import Distribution.Simple.Utils (cabalVersion)
import Distribution.Text (display)
#endif
Expand Down Expand Up @@ -267,7 +269,7 @@ cabal' cmd extraArgs0 = do
-- Would really like to do this, but we're not always
-- going to be building against sufficiently recent
-- Cabal which provides this macro.
-- , "--dependency=Cabal=" ++ THIS_PACKAGE_KEY
-- , "--dependency=Cabal=" ++ LOCAL_COMPONENT_ID
-- These flags make the test suite run faster
-- Can't do this unless we LD_LIBRARY_PATH correctly
-- , "--enable-executable-dynamic"
Expand Down Expand Up @@ -340,10 +342,10 @@ rawCompileSetup verbosity suite e path = do
ghcPackageDBParams (ghcVersion suite) (packageDBStack suite) ++
[ "-hide-all-packages"
, "-package base"
#ifdef CURRENT_COMPONENT_ID
#ifdef LOCAL_COMPONENT_ID
-- This is best, but we don't necessarily have it
-- if we're bootstrapping with old Cabal.
, "-package-id " ++ CURRENT_COMPONENT_ID
, "-package-id " ++ LOCAL_COMPONENT_ID
#else
-- This mostly works, UNLESS you've installed a
-- version of Cabal with the SAME version number.
Expand Down Expand Up @@ -421,6 +423,17 @@ runExe' exe_name args = do
let exe = dist_dir </> "build" </> exe_name </> exe_name
run Nothing exe args

-- | Run an executable that was installed by cabal. The @exe_name@
-- is precisely the name of the executable.
runInstalledExe :: String -> [String] -> TestM ()
runInstalledExe exe_name args = void (runInstalledExe' exe_name args)

runInstalledExe' :: String -> [String] -> TestM Result
runInstalledExe' exe_name args = do
usr <- prefixDir
let exe = usr </> "bin" </> exe_name
run Nothing exe args

run :: Maybe FilePath -> String -> [String] -> TestM Result
run mb_cwd path args = do
verbosity <- getVerbosity
Expand Down Expand Up @@ -480,13 +493,13 @@ requireSuccess r@Result { resultCommand = cmd

record :: Result -> TestM ()
record res = do
build_dir <- distDir
log_dir <- topDir
(suite, _) <- ask
liftIO $ createDirectoryIfMissing True build_dir
liftIO $ C.appendFile (build_dir </> "test.log")
liftIO $ createDirectoryIfMissing True log_dir
liftIO $ C.appendFile (log_dir </> "test.log")
(C.pack $ "+ " ++ resultCommand res ++ "\n"
++ resultOutput res ++ "\n\n")
let test_sh = build_dir </> "test.sh"
let test_sh = log_dir </> "test.sh"
b <- liftIO $ doesFileExist test_sh
when (not b) . liftIO $ do
-- This is hella racey but this is not that security important
Expand Down
Loading

0 comments on commit ccf5d8d

Please sign in to comment.