Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@
- --ignore-glob=Cabal-tests/tests/custom-setup/CabalDoctestSetup.hs
- --ignore-glob=Cabal-tests/tests/custom-setup/IdrisSetup.hs
- --ignore-glob=cabal-testsuite/PackageTests/BuildWays/q/app/Main.hs
- --ignore-glob=cabal-testsuite/PackageTests/CppOptions/CppOpts/Main.hs
- --ignore-glob=cabal-testsuite/PackageTests/CMain/10168/src/Lib.hs
- --ignore-glob=cabal-testsuite/PackageTests/CmmSources/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/CmmSourcesDyn/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/CmmSourcesExe/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/Cmm/CmmSources/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/Cmm/CmmSourcesDyn/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/Cmm/CmmSourcesExe/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/NewBuild/CmdRun/Script/script.hs
- --ignore-glob=cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptLiterate/script.lhs
- --ignore-glob=cabal-testsuite/PackageTests/Regression/T5309/lib/Bio/Character/Exportable/Class.hs
Expand Down
15 changes: 15 additions & 0 deletions cabal-testsuite/PackageTests/CppOptions/CppOpts/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{-# LANGUAGE CPP #-}

module Main where

#ifndef __TESTOPT_CPP__
#error "Did not get required __TESTOPT_CPP__ from cpp-options"
#endif

main :: IO ()
main = do
-- The value 44 comes from __TESTOPT_CPP__ - see the cabal file.
let secret = __TESTOPT_CPP__ :: Int
if secret == 44
then putStrLn ("The secret is " ++ show secret)
else error ("Expected value 44, got " ++ show secret)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/CppOptions/CppOpts/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest $ recordMode DoNotRecord $ do
cabal "v2-build" ["cpp-opts-exe"]
withPlan $ runPlanExe "cpp-opts" "cpp-opts-exe" []
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/CppOptions/CppOpts/cpp-opts.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cabal-version: 2.2
name: cpp-opts
version: 0.1
build-type: Simple

executable cpp-opts-exe
main-is: Main.hs
build-depends: base
default-language: Haskell2010
cpp-options: -D__TESTOPT_CPP__=44
16 changes: 16 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsAsm/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{-# LANGUAGE ForeignFunctionInterface #-}

module Main where

import Foreign.C (CInt (..))

foreign import ccall "asmlib.h meaning_of_life_asm"
meaning_of_life_asm :: IO CInt

main :: IO ()
main = do
secret <- meaning_of_life_asm
-- The value 33 comes from meaning_of_life_val - see asm-options in the cabal file.
if (secret == 33)
then putStrLn ("The secret is " ++ show secret)
else error ("Expected value 33, got " ++ show secret)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef ASMLIB_H
#define ASMLIB_H

int meaning_of_life_asm();

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# macOS/AArch64 (Mach-O)
.macro func name
.globl _\name
_\name:
.endm

.text
func meaning_of_life_asm

mov w0, #MEANING_OF_LIFE_VAL
ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.text
.globl meaning_of_life_asm
.type meaning_of_life_asm, @function
meaning_of_life_asm:
movl $MEANING_OF_LIFE_VAL, %eax
ret
.size meaning_of_life_asm, .-meaning_of_life_asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.text
.globl meaning_of_life_asm

meaning_of_life_asm:
movl $MEANING_OF_LIFE_VAL, %eax
ret
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
12 changes: 12 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsAsm/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Test.Cabal.Prelude
import Distribution.System (Arch (..), buildArch, OS (..), buildOS)

main = do
skipUnlessIO "needs x86_64 or aarch64"
( (buildArch == X86_64 && buildOS == Windows)
|| (buildArch == X86_64 && buildOS == Linux)
|| (buildArch == AArch64 && buildOS == OSX)
)
cabalTest $ recordMode DoNotRecord $ do
cabal "v2-build" ["foreign-opts-asm-exe"]
withPlan $ runPlanExe "foreign-opts-asm" "foreign-opts-asm-exe" []
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cabal-version: 3.0
name: foreign-opts-asm
version: 0.1
build-type: Simple

executable foreign-opts-asm-exe
main-is: Main.hs
build-depends: base
default-language: Haskell2010
include-dirs: abits
if os(windows) && arch(x86_64)
asm-sources: abits/asmlib_x86_64_windows.S
elif os(darwin) && arch(aarch64)
asm-sources: abits/asmlib_aarch64_darwin.S
elif os(linux) && arch(x86_64)
asm-sources: abits/asmlib_x86_64_linux.S
asm-options: -DMEANING_OF_LIFE_VAL=33
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/FFI/ForeignOptsCxx/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ main :: IO ()
main = do
secret <- meaning_of_life_cxx
-- The value 22 comes from __TESTOPT_CXX__ - see the cabal file.
if (secret == 22)
if secret == 22
then putStrLn ("The secret is " ++ show secret)
else error ("Expected value 22, got " ++ show secret)
18 changes: 18 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsLd/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{-# LANGUAGE ForeignFunctionInterface #-}

module Main where

import Foreign.C (CInt (..))

-- With ld-options: -Wl,--wrap=meaning_of_life_ld_real, the linker redirects
-- this call to __wrap_meaning_of_life_ld_real, which returns 55.
foreign import ccall "ldlib.h meaning_of_life_ld_real"
meaning_of_life_ld_real :: IO CInt

main :: IO ()
main = do
secret <- meaning_of_life_ld_real
-- The value 55 comes from __wrap_meaning_of_life_ld_real - see ld-options in the cabal file.
if secret == 55
then putStrLn ("The secret is " ++ show secret)
else error ("Expected value 55, got " ++ show secret)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
8 changes: 8 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsLd/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Test.Cabal.Prelude

main = do
skipIfOSX "Apple linker does not support --wrap"
skipIfWindows "Windows linker does not support --wrap"
cabalTest $ recordMode DoNotRecord $ do
cabal "v2-build" ["foreign-opts-ld-exe"]
withPlan $ runPlanExe "foreign-opts-ld" "foreign-opts-ld-exe" []
14 changes: 14 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsLd/cbits/ldlib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "ldlib.h"

/* The "real" implementation - returns 0, the wrong value.
* With ld-options: -Wl,--wrap=meaning_of_life_ld_real, the linker redirects
* all calls to this function to __wrap_meaning_of_life_ld_real below. */
int meaning_of_life_ld_real() {
return 0;
}

/* The wrapper that the linker substitutes in place of the real function.
* Returns 55 - see ld-options in the cabal file. */
int __wrap_meaning_of_life_ld_real() {
return 55;
}
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/FFI/ForeignOptsLd/cbits/ldlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef LDLIB_H
#define LDLIB_H

/* The "real" function; with --wrap, calls to this are redirected by the linker. */
int meaning_of_life_ld_real();

/* The wrapper that the linker calls instead of the real function. */
int __wrap_meaning_of_life_ld_real();

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cabal-version: 2.2
name: foreign-opts-ld
version: 0.1
build-type: Simple

executable foreign-opts-ld-exe
main-is: Main.hs
build-depends: base
default-language: Haskell2010
include-dirs: cbits
c-sources: cbits/ldlib.c
-- Redirect calls to meaning_of_life_ld_real to __wrap_meaning_of_life_ld_real.
-- If ld-options are not passed the real function (returning 0) is called instead
-- of the wrapper (returning 55), and the test fails at runtime.
ld-options: -Wl,--wrap=meaning_of_life_ld_real
Loading