Skip to content

Commit 9a77111

Browse files
committed
Fix tests
1 parent 62e4f18 commit 9a77111

File tree

6 files changed

+44
-28
lines changed

6 files changed

+44
-28
lines changed

app/Main.hs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ main = do
1919
pwd <- getCurrentDirectory
2020
files <- listDirectory pwd
2121
cfs <- cabalFiles pwd
22-
let cabal = (cabalComponent, "cabal")
23-
stack = (stackComponent, "stack")
24-
(fmt, name) =
25-
if | any (("dist-newstyle" ==) . takeFileName) files -> cabal
26-
| any ((".stack-work" ==) . takeFileName) files -> stack
27-
| any (("stack.yaml" ==) . takeFileName) files -> stack
28-
| otherwise -> cabal
22+
let name =
23+
if | any (("dist-newstyle" ==) . takeFileName) files -> "cabal"
24+
| any ((".stack-work" ==) . takeFileName) files -> "stack"
25+
| any (("stack.yaml" ==) . takeFileName) files -> "stack"
26+
| otherwise -> "cabal"
2927
gen f = do
3028
f' <- T.readFile f
3129
case parsePackage' f' of
@@ -49,8 +47,7 @@ main = do
4947
<> pwd
5048
<> "\n You may need to run stack build."
5149
pkgs <- catMaybes <$> mapM gen cfs
52-
putStr <$> hieYaml name $ unlines $
53-
concatMap (\(Package n cs) -> map ((<> "\n") . fmtComponent . fmt n) cs) pkgs
50+
putStr <$> hieYaml name $ fmtPkgs name pkgs
5451

5552
cabalFiles :: FilePath -> IO [FilePath]
5653
cabalFiles f = do

implicit-hie.cabal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cabal-version: 1.12
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: ee9bceb3ed6e6ee053acc1dc9dde3033fed8e9f565a8c8bbdfa52f9be9c507aa
7+
-- hash: 19d5dbbfaaca0af267a9130152cdf8d4a25d59ddd71229a803bfa48283606994
88

99
name: implicit-hie
1010
version: 0.1.0.0
@@ -33,7 +33,7 @@ library
3333
Paths_implicit_hie
3434
hs-source-dirs:
3535
src
36-
ghc-options: -O2 -flate-specialise -fexpose-all-unfoldings -fspecialize-aggressively -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns -fno-warn-unused-imports -fno-warn-unused-binds -fno-warn-name-shadowing -fwarn-redundant-constraints
36+
ghc-options: -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns -fno-warn-unused-imports -fno-warn-unused-binds -fno-warn-name-shadowing -fwarn-redundant-constraints
3737
build-depends:
3838
attoparsec
3939
, base >=4.7 && <5
@@ -47,7 +47,7 @@ executable gen-hie
4747
Paths_implicit_hie
4848
hs-source-dirs:
4949
app
50-
ghc-options: -O2 -flate-specialise -fexpose-all-unfoldings -fspecialize-aggressively -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns -fno-warn-unused-imports -fno-warn-unused-binds -fno-warn-name-shadowing -fwarn-redundant-constraints -threaded -rtsopts -with-rtsopts=-N
50+
ghc-options: -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns -fno-warn-unused-imports -fno-warn-unused-binds -fno-warn-name-shadowing -fwarn-redundant-constraints -threaded -rtsopts -with-rtsopts=-N
5151
build-depends:
5252
attoparsec
5353
, base >=4.7 && <5
@@ -65,7 +65,7 @@ test-suite implicit-hie-test
6565
Paths_implicit_hie
6666
hs-source-dirs:
6767
test
68-
ghc-options: -O2 -flate-specialise -fexpose-all-unfoldings -fspecialize-aggressively -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns -fno-warn-unused-imports -fno-warn-unused-binds -fno-warn-name-shadowing -fwarn-redundant-constraints -threaded -rtsopts -with-rtsopts=-N
68+
ghc-options: -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns -fno-warn-unused-imports -fno-warn-unused-binds -fno-warn-name-shadowing -fwarn-redundant-constraints -threaded -rtsopts -with-rtsopts=-N
6969
build-depends:
7070
attoparsec
7171
, base >=4.7 && <5

package.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ dependencies:
2626
- yaml
2727

2828
ghc-options:
29-
- -O2
30-
- -flate-specialise
31-
- -fexpose-all-unfoldings
32-
- -fspecialize-aggressively
29+
# - -O2
30+
# - -flate-specialise
31+
# - -fexpose-all-unfoldings
32+
# - -fspecialize-aggressively
3333
- -Wall
3434
- -Wincomplete-record-updates
3535
- -Wincomplete-uni-patterns

src/Hie/Yaml.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Hie.Yaml
44
( hieYaml,
55
fmtComponent,
6+
fmtPkgs,
67
cabalComponent,
78
stackComponent,
89
)
@@ -49,5 +50,15 @@ fmtComponent (p, c) =
4950
<> "component: "
5051
<> dQuote c
5152

53+
dropLast :: [a] -> [a]
54+
dropLast l = take (length l - 1) l
55+
56+
fmtPkgs :: String -> [Package] -> String
57+
fmtPkgs sOrC pkgs = dropLast $ unlines l
58+
where
59+
comp = if sOrC == "cabal" then cabalComponent else stackComponent
60+
f (Package n cs) = map ((<> "\n") . fmtComponent . comp n) cs
61+
l = concatMap f pkgs
62+
5263
dQuote :: String -> String
5364
dQuote t = '"' : t <> "\""

test/Spec.hs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ spec = do
1717
describe "Should Succeed"
1818
$ it "successfully parses executable section"
1919
$ exeSection ~> parseExe 0
20-
`shouldParse` Exe "implicit-hie-exe" "app/Main.hs"
20+
`shouldParse` Comp Exe "implicit-hie-exe" "app/Main.hs"
2121
describe "Should Succeed"
2222
$ it "successfully parses test section"
2323
$ testSection ~> parseTestSuite 0
24-
`shouldParse` Test "implicit-hie-test" "test"
24+
`shouldParse` Comp Test "implicit-hie-test" "test"
2525
describe "Should Succeed"
2626
$ it "successfully parses library section"
2727
$ libSection ~> parseLib 0
28-
`shouldParse` Lib "" "src"
28+
`shouldParse` Comp Lib "" "src"
2929
describe "Should Succeed"
3030
$ it "successfully parses bench section"
3131
$ benchSection ~> parseBench 0
32-
`shouldParse` Bench "folds" "benchmarks/folds.hs"
32+
`shouldParse` Comp Bench "folds" "benchmarks/folds.hs"
3333
describe "Should Succeed"
3434
$ it "successfully parses package"
3535
$ fullFile ~> parsePackage
3636
`shouldParse` Package
3737
"implicit-hie"
38-
[ Lib "" "src",
39-
Exe "implicit-hie-exe" "app/Main.hs",
40-
Test "implicit-hie-test" "test"
38+
[ Comp Lib "" "src",
39+
Comp Exe "implicit-hie-exe" "app/Main.hs",
40+
Comp Test "implicit-hie-test" "test"
4141
]
4242
describe "Should Succeed"
4343
$ it
@@ -47,13 +47,15 @@ spec = do
4747
`leavesUnconsumed` r
4848
describe "Should Succeed"
4949
$ it "successfully generates stack hie.yaml"
50-
$ (stackHieYaml <$> parseOnly parsePackage fullFile) `shouldBe` Right stackHie
50+
$ (hieYaml "stack" . fmtPkgs "stack" . (: []) <$> parseOnly parsePackage fullFile)
51+
`shouldBe` Right stackHie
5152
describe "Should Succeed"
5253
$ it "successfully generates stack hie.yaml"
5354
$ do
5455
f <- T.readFile "test/haskell-language-server-cabal"
55-
o <- T.readFile "test/hie.yaml.cbl"
56-
(cabalHieYaml <$> parseOnly parsePackage f) `shouldBe` Right o
56+
o <- readFile "test/hie.yaml.cbl"
57+
(hieYaml "cabal" . fmtPkgs "cabal" . (: []) <$> parseOnly parsePackage f)
58+
`shouldBe` Right o
5759

5860
fullFile :: Text
5961
fullFile = "name: implicit-hie\n" <> libSection <> exeSection <> testSection
@@ -113,14 +115,16 @@ benchSection =
113115
\ type: exitcode-stdio-1.0\n\
114116
\ main-is: folds.hs\n"
115117

116-
stackHie :: Text
118+
stackHie :: String
117119
stackHie =
118120
"cradle:\n\
119121
\ stack:\n\
120122
\ - path: \"src\"\n\
121123
\ component: \"implicit-hie:lib\"\n\
124+
\\n\
122125
\ - path: \"app/Main.hs\"\n\
123126
\ component: \"implicit-hie:exe:implicit-hie-exe\"\n\
127+
\\n\
124128
\ - path: \"test\"\n\
125129
\ component: \"implicit-hie:test:implicit-hie-test\"\n\
126130
\"

test/hie.yaml.cbl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ cradle:
22
cabal:
33
- path: "src"
44
component: "lib:haskell-language-server"
5+
56
- path: "exe/Main.hs"
67
component: "haskell-language-server:exe:haskell-language-server"
8+
79
- path: "exe/Wrapper.hs"
810
component: "haskell-language-server:exe:haskell-language-server-wrapper"
11+
912
- path: "test/functional"
1013
component: "haskell-language-server:test:func-test"
14+
1115
- path: "test/utils"
1216
component: "lib:haskell-language-server:hls-test-utils"

0 commit comments

Comments
 (0)