summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-04-27 19:53:13 -0400
committerBen Gamari <ben@smart-cactus.org>2022-05-14 22:35:31 -0400
commitdee3d99fccf27b432e689f73a58c4c5564887ff3 (patch)
tree0953d56dda852645a03b271c9e029d72264527cc
parent7965393b20b571551e574e0a91fd4f05964f7488 (diff)
downloadhaskell-wip/T20010b.tar.gz
testsuite: Add tests for system-cxx-std-lib packagewip/T20010b
Test that we can successfully link against C++ code both in GHCi and batch compilation. See #20010
-rw-r--r--testsuite/tests/package/T20010/Makefile18
-rw-r--r--testsuite/tests/package/T20010/T20010-ghci.script2
-rw-r--r--testsuite/tests/package/T20010/T20010-ghci.stdout1
-rw-r--r--testsuite/tests/package/T20010/T20010.hs10
-rw-r--r--testsuite/tests/package/T20010/T20010.stdout1
-rw-r--r--testsuite/tests/package/T20010/T20010_c.cpp7
-rw-r--r--testsuite/tests/package/T20010/all.T4
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, [])