testsuite: Add test for #16104
authorBen Gamari <ben@smart-cactus.org>
Tue, 15 Jan 2019 16:48:59 +0000 (11:48 -0500)
committerBen Gamari <ben@smart-cactus.org>
Sun, 27 Jan 2019 13:32:12 +0000 (08:32 -0500)
testsuite/tests/plugins/Makefile
testsuite/tests/plugins/T16104-plugin/LICENSE [new file with mode: 0644]
testsuite/tests/plugins/T16104-plugin/Makefile [new file with mode: 0644]
testsuite/tests/plugins/T16104-plugin/Setup.hs [new file with mode: 0644]
testsuite/tests/plugins/T16104-plugin/T16104-plugin.cabal [new file with mode: 0644]
testsuite/tests/plugins/T16104-plugin/T16104_Plugin.hs [new file with mode: 0644]
testsuite/tests/plugins/T16104.hs [new file with mode: 0644]
testsuite/tests/plugins/T16104.stdout [new file with mode: 0644]
testsuite/tests/plugins/all.T

index 8a6af5b..d913ca5 100644 (file)
@@ -121,3 +121,7 @@ plugin-recomp-change-prof:
        "$(MAKE)" -s --no-print-directory -C plugin-recomp package.plugins01 TOP=$(TOP) RUN=-DRUN2
        "$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -v0 plugin-recomp-test.hs -package-db plugin-recomp/pkg.plugins01/local.package.conf -fplugin PurePlugin
        "$(TEST_HC)" $(TEST_HC_OPTS) -prof -osuf p_o -hisuf p_hi -v0 plugin-recomp-test.hs -package-db plugin-recomp/pkg.plugins01/local.package.conf -fplugin PurePlugin
+
+.PHONY: T16104
+T16104:
+       "$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -v0 T16104.hs -package-db T16104-plugin/pkg.T16104-plugin/local.package.conf
diff --git a/testsuite/tests/plugins/T16104-plugin/LICENSE b/testsuite/tests/plugins/T16104-plugin/LICENSE
new file mode 100644 (file)
index 0000000..6297f71
--- /dev/null
@@ -0,0 +1,10 @@
+Copyright (c) 2008, Max Bolingbroke
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+    * Neither the name of Max Bolingbroke nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/testsuite/tests/plugins/T16104-plugin/Makefile b/testsuite/tests/plugins/T16104-plugin/Makefile
new file mode 100644 (file)
index 0000000..5a0289c
--- /dev/null
@@ -0,0 +1,18 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+clean.%:
+       rm -rf pkg.$*
+
+HERE := $(abspath .)
+$(eval $(call canonicalise,HERE))
+
+package.%:
+       $(MAKE) -s --no-print-directory clean.$*
+       mkdir pkg.$*
+       "$(TEST_HC)" -outputdir pkg.$* --make -v0 -o pkg.$*/setup Setup.hs
+       "$(GHC_PKG)" init pkg.$*/local.package.conf
+       pkg.$*/setup configure --distdir pkg.$*/dist -v0 $(CABAL_PLUGIN_BUILD) --prefix="$(HERE)/pkg.$*/install" --with-compiler="$(TEST_HC)" --with-hc-pkg="$(GHC_PKG)" --package-db=pkg.$*/local.package.conf $(if $(findstring YES,$(HAVE_PROFILING)), --enable-library-profiling)
+       pkg.$*/setup build     --distdir pkg.$*/dist -v0
+       pkg.$*/setup install   --distdir pkg.$*/dist -v0
diff --git a/testsuite/tests/plugins/T16104-plugin/Setup.hs b/testsuite/tests/plugins/T16104-plugin/Setup.hs
new file mode 100644 (file)
index 0000000..e8ef27d
--- /dev/null
@@ -0,0 +1,3 @@
+import Distribution.Simple
+
+main = defaultMain
diff --git a/testsuite/tests/plugins/T16104-plugin/T16104-plugin.cabal b/testsuite/tests/plugins/T16104-plugin/T16104-plugin.cabal
new file mode 100644 (file)
index 0000000..5288e8f
--- /dev/null
@@ -0,0 +1,11 @@
+Name:           T16104-plugin
+Version:        0.1
+Synopsis:       For testing
+Cabal-Version:  >= 1.2
+Build-Type:     Simple
+License:        BSD3
+License-File:   LICENSE
+
+Library
+    Build-Depends: base, ghc
+    Exposed-Modules: T16104_Plugin
diff --git a/testsuite/tests/plugins/T16104-plugin/T16104_Plugin.hs b/testsuite/tests/plugins/T16104-plugin/T16104_Plugin.hs
new file mode 100644 (file)
index 0000000..79cd0fe
--- /dev/null
@@ -0,0 +1,20 @@
+{-# LANGUAGE TemplateHaskell #-}
+
+module T16104_Plugin (plugin) where
+
+import GhcPlugins
+import Data.Bits
+
+plugin :: Plugin
+plugin = defaultPlugin {installCoreToDos = install}
+  where install _ todos = return (test : todos)
+
+        test = CoreDoPluginPass "Test" check
+
+        check :: ModGuts -> CoreM ModGuts
+        check m = do mbN <- thNameToGhcName 'complement
+                     case mbN of
+                       Just _  -> liftIO $ putStrLn "Found complement!"
+                       Nothing -> error "Failed to locate complement"
+
+                     return m
diff --git a/testsuite/tests/plugins/T16104.hs b/testsuite/tests/plugins/T16104.hs
new file mode 100644 (file)
index 0000000..bfef697
--- /dev/null
@@ -0,0 +1,4 @@
+{-# OPTIONS_GHC -fplugin T16104_Plugin #-}
+
+main :: IO ()
+main = return ()
diff --git a/testsuite/tests/plugins/T16104.stdout b/testsuite/tests/plugins/T16104.stdout
new file mode 100644 (file)
index 0000000..a1eb7b6
--- /dev/null
@@ -0,0 +1 @@
+Found complement!
index da6294e..82e9fcb 100644 (file)
@@ -208,3 +208,9 @@ test('T15858',
       extra_hc_opts("-package-db plugin-recomp/pkg.plugins01/local.package.conf ")
       ],
      ghci_script, ['T15858.script'])
+
+test('T16104',
+     [extra_files(['T16104-plugin/']),
+      pre_cmd('$MAKE -s --no-print-directory -C T16104-plugin package.T16104-plugin TOP={top}')
+     ],
+     run_command, ['$MAKE -s --no-print-directory T16104'])