1
1
mirror of https://github.com/tweag/ormolu.git synced 2024-09-11 13:16:13 +03:00

Cabal file lookup: fix handling of hs-source-dirs: .

This commit is contained in:
Alexander Esgen 2022-07-15 14:48:32 +02:00 committed by Mark Karpov
parent 7fc42d1929
commit 84a3f0eaba
7 changed files with 34 additions and 1 deletions

View File

@ -6,6 +6,9 @@
* Indent closing bracket for list comprehensions in `do` blocks.
[Issue 893](https://github.com/tweag/ormolu/issues/893).
* Fix `hs-source-dirs: .` resulting in failing to find a `.cabal` file for a
Haskell source file. [Issue 909](https://github.com/tweag/ormolu/issues/909).
## Ormolu 0.5.0.0
* Changed the way operator fixities and precedences are inferred.

3
data/cabal-tests/Bar.hs Normal file
View File

@ -0,0 +1,3 @@
module Foo where
import Data.List qualified as List

3
data/cabal-tests/Foo.hs Normal file
View File

@ -0,0 +1,3 @@
module Foo where
import Data.List qualified as List

View File

@ -0,0 +1,13 @@
cabal-version: 2.4
name: test
version: 0
library
exposed-modules: Foo
hs-source-dirs: .
default-extensions: ImportQualifiedPost
executable app
main-is: Main
other-modules: Bar
default-extensions: ImportQualifiedPost

View File

@ -14,6 +14,7 @@ build-type: Simple
extra-source-files:
data/**/*.hs
data/**/*.txt
data/**/*.cabal
extract-hackage-info/hackage-info.json
extra-doc-files:

View File

@ -168,7 +168,7 @@ getExtensionAndDepsMap cabalFile GenericPackageDescription {..} =
extractFromBuildInfo extraModules BuildInfo {..} = (,(exts, deps)) $ do
m <- extraModules ++ (ModuleName.toFilePath <$> otherModules)
(takeDirectory cabalFile </>) <$> prependSrcDirs (dropExtensions m)
normalise . (takeDirectory cabalFile </>) <$> prependSrcDirs (dropExtensions m)
where
prependSrcDirs f
| null hsSourceDirs = [f]

View File

@ -42,3 +42,13 @@ spec = do
it "extracts correct dependencies from ormolu.cabal (tests/Ormolu/PrinterSpec.hs)" $ do
CabalInfo {..} <- parseCabalInfo "ormolu.cabal" "tests/Ormolu/PrinterSpec.hs"
ciDependencies `shouldBe` Set.fromList ["QuickCheck", "base", "containers", "directory", "filepath", "ghc-lib-parser", "hspec", "hspec-megaparsec", "megaparsec", "ormolu", "path", "path-io", "temporary", "text"]
it "handles `hs-source-dirs: .`" $ do
CabalInfo {..} <- parseTestCabalInfo "Foo.hs"
ciDynOpts `shouldContain` [DynOption "-XImportQualifiedPost"]
it "handles empty hs-source-dirs" $ do
CabalInfo {..} <- parseTestCabalInfo "Bar.hs"
ciDynOpts `shouldContain` [DynOption "-XImportQualifiedPost"]
where
parseTestCabalInfo f =
parseCabalInfo "data/cabal-tests/test.cabal" ("data/cabal-tests" </> f)