diff options
author | Ben Gamari <ben@smart-cactus.org> | 2022-04-27 19:53:13 -0400 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2022-06-17 10:05:17 +0100 |
commit | 1f6c5870fb507e845a9ce86c07b9010ff9fbf67f (patch) | |
tree | 8ac3a95b4ee367fae758b17fa874050b0a1d74c7 | |
parent | ec51453f46bd15f928e82a994784b0d88f128794 (diff) | |
download | haskell-1f6c5870fb507e845a9ce86c07b9010ff9fbf67f.tar.gz |
testsuite: Add tests for system-cxx-std-lib package
Test that we can successfully link against C++ code both in GHCi and
batch compilation.
See #20010
(cherry picked from commit 03efe28317c5e037eab4d47790a6a1fb74d38c3d)
-rw-r--r-- | testsuite/tests/package/T20010/Makefile | 18 | ||||
-rw-r--r-- | testsuite/tests/package/T20010/T20010-ghci.script | 2 | ||||
-rw-r--r-- | testsuite/tests/package/T20010/T20010-ghci.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/package/T20010/T20010.hs | 10 | ||||
-rw-r--r-- | testsuite/tests/package/T20010/T20010.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/package/T20010/T20010_c.cpp | 7 | ||||
-rw-r--r-- | testsuite/tests/package/T20010/all.T | 4 |
7 files changed, 43 insertions, 0 deletions
diff --git a/testsuite/tests/package/T20010/Makefile b/testsuite/tests/package/T20010/Makefile new file mode 100644 index 0000000000..9343836a5e --- /dev/null +++ b/testsuite/tests/package/T20010/Makefile @@ -0,0 +1,18 @@ +TOP=../../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +T20010: + '$(TEST_HC)' $(TEST_HC_OPTS) -c T20010.hs + '$(TEST_HC)' $(TEST_HC_OPTS) -c T20010_c.cpp + '$(TEST_HC)' $(TEST_HC_OPTS) -package system-cxx-std-lib T20010_c.o T20010.o -o T20010 + ./T20010 + +T20010-ghci: + '$(TEST_HC)' $(TEST_HC_OPTS) -c T20010.hs + # We must build with PIC lest we end up with R_X86_64_32 relocations in + # .rodata which precludes linking into a shared object and therefore loading + # in GHCi + '$(TEST_HC)' $(TEST_HC_OPTS) -c -fPIC T20010_c.cpp + '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) -package system-cxx-std-lib T20010_c.o <T20010-ghci.script + diff --git a/testsuite/tests/package/T20010/T20010-ghci.script b/testsuite/tests/package/T20010/T20010-ghci.script new file mode 100644 index 0000000000..da04af1cb0 --- /dev/null +++ b/testsuite/tests/package/T20010/T20010-ghci.script @@ -0,0 +1,2 @@ +:load T20010 +hello 42 diff --git a/testsuite/tests/package/T20010/T20010-ghci.stdout b/testsuite/tests/package/T20010/T20010-ghci.stdout new file mode 100644 index 0000000000..d9a45b2f81 --- /dev/null +++ b/testsuite/tests/package/T20010/T20010-ghci.stdout @@ -0,0 +1 @@ +hello world 42 diff --git a/testsuite/tests/package/T20010/T20010.hs b/testsuite/tests/package/T20010/T20010.hs new file mode 100644 index 0000000000..306ed607e2 --- /dev/null +++ b/testsuite/tests/package/T20010/T20010.hs @@ -0,0 +1,10 @@ +module Main where + +import Foreign.C.Types + +foreign import ccall unsafe "hello" hello :: CInt -> IO () + +main :: IO () +main = do + hello 42 + diff --git a/testsuite/tests/package/T20010/T20010.stdout b/testsuite/tests/package/T20010/T20010.stdout new file mode 100644 index 0000000000..d9a45b2f81 --- /dev/null +++ b/testsuite/tests/package/T20010/T20010.stdout @@ -0,0 +1 @@ +hello world 42 diff --git a/testsuite/tests/package/T20010/T20010_c.cpp b/testsuite/tests/package/T20010/T20010_c.cpp new file mode 100644 index 0000000000..582c561b3f --- /dev/null +++ b/testsuite/tests/package/T20010/T20010_c.cpp @@ -0,0 +1,7 @@ +#include <iostream> + +extern "C" { +void hello(int x) { + std::cout << "hello world " << x << std::endl; +} +} diff --git a/testsuite/tests/package/T20010/all.T b/testsuite/tests/package/T20010/all.T new file mode 100644 index 0000000000..4bfaecfcc2 --- /dev/null +++ b/testsuite/tests/package/T20010/all.T @@ -0,0 +1,4 @@ +# Test that GHC links to the C++ standard library as expected +# when the system-cxx-std-lib package is used. +test('T20010', normal, makefile_test, []) +test('T20010-ghci', extra_files(['T20010_c.cpp', 'T20010.hs']), makefile_test, []) |