add a test for #5289, and various other GHCi linking scenarios
authorSimon Marlow <marlowsd@gmail.com>
Tue, 2 Aug 2011 13:10:54 +0000 (14:10 +0100)
committerSimon Marlow <marlowsd@gmail.com>
Wed, 3 Aug 2011 12:12:13 +0000 (13:12 +0100)
testsuite/tests/ghci/linking/Makefile [new file with mode: 0644]
testsuite/tests/ghci/linking/TestLink.hs [new file with mode: 0644]
testsuite/tests/ghci/linking/all.T [new file with mode: 0644]
testsuite/tests/ghci/linking/f.c [new file with mode: 0644]
testsuite/tests/ghci/linking/ghcilink001.stdout [new file with mode: 0644]
testsuite/tests/ghci/linking/ghcilink002.stderr-i386-unknown-mingw32 [new file with mode: 0644]
testsuite/tests/ghci/linking/ghcilink002.stdout [new file with mode: 0644]
testsuite/tests/ghci/linking/ghcilink003.stdout [new file with mode: 0644]
testsuite/tests/ghci/linking/ghcilink004.stdout [new file with mode: 0644]
testsuite/tests/ghci/linking/ghcilink005.stderr-i386-unknown-mingw32 [new file with mode: 0644]
testsuite/tests/ghci/linking/ghcilink005.stdout [new file with mode: 0644]

diff --git a/testsuite/tests/ghci/linking/Makefile b/testsuite/tests/ghci/linking/Makefile
new file mode 100644 (file)
index 0000000..31ac289
--- /dev/null
@@ -0,0 +1,118 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+LOCAL_GHC_PKG = '$(GHC_PKG)' --no-user-package-conf -f $(LOCAL_PKGCONF)
+
+# Test 1: ghci -Ldir -lfoo
+#   with dir/libfoo.a
+
+.PHONY: ghcilink001
+ghcilink001 :
+       $(RM) -rf dir001
+       mkdir dir001
+       "$(TEST_HC)" -c f.c -o dir001/foo.o
+       ar cqs dir001/libfoo.a dir001/foo.o
+       echo "test" | "$(TEST_HC)" --interactive -v0 -Ldir001 -lfoo TestLink.hs
+
+# Test 2: ghci -Ldir -lfoo
+#   with dir/libfoo.so
+
+ifeq "$(WINDOWS)" "YES"
+DLL = $1.dll
+else
+DLL = lib$1.so
+endif
+
+.PHONY: ghcilink002
+ghcilink002 :
+       $(RM) -rf dir002
+       mkdir dir002
+       "$(TEST_HC)" -c -dynamic f.c -o dir002/foo.o
+       "$(TEST_HC)" -shared -v0 -o dir002/$(call DLL,foo) dir002/foo.o
+       echo "test" | "$(TEST_HC)" --interactive -v0 -Ldir002 -lfoo TestLink.hs
+
+# Test 3: ghci -lstdc++
+#    where libstdc++.so is normally found in a directory private to gcc,
+#    so only gcc can find it (see #5289)
+
+.PHONY: ghcilink003
+ghcilink003 :
+       echo ":q" | "$(TEST_HC)" --interactive -v0 -lstdc++
+
+# Test 4: 
+#   package P
+#      library-dirs: `pwd`/dir004
+#      extra-libraries: foo
+#   with 
+#    dir004/libfoo.a
+
+LOCAL_PKGCONF004=dir004/local.package.conf
+PKG004=dir004/pkg.conf
+
+ghcilink004 :
+       $(RM) -rf dir004
+       mkdir dir004
+       #
+       rm -f $(PKG004)
+       echo "name: test" >>$(PKG004)
+       echo "version: 1.0" >>$(PKG004)
+       echo "id: test-XXX" >>$(PKG004)
+       echo "library-dirs: `pwd`/dir004" >>$(PKG004)
+       echo "extra-libraries: foo" >>$(PKG004)
+       echo "[]" >$(LOCAL_PKGCONF004)
+       '$(GHC_PKG)' --no-user-package-conf -f $(LOCAL_PKGCONF004) register $(PKG004) -v0
+       #
+       "$(TEST_HC)" -c f.c -o dir004/foo.o
+       ar cqs dir004/libfoo.a dir004/foo.o
+       echo "test" | "$(TEST_HC)" --interactive -v0 -package-conf $(LOCAL_PKGCONF004) -package test TestLink.hs
+
+
+# Test 5: 
+#   package P
+#      library-dirs: `pwd`/dir005
+#      extra-libraries: foo
+#   with 
+#    dir005/libfoo.so
+
+LOCAL_PKGCONF005=dir005/ghcilink005.package.conf
+PKG005=dir005/pkg.conf
+
+ghcilink005 :
+       $(RM) -rf dir005
+       mkdir dir005
+       #
+       rm -f $(PKG005)
+       echo "name: test" >>$(PKG005)
+       echo "version: 1.0" >>$(PKG005)
+       echo "id: test-XXX" >>$(PKG005)
+       echo "library-dirs: `pwd`/dir005" >>$(PKG005)
+       echo "extra-libraries: foo" >>$(PKG005)
+       echo "[]" >$(LOCAL_PKGCONF005)
+       '$(GHC_PKG)' --no-user-package-conf -f $(LOCAL_PKGCONF005) register $(PKG005) -v0
+       #
+       "$(TEST_HC)" -c -dynamic f.c -o dir005/foo.o
+       "$(TEST_HC)" -shared -o dir005/$(call DLL,foo) dir005/foo.o
+       echo "test" | "$(TEST_HC)" --interactive -v0 -package-conf $(LOCAL_PKGCONF005) -package test TestLink.hs
+
+# Test 6: 
+#   package P
+#      extra-libraries: stdc++
+
+LOCAL_PKGCONF006=dir006/ghcilink006.package.conf
+PKG006=dir006/pkg.conf
+
+ghcilink006 :
+       $(RM) -rf dir006
+       mkdir dir006
+       #
+       rm -f $(PKG006)
+       echo "name: test" >>$(PKG006)
+       echo "version: 1.0" >>$(PKG006)
+       echo "id: test-XXX" >>$(PKG006)
+       echo "extra-libraries: stdc++" >>$(PKG006)
+       echo "[]" >$(LOCAL_PKGCONF006)
+       '$(GHC_PKG)' --no-user-package-conf -f $(LOCAL_PKGCONF006) register $(PKG006) -v0
+       #
+       echo ":q" | "$(TEST_HC)" --interactive -v0 -package-conf $(LOCAL_PKGCONF006) -package test
+
diff --git a/testsuite/tests/ghci/linking/TestLink.hs b/testsuite/tests/ghci/linking/TestLink.hs
new file mode 100644 (file)
index 0000000..808f6e3
--- /dev/null
@@ -0,0 +1,8 @@
+module TestLink where
+
+import Foreign.C
+
+foreign import ccall "f" f :: CInt -> IO CInt
+
+test :: IO ()
+test = f 42 >>= print
diff --git a/testsuite/tests/ghci/linking/all.T b/testsuite/tests/ghci/linking/all.T
new file mode 100644 (file)
index 0000000..8c2e821
--- /dev/null
@@ -0,0 +1,37 @@
+test('ghcilink001',
+     [ if_os('mingw32', skip), # crashes; see #5371
+       extra_clean(['dir001/*','dir001'])
+     ],
+     run_command,
+     ['$MAKE -s --no-print-directory ghcilink001'])
+
+test('ghcilink002',
+     extra_clean(['dir002/*','dir002']),
+     run_command,
+     ['$MAKE -s --no-print-directory ghcilink002'])
+
+test('ghcilink003',
+     [
+       if_os('mingw32', expect_broken(5289)), # still cannot load libstdc++
+                                              # on Windows.  See also #4468.
+       extra_clean(['dir003/*','dir003'])
+     ],
+     run_command,
+     ['$MAKE -s --no-print-directory ghcilink003'])
+
+test('ghcilink004',
+     [ if_os('mingw32', skip), # crashes; see #5371
+       extra_clean(['dir004/*','dir004'])
+     ],
+     run_command,
+     ['$MAKE -s --no-print-directory ghcilink004'])
+
+test('ghcilink005',
+     extra_clean(['dir005/*','dir005']),
+     run_command,
+     ['$MAKE -s --no-print-directory ghcilink005'])
+
+test('ghcilink006',
+     extra_clean(['dir006/*','dir006']),
+     run_command,
+     ['$MAKE -s --no-print-directory ghcilink006'])
diff --git a/testsuite/tests/ghci/linking/f.c b/testsuite/tests/ghci/linking/f.c
new file mode 100644 (file)
index 0000000..caf249d
--- /dev/null
@@ -0,0 +1,4 @@
+int f(int x)
+{
+    return x*2;
+}
diff --git a/testsuite/tests/ghci/linking/ghcilink001.stdout b/testsuite/tests/ghci/linking/ghcilink001.stdout
new file mode 100644 (file)
index 0000000..871727d
--- /dev/null
@@ -0,0 +1 @@
+84
diff --git a/testsuite/tests/ghci/linking/ghcilink002.stderr-i386-unknown-mingw32 b/testsuite/tests/ghci/linking/ghcilink002.stderr-i386-unknown-mingw32
new file mode 100644 (file)
index 0000000..c0649da
--- /dev/null
@@ -0,0 +1 @@
+Creating library file: dir002/foo.dll.a\r
diff --git a/testsuite/tests/ghci/linking/ghcilink002.stdout b/testsuite/tests/ghci/linking/ghcilink002.stdout
new file mode 100644 (file)
index 0000000..871727d
--- /dev/null
@@ -0,0 +1 @@
+84
diff --git a/testsuite/tests/ghci/linking/ghcilink003.stdout b/testsuite/tests/ghci/linking/ghcilink003.stdout
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/testsuite/tests/ghci/linking/ghcilink004.stdout b/testsuite/tests/ghci/linking/ghcilink004.stdout
new file mode 100644 (file)
index 0000000..871727d
--- /dev/null
@@ -0,0 +1 @@
+84
diff --git a/testsuite/tests/ghci/linking/ghcilink005.stderr-i386-unknown-mingw32 b/testsuite/tests/ghci/linking/ghcilink005.stderr-i386-unknown-mingw32
new file mode 100644 (file)
index 0000000..7929095
--- /dev/null
@@ -0,0 +1 @@
+Creating library file: dir005/foo.dll.a\r
diff --git a/testsuite/tests/ghci/linking/ghcilink005.stdout b/testsuite/tests/ghci/linking/ghcilink005.stdout
new file mode 100644 (file)
index 0000000..871727d
--- /dev/null
@@ -0,0 +1 @@
+84