Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sergv committed Jan 8, 2022
1 parent 4354125 commit 1b0fbdc
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{-# LANGUAGE ForeignFunctionInterface #-}

module Main (main) where

foreign import ccall "foo" foo :: Int -> Int

main :: IO ()
main = do
let x = foo 0
y = x
let x = y
print x
pure ()
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/custom-cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if which cc >/dev/null 2>&1; then
cc -DNOERROR6 "${@}"
elif which gcc >/dev/null 2>&1; then
gcc -DNOERROR6 "${@}"
elif which clang >/dev/null 2>&1; then
clang -DNOERROR6 "${@}"
else
echo "Cannot find C compiler" >&2
exit 1
fi

11 changes: 11 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/custom-cc.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo OFF

where /q gcc.exe

IF %ERRORLEVEL% EQU 0 (
call gcc.exe -DNOERROR6 %*
EXIT /B %ERRORLEVEL%
)

ECHO "Cannot find C compiler"
EXIT /B 1
28 changes: 28 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/foo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

#ifndef NOERROR1
#error "NOERROR1 was not passed"
#endif

#ifndef NOERROR2
#error "NOERROR2 was not passed"
#endif

#ifndef NOERROR3
#error "NOERROR3 was not passed"
#endif

#ifndef NOERROR4
#error "NOERROR4 was not passed"
#endif

#ifndef NOERROR5
#error "NOERROR5 was not passed"
#endif

#ifndef NOERROR6
#error "NOERROR6 was not passed"
#endif

int foo(int x) {
return x + 42;
}
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/my.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: my
version: 0.1
license: BSD3
cabal-version: >= 1.10
build-type: Simple

executable foo
default-language: Haskell2010
main-is: Main.hs
c-sources: foo.c
build-depends: base
ghc-options: -DNOERROR4
cc-options: -DNOERROR5 -march=native
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Setup configure
Configuring my-0.1...
Warning: Instead of 'ghc-options: -DNOERROR4' use 'cpp-options: -DNOERROR4'
# Setup build
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Setup configure
Configuring my-0.1...
Warning: Instead of 'ghc-options: -DNOERROR4' use 'cpp-options: -DNOERROR4'
# Setup build
18 changes: 18 additions & 0 deletions cabal-testsuite/PackageTests/CCompilerOverride/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Test.Cabal.Prelude

-- Test that all the respective defines -DNOERROR... specified in variosu ways
-- all end up routed to the C compiler. Otherwise the C file we depend on will
-- not compile.
main = setupAndCabalTest $ do
isWin <- isWindows
env <- getTestEnv
let pwd = testCurrentDir env
customCC = pwd ++ "/custom-cc" ++ if isWin then ".bat" else ""

setup "configure"
[ "--ghc-option=-DNOERROR1"
, "--ghc-option=-optc=-DNOERROR2"
, "--ghc-option=-optP=-DNOERROR3"
, "--with-gcc=" ++ customCC
]
setup "build" ["-v2"]

0 comments on commit 1b0fbdc

Please sign in to comment.