Skip to content

Commit feeba7b

Browse files
committed
Tests for internal libraries (haskell#269) and separate cabal_macros.h (haskell#1893)
Signed-off-by: Edward Z. Yang <[email protected]>
1 parent 1e4ea9d commit feeba7b

File tree

22 files changed

+255
-39
lines changed

22 files changed

+255
-39
lines changed

Cabal/Cabal.cabal

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,30 @@ extra-source-files:
119119
tests/PackageTests/HaddockNewline/A.hs
120120
tests/PackageTests/HaddockNewline/HaddockNewline.cabal
121121
tests/PackageTests/HaddockNewline/Setup.hs
122-
tests/PackageTests/MultipleLibraries/p.cabal
123-
tests/PackageTests/MultipleLibraries/p/P.hs
124-
tests/PackageTests/MultipleLibraries/p/Foo.hs
125-
tests/PackageTests/MultipleLibraries/p/p.cabal
126-
tests/PackageTests/MultipleLibraries/p/p/P.hs
127-
tests/PackageTests/MultipleLibraries/p/q/Q.hs
128-
tests/PackageTests/MultipleLibraries/q/Q.hs
129-
tests/PackageTests/MultipleLibraries/q/q.cabal
122+
tests/PackageTests/InternalLibraries/Executable/dist-test.Dynamic/test.sh
123+
tests/PackageTests/InternalLibraries/Executable/dist-test.Static/test.sh
124+
tests/PackageTests/InternalLibraries/Executable/exe/Main.hs
125+
tests/PackageTests/InternalLibraries/Executable/foo.cabal
126+
tests/PackageTests/InternalLibraries/Executable/src/Foo.hs
127+
tests/PackageTests/InternalLibraries/Library/dist-test/test.sh
128+
tests/PackageTests/InternalLibraries/Library/fooexe/Main.hs
129+
tests/PackageTests/InternalLibraries/Library/fooexe/fooexe.cabal
130+
tests/PackageTests/InternalLibraries/Library/foolib/Foo.hs
131+
tests/PackageTests/InternalLibraries/Library/foolib/foolib.cabal
132+
tests/PackageTests/InternalLibraries/Library/foolib/private/Internal.hs
133+
tests/PackageTests/InternalLibraries/dist-test/test.sh
134+
tests/PackageTests/InternalLibraries/p/Foo.hs
135+
tests/PackageTests/InternalLibraries/p/p.cabal
136+
tests/PackageTests/InternalLibraries/p/p/P.hs
137+
tests/PackageTests/InternalLibraries/p/q/Q.hs
138+
tests/PackageTests/InternalLibraries/q/Q.hs
139+
tests/PackageTests/InternalLibraries/q/q.cabal
140+
tests/PackageTests/Macros/A.hs
141+
tests/PackageTests/Macros/B.hs
142+
tests/PackageTests/Macros/Main.hs
143+
tests/PackageTests/Macros/dist-test/test.sh
144+
tests/PackageTests/Macros/macros.cabal
145+
tests/PackageTests/Macros/src/C.hs
130146
tests/PackageTests/OrderFlags/Foo.hs
131147
tests/PackageTests/OrderFlags/my.cabal
132148
tests/PackageTests/PathsModule/Executable/Main.hs
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Foo
2+
main = print (foo 23)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: foo
2+
version: 0.1.0.0
3+
license: BSD3
4+
author: Edward Z. Yang
5+
maintainer: [email protected]
6+
build-type: Simple
7+
cabal-version: >=1.23
8+
9+
library foo-internal
10+
exposed-modules: Foo
11+
build-depends: base
12+
hs-source-dirs: src
13+
default-language: Haskell2010
14+
15+
executable foo
16+
main-is: Main.hs
17+
build-depends: base, foo-internal
18+
hs-source-dirs: exe
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Foo where
2+
{-# NOINLINE foo #-}
3+
foo :: Int -> Int
4+
foo x = x + 23
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import Foo
4+
5+
main :: IO ()
6+
main = print foo
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: fooexe
2+
version: 0.1.0.0
3+
license: BSD3
4+
author: Edward Z. Yang
5+
maintainer: [email protected]
6+
build-type: Simple
7+
cabal-version: >=1.10
8+
9+
executable fooexe
10+
main-is: Main.hs
11+
build-depends: base, foolib
12+
default-language: Haskell2010
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Foo where
2+
import Internal
3+
foo = internal + 2
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: foolib
2+
version: 0.1.0.0
3+
license: BSD3
4+
author: Edward Z. Yang
5+
maintainer: [email protected]
6+
build-type: Simple
7+
cabal-version: >=1.23
8+
9+
library foolib-internal
10+
exposed-modules: Internal
11+
hs-source-dirs: private
12+
build-depends: base
13+
14+
library
15+
exposed-modules: Foo
16+
build-depends: base, foolib-internal
17+
default-language: Haskell2010
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Internal where
2+
{-# NOINLINE internal #-}
3+
internal :: Int
4+
internal = 23

Cabal/tests/PackageTests/Macros/A.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{-# LANGUAGE CPP #-}
2+
import C
3+
#ifdef VERSION_filepath
4+
#error "Should not see macro from library"
5+
#endif
6+
#ifdef VERSION_containers
7+
#error "Should not see macro from executable macros-b"
8+
#endif
9+
main = do
10+
putStrLn CURRENT_COMPONENT_ID

Cabal/tests/PackageTests/Macros/B.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{-# LANGUAGE CPP #-}
2+
import C
3+
#ifdef VERSION_filepath
4+
#error "Should not see macro from library"
5+
#endif
6+
#ifdef VERSION_deepseq
7+
#error "Should not see macro from executable macros-a"
8+
#endif
9+
main = do
10+
putStrLn CURRENT_COMPONENT_ID
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Main where
2+
3+
main :: IO ()
4+
main = putStrLn "Hello, Haskell!"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: macros
2+
version: 0.1.0.0
3+
license: BSD3
4+
license-file: LICENSE
5+
author: Edward Z. Yang
6+
maintainer: [email protected]
7+
build-type: Simple
8+
cabal-version: >=1.10
9+
10+
library macros
11+
exposed-modules: C
12+
hs-source-dirs: src
13+
build-depends: base, filepath
14+
15+
executable macros-a
16+
main-is: A.hs
17+
build-depends: base, deepseq, macros
18+
default-language: Haskell2010
19+
20+
executable macros-b
21+
main-is: B.hs
22+
build-depends: base, containers, macros
23+
default-language: Haskell2010
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{-# LANGUAGE CPP #-}
2+
module C where
3+
#ifdef VERSION_deepseq
4+
#error "Should not see macro from executable macros-a"
5+
#endif
6+
#ifdef VERSION_containers
7+
#error "Should not see macro from executable macros-b"
8+
#endif
9+
c :: String
10+
c = CURRENT_COMPONENT_ID

Cabal/tests/PackageTests/PackageTester.hs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ module PackageTests.PackageTester
2828
, run
2929
, runExe
3030
, runExe'
31+
, runInstalledExe
32+
, runInstalledExe'
3133
, rawRun
3234
, rawCompileSetup
3335
, withPackage
@@ -68,7 +70,7 @@ import Distribution.Simple.Configure
6870
import Distribution.Verbosity (Verbosity)
6971
import Distribution.Simple.BuildPaths (exeExtension)
7072

71-
#ifndef CURRENT_COMPONENT_ID
73+
#ifndef LOCAL_COMPONENT_ID
7274
import Distribution.Simple.Utils (cabalVersion)
7375
import Distribution.Text (display)
7476
#endif
@@ -280,7 +282,7 @@ cabal' cmd extraArgs0 = do
280282
-- Would really like to do this, but we're not always
281283
-- going to be building against sufficiently recent
282284
-- Cabal which provides this macro.
283-
-- , "--dependency=Cabal=" ++ THIS_PACKAGE_KEY
285+
-- , "--dependency=Cabal=" ++ LOCAL_COMPONENT_ID
284286
-- These flags make the test suite run faster
285287
-- Can't do this unless we LD_LIBRARY_PATH correctly
286288
-- , "--enable-executable-dynamic"
@@ -359,10 +361,10 @@ rawCompileSetup verbosity suite e path = do
359361
ghcPackageDBParams (ghcVersion suite) (packageDBStack suite) ++
360362
[ "-hide-all-packages"
361363
, "-package base"
362-
#ifdef CURRENT_COMPONENT_ID
364+
#ifdef LOCAL_COMPONENT_ID
363365
-- This is best, but we don't necessarily have it
364366
-- if we're bootstrapping with old Cabal.
365-
, "-package-id " ++ CURRENT_COMPONENT_ID
367+
, "-package-id " ++ LOCAL_COMPONENT_ID
366368
#else
367369
-- This mostly works, UNLESS you've installed a
368370
-- version of Cabal with the SAME version number.
@@ -440,6 +442,17 @@ runExe' exe_name args = do
440442
let exe = dist_dir </> "build" </> exe_name </> exe_name
441443
run Nothing exe args
442444

445+
-- | Run an executable that was installed by cabal. The @exe_name@
446+
-- is precisely the name of the executable.
447+
runInstalledExe :: String -> [String] -> TestM ()
448+
runInstalledExe exe_name args = void (runInstalledExe' exe_name args)
449+
450+
runInstalledExe' :: String -> [String] -> TestM Result
451+
runInstalledExe' exe_name args = do
452+
usr <- prefixDir
453+
let exe = usr </> "bin" </> exe_name
454+
run Nothing exe args
455+
443456
run :: Maybe FilePath -> String -> [String] -> TestM Result
444457
run mb_cwd path args = do
445458
verbosity <- getVerbosity
@@ -499,13 +512,13 @@ requireSuccess r@Result { resultCommand = cmd
499512

500513
record :: Result -> TestM ()
501514
record res = do
502-
build_dir <- distDir
515+
log_dir <- topDir
503516
(suite, _) <- ask
504-
liftIO $ createDirectoryIfMissing True build_dir
505-
liftIO $ C.appendFile (build_dir </> "test.log")
517+
liftIO $ createDirectoryIfMissing True log_dir
518+
liftIO $ C.appendFile (log_dir </> "test.log")
506519
(C.pack $ "+ " ++ resultCommand res ++ "\n"
507520
++ resultOutput res ++ "\n\n")
508-
let test_sh = build_dir </> "test.sh"
521+
let test_sh = log_dir </> "test.sh"
509522
b <- liftIO $ doesFileExist test_sh
510523
when (not b) . liftIO $ do
511524
-- This is hella racey but this is not that security important

0 commit comments

Comments
 (0)