diff --git a/Cabal.hs b/Cabal.hs index cc42c67..cdc3650 100644 --- a/Cabal.hs +++ b/Cabal.hs @@ -47,9 +47,14 @@ fromCabal ghcOptions = do idirs = case hsSourceDirs of [] -> [cdir,owdir] dirs -> map (cdir ) dirs ++ [owdir] - depPkgs <- cabalDependPackages cabal + depPkgs <- removeMe cfile <$> cabalDependPackages cabal return (gopts,idirs,depPkgs) +removeMe :: FilePath -> [String] -> [String] +removeMe cabalfile depPkgs = filter (/= me) depPkgs + where + me = dropExtension $ takeFileName cabalfile + ---------------------------------------------------------------- -- CurrentWorkingDir, CabalDir, CabalFile diff --git a/ghc-mod.cabal b/ghc-mod.cabal index 4bdb7f7..acc74b9 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -70,6 +70,7 @@ Test-Suite spec BrowseSpec CabalSpec CabalApiSpec + CheckSpec FlagSpec LangSpec LintSpec diff --git a/test/CheckSpec.hs b/test/CheckSpec.hs new file mode 100644 index 0000000..4d0a797 --- /dev/null +++ b/test/CheckSpec.hs @@ -0,0 +1,14 @@ +module CheckSpec where + +import Test.Hspec +import Check +import Expectation +import Types + +spec :: Spec +spec = do + describe "checkSyntax" $ do + it "can check even if an executable depends on its library" $ do + withDirectory "test/data/ghc-mod-check" $ do + res <- checkSyntax defaultOptions "main.hs" + res `shouldBe` "main.hs:5:1:Warning:Top-level binding with no type signature: main :: IO ()\NUL\n" diff --git a/test/data/ghc-mod-check/Data/Foo.hs b/test/data/ghc-mod-check/Data/Foo.hs new file mode 100644 index 0000000..eb18003 --- /dev/null +++ b/test/data/ghc-mod-check/Data/Foo.hs @@ -0,0 +1,4 @@ +module Data.Foo where + +foo :: Int +foo = undefined diff --git a/test/data/ghc-mod-check/LICENSE b/test/data/ghc-mod-check/LICENSE new file mode 100644 index 0000000..36e8e59 --- /dev/null +++ b/test/data/ghc-mod-check/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2013, Kazu Yamamoto + +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 Kazu Yamamoto 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/test/data/ghc-mod-check/Setup.hs b/test/data/ghc-mod-check/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/test/data/ghc-mod-check/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/test/data/ghc-mod-check/ghc-mod-check.cabal b/test/data/ghc-mod-check/ghc-mod-check.cabal new file mode 100644 index 0000000..a9a6eb8 --- /dev/null +++ b/test/data/ghc-mod-check/ghc-mod-check.cabal @@ -0,0 +1,27 @@ +-- Initial ghc-mod-check.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ + +name: ghc-mod-check +version: 0.1.0.0 +synopsis: check test +-- description: +license: BSD3 +license-file: LICENSE +author: Kazu Yamamoto +maintainer: kazu@iij.ad.jp +-- copyright: +category: Data +build-type: Simple +cabal-version: >=1.8 + +library + -- exposed-modules: + -- other-modules: + build-depends: base + exposed-modules: Data.Foo + +executable foo + Main-Is: main.hs + GHC-Options: -Wall + Build-Depends: base >= 4 && < 5 + , ghc-mod-check diff --git a/test/data/ghc-mod-check/main.hs b/test/data/ghc-mod-check/main.hs new file mode 100644 index 0000000..0fbb592 --- /dev/null +++ b/test/data/ghc-mod-check/main.hs @@ -0,0 +1,5 @@ +module Main where + +import Data.Foo + +main = print foo