summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-04-27 19:53:13 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-05-17 00:25:02 -0400
commit03efe28317c5e037eab4d47790a6a1fb74d38c3d (patch)
tree4205a6fcff2b49103fd0769ceb80a87768b160bf
parent0ef249aa26f653677c5368bb51af34f7577ba5b9 (diff)
downloadhaskell-03efe28317c5e037eab4d47790a6a1fb74d38c3d.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
-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, [])