diff --git a/Setup.hs b/Setup.hs index 9135452..f8a0992 100755 --- a/Setup.hs +++ b/Setup.hs @@ -3,6 +3,7 @@ import Distribution.Simple import Distribution.Simple.Setup import Distribution.Simple.Install +import Distribution.Simple.Program import Distribution.Simple.Register import Distribution.Simple.InstallDirs as ID import Distribution.Simple.LocalBuildInfo @@ -25,6 +26,7 @@ main :: IO () main = defaultMainWithHooks $ simpleUserHooks { confHook = \(gpd, hbi) cf -> xBuildDependsLike <$> (confHook simpleUserHooks) (gpd, hbi) cf + , hookedPrograms = [ simpleProgram "shelltest" ] } xBuildDependsLike :: LocalBuildInfo -> LocalBuildInfo diff --git a/ghc-mod.cabal b/ghc-mod.cabal index c50565c..de0ac1a 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -299,6 +299,20 @@ Test-Suite spec Build-Depends: hspec < 2.4 && >= 2.0.0 X-Build-Depends-Like: CLibName + +Test-Suite shelltest + Default-Language: Haskell2010 + Main-Is: ShellTest.hs + Hs-Source-Dirs: shelltest + Type: exitcode-stdio-1.0 + Build-Tools: shelltest + Build-Depends: base + , process < 1.5 + -- , shelltestrunner >= 1.3.5 + if !flag(shelltest) + Buildable: False + + Benchmark criterion Type: exitcode-stdio-1.0 Default-Language: Haskell2010 @@ -325,6 +339,13 @@ Benchmark criterion , ghc-mod + +Flag shelltest + Description: Enable/disable shelltest test-suite + Default: False + Manual: True + + Source-Repository head Type: git Location: https://github.com/DanielG/ghc-mod.git diff --git a/shelltest/ShellTest.hs b/shelltest/ShellTest.hs new file mode 100644 index 0000000..541e021 --- /dev/null +++ b/shelltest/ShellTest.hs @@ -0,0 +1,23 @@ +#!/usr/bin/env runhaskell +-- ghc-mod: Making Haskell development *more* fun +-- Copyright (C) 2017 Daniel Gröber +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Affero General Public License for more details. +-- +-- You should have received a copy of the GNU Affero General Public License +-- along with this program. If not, see . + +module Main where + +import System.Exit +import System.Process + +main = exitWith =<< rawSystem "shelltest" [ "--execdir", "shelltest/" ] diff --git a/shelltest/browse.test b/shelltest/browse.test new file mode 100644 index 0000000..fb9409b --- /dev/null +++ b/shelltest/browse.test @@ -0,0 +1,11 @@ +cabal exec -- ghc-mod browse Data.Map +>>> /differenceWithKey/ +>>>= 0 + +cabal exec -- ghc-mod browse -d Data.Either +>>> /^either :: \(a -> c\) -> \(b -> c\) -> Either a b -> c$/ +>>>= 0 + +cabal exec -- ghc-mod browse -d Data.Either +>>> /^Left :: a -> Either a b$/ +>>>= 0 diff --git a/shelltest/browse/MyModule.hs b/shelltest/browse/MyModule.hs new file mode 100644 index 0000000..b2628eb --- /dev/null +++ b/shelltest/browse/MyModule.hs @@ -0,0 +1,11 @@ +module MyModule where + +data MyType = MyConstructor1 + | MyConstructor2 + +some_num = 0 +some_char = ' ' +some_string = "bar" + +($?>>/) :: Int -> Int -> Int +a $?>>/ b = a + b diff --git a/shelltest/browse/browse-project.testtpl b/shelltest/browse/browse-project.testtpl new file mode 100644 index 0000000..6026676 --- /dev/null +++ b/shelltest/browse/browse-project.testtpl @@ -0,0 +1,62 @@ + +cabal exec -- ghc-mod browse MyModule | sort +>>> +MyConstructor1 +MyConstructor2 +MyType +some_char +some_num +some_string +>>>= 0 + +cabal exec -- ghc-mod browse -q MyModule | sort +>>> +MyModule.MyConstructor1 +MyModule.MyConstructor2 +MyModule.MyType +MyModule.some_char +MyModule.some_num +MyModule.some_string +>>>= 0 + +cabal exec -- ghc-mod browse -d MyModule | sort +>>> +MyConstructor1 :: MyType +MyConstructor2 :: MyType +MyType :: data MyType +some_char :: Char +some_num :: Integer +some_string :: [Char] +>>>= 0 + +cabal exec -- ghc-mod browse -o MyModule | sort +>>> +($?>>/) +MyConstructor1 +MyConstructor2 +MyType +some_char +some_num +some_string +>>>= 0 + +cabal exec -- ghc-mod browse -p MyModule | sort +>>> +MyConstructor1 -- from:MyType +MyConstructor2 -- from:MyType +MyType +some_char +some_num +some_string +>>>= 0 + +cabal exec -- ghc-mod browse -odpq MyModule | sort +>>> +MyModule.($?>>/) :: Int -> Int -> Int +MyModule.MyConstructor1 :: MyType -- from:MyType +MyModule.MyConstructor2 :: MyType -- from:MyType +MyModule.MyType :: data MyType +MyModule.some_char :: Char +MyModule.some_num :: Integer +MyModule.some_string :: [Char] +>>>= 0 diff --git a/shelltest/browse/cabal/MyModule.hs b/shelltest/browse/cabal/MyModule.hs new file mode 120000 index 0000000..e0ba19a --- /dev/null +++ b/shelltest/browse/cabal/MyModule.hs @@ -0,0 +1 @@ +../MyModule.hs \ No newline at end of file diff --git a/shelltest/browse/cabal/browse-cabal.cabal b/shelltest/browse/cabal/browse-cabal.cabal new file mode 100644 index 0000000..f26aae4 --- /dev/null +++ b/shelltest/browse/cabal/browse-cabal.cabal @@ -0,0 +1,9 @@ +name: browse-cabal +version: 0 +build-type: Simple +cabal-version: >=1.2 + +library + hs-source-dirs: . + build-depends: base + exposed-modules: MyModule diff --git a/shelltest/browse/cabal/browse-cabal.test b/shelltest/browse/cabal/browse-cabal.test new file mode 120000 index 0000000..363e68b --- /dev/null +++ b/shelltest/browse/cabal/browse-cabal.test @@ -0,0 +1 @@ +../browse-project.testtpl \ No newline at end of file diff --git a/shelltest/browse/plain/MyModule.hs b/shelltest/browse/plain/MyModule.hs new file mode 120000 index 0000000..e0ba19a --- /dev/null +++ b/shelltest/browse/plain/MyModule.hs @@ -0,0 +1 @@ +../MyModule.hs \ No newline at end of file diff --git a/shelltest/browse/plain/browse-plain.test b/shelltest/browse/plain/browse-plain.test new file mode 100644 index 0000000..9a94a8a --- /dev/null +++ b/shelltest/browse/plain/browse-plain.test @@ -0,0 +1,4 @@ +# # TODO: make this work +# cabal exec -- ghc-mod browse MyModule +# >>> +# >>>= !0 diff --git a/shelltest/browse/sandbox/MyModule.hs b/shelltest/browse/sandbox/MyModule.hs new file mode 120000 index 0000000..e0ba19a --- /dev/null +++ b/shelltest/browse/sandbox/MyModule.hs @@ -0,0 +1 @@ +../MyModule.hs \ No newline at end of file diff --git a/shelltest/browse/sandbox/browse-sandbox.test b/shelltest/browse/sandbox/browse-sandbox.test new file mode 100644 index 0000000..9a94a8a --- /dev/null +++ b/shelltest/browse/sandbox/browse-sandbox.test @@ -0,0 +1,4 @@ +# # TODO: make this work +# cabal exec -- ghc-mod browse MyModule +# >>> +# >>>= !0 diff --git a/shelltest/browse/sandbox/test-setup.sh b/shelltest/browse/sandbox/test-setup.sh new file mode 100644 index 0000000..2721dd5 --- /dev/null +++ b/shelltest/browse/sandbox/test-setup.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +set -e + +rm cabal.sandbox.config +rm -r .cabal-sandbox + +cabal sandbox init diff --git a/shelltest/version.test b/shelltest/version.test new file mode 100644 index 0000000..04adc27 --- /dev/null +++ b/shelltest/version.test @@ -0,0 +1,7 @@ +cabal exec -- ghc-mod version +>>> /^ghc-mod version [0-9.]+ compiled by GHC [0-9.]+/ +>>>= 0 + +cabal exec -- ghc-mod --version +>>> /^ghc-mod version [0-9.]+ compiled by GHC [0-9.]+/ +>>>= 0