Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 59d4af0

Browse files
authored
Merge pull request #1031 from bubba/hspec-formatter
CI improvements
2 parents 60280ce + 11996fb commit 59d4af0

15 files changed

+172
-42
lines changed

.circleci/config.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defaults: &defaults
1818

1919
- run:
2020
name: Create a composite cabal file for changes detection
21-
command: find . -name "*.cabal" | grep -v "stack-work" | xargs cat > all-cabal.txt
21+
command: find . -name "*.cabal" | grep -v -e "stack-work" -e "dist-newstyle" -e "submodules" -e "testdata" | sort | xargs cat > all-cabal.txt
2222

2323
- restore_cache:
2424
keys:
@@ -52,7 +52,7 @@ defaults: &defaults
5252

5353
- run:
5454
name: Generate Hoogle database
55-
command: stack --stack-yaml=${STACK_FILE} exec hoogle generate
55+
command: if [ ! -d ~/.hoogle ]; then stack --stack-yaml=${STACK_FILE} exec hoogle generate; fi
5656

5757
- run:
5858
name: Clear cabal-helper cache
@@ -63,6 +63,7 @@ defaults: &defaults
6363
paths: &cache_paths
6464
- ~/.stack
6565
- ~/.cache
66+
- ~/.hoogle
6667
- ~/build/.stack-work
6768
- ~/build/hie-plugin-api/.stack-work
6869
- ~/build/submodules/HaRe/.stack-work
@@ -78,6 +79,9 @@ defaults: &defaults
7879
command: stack -j 1 --stack-yaml=${STACK_FILE} test --dump-logs
7980
no_output_timeout: 120m
8081

82+
- store_test_results:
83+
path: test-results
84+
8185
- store_artifacts:
8286
path: test-logs
8387

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ dist-newstyle/
6161
dist
6262
tags
6363
test-logs/
64+
test-results/
6465
.DS_Store
6566

6667
.hspec-failures

cabal.project

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,4 @@ packages:
66
./submodules/brittany
77
./submodules/cabal-helper/
88
./submodules/ghc-mod/
9-
./submodules/ghc-mod/core/
10-
11-
12-
-- allow-newer:ekg-core-0.1.1.4:base
13-
-- allow-newer:ekg-json-0.1.0.6:base
9+
./submodules/ghc-mod/core/

docs/CircleCI.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# CircleCI
2+
3+
## Jobs
4+
5+
For each version of GHC supported, CircleCI will kick off a build that will build and test HIE for that version.
6+
Whenever a new stack-x.y.z is added, be sure to also add it to both the `workflow` and `jobs` sections of `config.yml`.
7+
8+
In addition to the stack based jobs, there is also a job that builds HIE with `cabal new-build`.
9+
Currently tests are not run as there is an issue with cabal-helper-wrapper that prevents any ghc-mod tests from passing.
10+
11+
## Docker
12+
13+
Each job is carried out in a Docker container built from https://github.com/alanz/haskell-dockerfiles/blob/master/haskell-hie-ci/Dockerfile
14+
15+
## Caching
16+
17+
Since HIE takes a long time to build, CI caches things very liberally.
18+
Most importantly, the `~/.stack-work` directories for HIE as well as every submodule are cached before and after testing (This is so that if the build passes but the tests fail there is still something cached for the next build).
19+
20+
### Change detection
21+
22+
Before restoring any cache, the CircleCI job creates three files and uses their checksum to detect any changes:
23+
24+
1. `all-cabal.txt` detects any changes to `.cabal` files (not in submodules or test data)
25+
2. `stack-build.txt` detects any changes to the `stack-x.y.z` file
26+
3. `resolver.txt` detects any changes to the stack resolver
27+
28+
Each job will tries to restore the most specific cache avaialble for it, and fallback to a more general cache if not available:
29+
30+
31+
```yaml
32+
- restore_cache:
33+
keys:
34+
- stack-cache-{{ .Environment.HIE_CACHE }}-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "stack-build.txt" }}-{{ checksum "all-cabal.txt" }}
35+
- stack-cache-{{ .Environment.HIE_CACHE }}-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "stack-build.txt" }}
36+
- stack-cache-{{ .Environment.HIE_CACHE }}-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "resolver.txt" }}
37+
```
38+
39+
## Invalidating the cache
40+
41+
If you need to clear the cache on CircleCI, bump the `$HIE_CACHE` environment variable via the CircleCI web interface and rerun the workflow.

haskell-ide-engine.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,15 @@ library hie-test-utils
144144
, haskell-lsp
145145
, hie-plugin-api
146146
, aeson
147+
, blaze-markup
147148
, containers
148149
, data-default
149150
, directory
150151
, filepath
151152
, ghc-mod-core
152153
, hslogger
153154
, hspec
155+
, hspec-core
154156
, stm
155157
, text
156158
, unordered-containers

stack-8.6.1.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ extra-deps:
3434
- temporary-1.2.1.1
3535
- yaml-0.8.32
3636

37-
3837
flags:
3938
haskell-ide-engine:
4039
pedantic: true

stack-8.6.3.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ extra-deps:
2323
- temporary-1.2.1.1
2424
- yaml-0.8.32
2525

26-
2726
flags:
2827
haskell-ide-engine:
2928
pedantic: true

test/dispatcher/Main.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import System.Directory
2323
import System.FilePath
2424

2525
import Test.Hspec
26+
import Test.Hspec.Runner
2627

2728
-- ---------------------------------------------------------------------
2829
-- plugins
@@ -40,8 +41,9 @@ import Haskell.Ide.Engine.Plugin.HieExtras
4041
main :: IO ()
4142
main = do
4243
setupStackFiles
44+
config <- getHspecFormattedConfig "dispatcher"
4345
withFileLogging "main-dispatcher.log" $ do
44-
hspec funcSpec
46+
hspecWith config funcSpec
4547

4648
-- main :: IO ()
4749
-- main = do

test/functional/Main.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Main where
33
import Control.Monad.IO.Class
44
import Language.Haskell.LSP.Test
55
import qualified FunctionalSpec
6-
import Test.Hspec
6+
import Test.Hspec.Runner (hspecWith)
77
import TestUtils
88

99
main :: IO ()
@@ -13,5 +13,6 @@ main = do
1313
putStrLn "Warming up HIE cache..."
1414
runSessionWithConfig (defaultConfig { messageTimeout = 120 }) hieCommand fullCaps "test/testdata" $
1515
liftIO $ putStrLn "HIE cache is warmed up"
16-
-- withFileLogging "functional.log" $ hspec FunctionalSpec.spec
17-
withFileLogging logFilePath $ hspec FunctionalSpec.spec
16+
17+
config <- getHspecFormattedConfig "functional"
18+
withFileLogging logFilePath $ hspecWith config $ FunctionalSpec.spec

test/plugin-dispatcher/Main.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import Language.Haskell.LSP.Types
1414
import TestUtils
1515

1616
import Test.Hspec
17+
import Test.Hspec.Runner
1718

1819
-- ---------------------------------------------------------------------
1920

2021
main :: IO ()
2122
main = do
2223
setupStackFiles
23-
withFileLogging "plugin-dispatcher.log" $ do
24-
hspec newPluginSpec
24+
config <- getHspecFormattedConfig "plugin-dispatcher"
25+
withFileLogging "plugin-dispatcher.log" $ hspecWith config newPluginSpec
2526

2627
-- ---------------------------------------------------------------------
2728

test/unit/ApplyRefactPluginSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ applyRefactSpec = do
134134
filePath <- filePathToUri <$> makeAbsolute "./test/testdata/HlintPragma.hs"
135135

136136
let req = lintCmd' filePath
137-
r <- cdAndDo "./test/testdata" $ runIGM testPlugins req
137+
r <- withCurrentDirectory "./test/testdata" $ runIGM testPlugins req
138138
r `shouldBe`
139139
(IdeResultOk
140140
(PublishDiagnosticsParams

test/unit/GhcModPluginSpec.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ testPlugins = pluginDescToIdePlugins [ghcmodDescriptor "ghcmod"]
3939
ghcmodSpec :: Spec
4040
ghcmodSpec =
4141
describe "ghc-mod plugin commands(old plugin api)" $ do
42-
it "runs the check command" $ cdAndDo "./test/testdata" $ do
42+
it "runs the check command" $ withCurrentDirectory "./test/testdata" $ do
4343
fp <- makeAbsolute "./FileWithWarning.hs"
4444
let act = setTypecheckedModule arg
4545
arg = filePathToUri fp
@@ -57,7 +57,7 @@ ghcmodSpec =
5757

5858
-- ---------------------------------
5959

60-
it "runs the lint command" $ cdAndDo "./test/testdata" $ do
60+
it "runs the lint command" $ withCurrentDirectory "./test/testdata" $ do
6161
fp <- makeAbsolute "FileWithWarning.hs"
6262
let uri = filePathToUri fp
6363
act = lintCmd' uri
@@ -71,7 +71,7 @@ ghcmodSpec =
7171

7272
-- ---------------------------------
7373

74-
it "runs the info command" $ cdAndDo "./test/testdata" $ do
74+
it "runs the info command" $ withCurrentDirectory "./test/testdata" $ do
7575
fp <- makeAbsolute "HaReRename.hs"
7676
let uri = filePathToUri fp
7777
act = infoCmd' uri "main"
@@ -82,7 +82,7 @@ ghcmodSpec =
8282

8383
-- ---------------------------------
8484

85-
it "runs the type command" $ cdAndDo "./test/testdata" $ do
85+
it "runs the type command" $ withCurrentDirectory "./test/testdata" $ do
8686
fp <- makeAbsolute "HaReRename.hs"
8787
let uri = filePathToUri fp
8888
act = do
@@ -117,7 +117,7 @@ ghcmodSpec =
117117

118118
-- ---------------------------------
119119

120-
it "runs the casesplit command" $ cdAndDo "./test/testdata" $ do
120+
it "runs the casesplit command" $ withCurrentDirectory "./test/testdata" $ do
121121
fp <- makeAbsolute "GhcModCaseSplit.hs"
122122
let uri = filePathToUri fp
123123
act = do

test/unit/HaRePluginSpec.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ testPlugins = pluginDescToIdePlugins [hareDescriptor "hare"]
4343

4444
dispatchRequestPGoto :: IdeGhcM a -> IO a
4545
dispatchRequestPGoto =
46-
cdAndDo "./test/testdata/gototest"
46+
withCurrentDirectory "./test/testdata/gototest"
4747
. runIGM testPlugins
4848

4949
-- ---------------------------------------------------------------------
@@ -54,7 +54,7 @@ hareSpec = do
5454
cwd <- runIO getCurrentDirectory
5555
-- ---------------------------------
5656

57-
it "renames" $ cdAndDo "test/testdata" $ do
57+
it "renames" $ withCurrentDirectory "test/testdata" $ do
5858

5959
let uri = filePathToUri $ cwd </> "test/testdata/HaReRename.hs"
6060
act = renameCmd' uri (toPos (5,1)) "foolong"
@@ -67,7 +67,7 @@ hareSpec = do
6767

6868
-- ---------------------------------
6969

70-
it "returns an error for invalid rename" $ cdAndDo "test/testdata" $ do
70+
it "returns an error for invalid rename" $ withCurrentDirectory "test/testdata" $ do
7171
let uri = filePathToUri $ cwd </> "test/testdata/HaReRename.hs"
7272
act = renameCmd' uri (toPos (15,1)) "foolong"
7373
arg = HPT uri (toPos (15,1)) "foolong"
@@ -78,7 +78,7 @@ hareSpec = do
7878

7979
-- ---------------------------------
8080

81-
it "demotes" $ cdAndDo "test/testdata" $ do
81+
it "demotes" $ withCurrentDirectory "test/testdata" $ do
8282
let uri = filePathToUri $ cwd </> "test/testdata/HaReDemote.hs"
8383
act = demoteCmd' uri (toPos (6,1))
8484
arg = HP uri (toPos (6,1))
@@ -90,7 +90,7 @@ hareSpec = do
9090

9191
-- ---------------------------------
9292

93-
it "duplicates a definition" $ cdAndDo "test/testdata" $ do
93+
it "duplicates a definition" $ withCurrentDirectory "test/testdata" $ do
9494
let uri = filePathToUri $ cwd </> "test/testdata/HaReRename.hs"
9595
act = dupdefCmd' uri (toPos (5,1)) "foonew"
9696
arg = HPT uri (toPos (5,1)) "foonew"
@@ -102,7 +102,7 @@ hareSpec = do
102102

103103
-- ---------------------------------
104104

105-
it "converts if to case" $ cdAndDo "test/testdata" $ do
105+
it "converts if to case" $ withCurrentDirectory "test/testdata" $ do
106106

107107
let uri = filePathToUri $ cwd </> "test/testdata/HaReCase.hs"
108108
act = iftocaseCmd' uri (Range (toPos (5,9))
@@ -117,7 +117,7 @@ hareSpec = do
117117

118118
-- ---------------------------------
119119

120-
it "lifts one level" $ cdAndDo "test/testdata" $ do
120+
it "lifts one level" $ withCurrentDirectory "test/testdata" $ do
121121

122122
let uri = filePathToUri $ cwd </> "test/testdata/HaReMoveDef.hs"
123123
act = liftonelevelCmd' uri (toPos (6,5))
@@ -131,7 +131,7 @@ hareSpec = do
131131

132132
-- ---------------------------------
133133

134-
it "lifts to top level" $ cdAndDo "test/testdata" $ do
134+
it "lifts to top level" $ withCurrentDirectory "test/testdata" $ do
135135

136136
let uri = filePathToUri $ cwd </> "test/testdata/HaReMoveDef.hs"
137137
act = lifttotoplevelCmd' uri (toPos (12,9))
@@ -147,7 +147,7 @@ hareSpec = do
147147

148148
-- ---------------------------------
149149

150-
it "deletes a definition" $ cdAndDo "test/testdata" $ do
150+
it "deletes a definition" $ withCurrentDirectory "test/testdata" $ do
151151
let uri = filePathToUri $ cwd </> "test/testdata/FuncTest.hs"
152152
act = deleteDefCmd' uri (toPos (6,1))
153153
arg = HP uri (toPos (6,1))
@@ -159,7 +159,7 @@ hareSpec = do
159159

160160
-- ---------------------------------
161161

162-
it "generalises an applicative" $ cdAndDo "test/testdata" $ do
162+
it "generalises an applicative" $ withCurrentDirectory "test/testdata" $ do
163163
let uri = filePathToUri $ cwd </> "test/testdata/HaReGA1.hs"
164164
act = genApplicativeCommand' uri (toPos (4,1))
165165
arg = HP uri (toPos (4,1))

test/unit/Main.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import qualified Spec
99
main :: IO ()
1010
main = do
1111
setupStackFiles
12-
withFileLogging "main.log" $ hspec Spec.spec
12+
config <- getHspecFormattedConfig "unit"
13+
withFileLogging "main.log" $ hspecWith config $ Spec.spec
1314

1415
-- main :: IO ()
1516
-- main = do

0 commit comments

Comments
 (0)