Skip to content

Commit 7a8a9ed

Browse files
authored
Add testing support on ghc >= 9.4 (#21)
* build: move from deprecated gh action, invalidate cache * build: move to newer, more performant cabal * build: run gh-actions on ghc 9.12 * build: add support for newer dependencies when testing * fix: tests on ghc >= 9.4 * build: remove support for ghc ^>= 9.0 and 9.2 * build: no longer test on unsupported ghc 9.0 and 9.2 * build: use recommended caching system * build: use alternative caching mechanism * chore: remove unused test comparison
1 parent 72b3698 commit 7a8a9ed

File tree

4 files changed

+70
-55
lines changed

4 files changed

+70
-55
lines changed

.github/workflows/cabal.yml

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,53 @@
11
name: cabal
2-
32
on:
43
push:
5-
branches: [ main ]
4+
branches: [main]
65
pull_request:
7-
branches: [ '*' ]
8-
6+
branches: ['*']
97
jobs:
108
build:
119
runs-on: ubuntu-20.04
1210
strategy:
1311
fail-fast: false
1412
matrix:
15-
ghc: ["8.6", "8.8", "8.10", "9.0", "9.2", "9.4"]
16-
cabal: ["3.6"]
17-
cache-version: ["2022-10-25"]
18-
13+
ghc-version: ["8.6", "8.8", "8.10", "9.4", "9.6", "9.8", "9.12"]
14+
cabal-version: ["3.12"]
15+
cache-version: ["2025-01-01"]
1916
steps:
20-
- uses: actions/checkout@v2
21-
- uses: haskell/actions/setup@v2
22-
with:
23-
ghc-version: ${{ matrix.ghc }}
24-
cabal-version: ${{ matrix.cabal }}
25-
26-
- name: Cache ~/.cabal/store
27-
uses: actions/cache@v3
28-
with:
29-
path: |
30-
~/.cabal/store
31-
dist-newstyle
32-
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ matrix.cache-version }}-cabal
33-
34-
- name: Install dependencies
35-
run: |
36-
cabal update
37-
cabal configure --disable-optimization --enable-tests --write-ghc-environment-files=always -j2
38-
cabal build --only-dependencies
39-
40-
- name: Build & Test
41-
run: |
42-
cabal build --flag dev
43-
cabal test --flag dev
17+
- uses: actions/checkout@v4
18+
- name: Set up GHC ${{ matrix.ghc-version }}
19+
uses: haskell-actions/setup@v2
20+
id: setup
21+
with:
22+
ghc-version: ${{ matrix.ghc-version }}
23+
cabal-version: ${{ matrix.cabal-version }}
24+
cabal-update: true
25+
- name: Configure the build
26+
run: |
27+
cabal configure --enable-tests --disable-documentation --disable-optimization --write-ghc-environment-files=always -j2
28+
cabal build all --dry-run
29+
- name: Restore cached dependencies
30+
uses: actions/cache/restore@v4
31+
id: cache
32+
env:
33+
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}-${{ matrix.cache-version }}
34+
with:
35+
path: ${{ steps.setup.outputs.cabal-store }}
36+
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
37+
restore-keys: ${{ env.key }}-
38+
- name: Install dependencies
39+
# If we had an exact cache hit, the dependencies will be up to date.
40+
if: steps.cache.outputs.cache-hit != 'true'
41+
run: cabal build all --only-dependencies
42+
# Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
43+
- name: Save cached dependencies
44+
uses: actions/cache/save@v4
45+
# If we had an exact cache hit, trying to save the cache would error because of key clash.
46+
if: steps.cache.outputs.cache-hit != 'true'
47+
with:
48+
path: ${{ steps.setup.outputs.cabal-store }}
49+
key: ${{ steps.cache.outputs.cache-primary-key }}
50+
- name: Build
51+
run: cabal build all --flag dev
52+
- name: Run tests
53+
run: cabal test all --flag dev

haskell-stack-trace-plugin.cabal

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extra-source-files:
2020
CHANGELOG.md
2121
Readme.md
2222

23-
tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.4 || ==9.4.8 || ==9.6.6 || ==9.8.4 || ==9.10.1 || ==9.12.1
23+
tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.4.8 || ==9.6.6 || ==9.8.4 || ==9.10.1 || ==9.12.1
2424

2525
source-repository head
2626
type: git
@@ -38,7 +38,7 @@ common common-opts
3838
library
3939
import: common-opts
4040
hs-source-dirs: src
41-
build-depends: ghc ^>=8.6 || ^>=8.8 || ^>=8.10 || ^>=9.0 || ^>=9.2 || ^>=9.4 || ^>=9.6 || ^>=9.8 || ^>=9.10 || ^>=9.12
41+
build-depends: ghc ^>=8.6 || ^>=8.8 || ^>=8.10 || ^>=9.4 || ^>=9.6 || ^>=9.8 || ^>=9.10 || ^>=9.12
4242
exposed-modules: StackTrace.Plugin
4343

4444
if flag(dev)
@@ -55,8 +55,10 @@ test-suite test
5555
hs-source-dirs: test
5656
type: exitcode-stdio-1.0
5757
build-depends:
58-
, bytestring >=0.10 && <0.12
59-
, hspec ^>=2.8
58+
, bytestring >=0.10
59+
, hspec ^>=2.8 || ^>=2.11
60+
, raw-strings-qq ^>=1.1
61+
, regex-tdfa ^>=1.3
6062
, typed-process ^>=0.2
6163

6264
build-tool-depends: hspec-discover:hspec-discover ^>=2.8

test/StackTrace/PluginSpec.hs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE QuasiQuotes #-}
3+
24
module StackTrace.PluginSpec (spec) where
35

46
import Data.ByteString.Lazy (ByteString)
5-
import qualified Data.ByteString.Lazy as BL
6-
import Test.Hspec
7+
import qualified Data.ByteString.Lazy.Char8 as BS
78
import System.Process.Typed
9+
import Test.Hspec
10+
import Text.RawString.QQ
11+
import Text.Regex.TDFA ((=~))
12+
13+
-- | Extracts the function names of all functions that appear in a stack trace
14+
extractStackTraceFunctions :: String -> [String]
15+
extractStackTraceFunctions input = map extractFunctionName matches
16+
where
17+
regex = [r|[ ]*([A-Za-z0-9]+), called at example/Main.hs:[0-9]+:[0-9]+ in [^:]+:Main|] :: String
18+
matches = (input =~ regex) :: [[String]]
19+
extractFunctionName :: [String] -> String
20+
extractFunctionName (_ : name : _) = name
21+
extractFunctionName _ = error "Regex match failed"
822

923
spec :: Spec
1024
spec = do
1125
output <- runIO exe
12-
expected <- runIO $ BL.readFile "test/resource/ghc.output"
13-
it "integration test" $ output `shouldBe` expected
26+
let outputStr = BS.unpack output
27+
let extractedFunctions = extractStackTraceFunctions outputStr
28+
29+
-- each of these exceptions should appear in the stack trace
30+
let expectedFunctions = ["error", "fError", "f10", "f9", "f8", "f7", "f6", "f5", "f4", "f3", "f2", "f1", "main"] :: [String]
1431

32+
it "integration test" $ extractedFunctions `shouldBe` expectedFunctions
1533

1634
exe :: IO ByteString
1735
exe = do

test/resource/ghc.output

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)