Skip to content

Commit

Permalink
Merge pull request #1 from andys8/update-haskell-ghc-92
Browse files Browse the repository at this point in the history
  • Loading branch information
kazk authored Sep 8, 2022
2 parents c54a130 + 6941b69 commit a905e36
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 50 deletions.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
dist/
dist-newstyle/
dist
dist-*
cabal-dev
*.o
*.hi
*.hie
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ main = hspecWith defaultConfig {configFormatter = Just codewars} Spec.spec
-- test/Spec.hs
{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --module-name=Spec #-}
```

## Development

```shell
cabal install
cabal test
```
49 changes: 49 additions & 0 deletions cabal.project.freeze
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
active-repositories: hackage.haskell.org:merge
constraints: any.HUnit ==1.6.2.0,
any.QuickCheck ==2.14.2,
QuickCheck -old-random +templatehaskell,
any.ansi-terminal ==0.11.3,
ansi-terminal -example,
any.array ==0.5.4.0,
any.base ==4.16.3.0,
any.binary ==0.8.9.0,
any.bytestring ==0.11.3.1,
any.call-stack ==0.4.0,
any.colour ==2.3.6,
any.containers ==0.6.5.1,
any.deepseq ==1.4.6.1,
any.directory ==1.3.6.2,
any.exceptions ==0.10.4,
any.filepath ==1.4.2.2,
any.ghc ==9.2.4,
any.ghc-bignum ==1.2,
any.ghc-boot ==9.2.4,
any.ghc-boot-th ==9.2.4,
any.ghc-heap ==9.2.4,
any.ghc-prim ==0.8.0,
any.ghci ==9.2.4,
any.hpc ==0.6.1.0,
any.hspec ==2.10.4,
any.hspec-core ==2.10.4,
any.hspec-discover ==2.10.4,
any.hspec-expectations ==0.8.2,
any.mtl ==2.2.2,
any.pretty ==1.1.3.6,
any.primitive ==0.7.4.0,
any.process ==1.6.13.2,
any.quickcheck-io ==0.2.0,
any.random ==1.2.1.1,
any.rts ==1.0.2,
any.setenv ==0.1.1.3,
any.splitmix ==0.1.0.4,
splitmix -optimised-mixer,
any.stm ==2.5.0.2,
any.template-haskell ==2.18.0.0,
any.terminfo ==0.4.1.5,
any.text ==2.0.1,
text -developer +simdutf,
any.tf-random ==0.5,
any.time ==1.11.1.1,
any.transformers ==0.5.6.2,
any.unix ==2.7.2.2
index-state: hackage.haskell.org 2022-09-07T06:34:06Z
6 changes: 6 additions & 0 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cradle:
cabal:
- path: "src"
component: "lib:hspec-formatters-codewars"
- path: "test"
component: "hspec-formatters-codewars:test:hspec-formatters-codewars-spec"
51 changes: 33 additions & 18 deletions hspec-formatters-codewars.cabal
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
cabal-version: >=1.10

name: hspec-formatters-codewars
version: 0.1.0
synopsis: Hspec formatter for Codewars
homepage: https://githuc.com/codewars/hspec-formatters-codewars
license: MIT
build-type: Simple
cabal-version: 2.4
name: hspec-formatters-codewars
version: 0.1.0
synopsis: Hspec formatter for Codewars
homepage: https://github.com/codewars/hspec-formatters-codewars
license: MIT
build-type: Simple

library
hs-source-dirs:
src
hs-source-dirs: src
build-depends:
, base >=4 && <5
, hspec >=2.8 && <3
, hspec-core >=2.8 && <3
, text >=2 && <3

exposed-modules: Test.Hspec.Formatters.Codewars
default-language: GHC2021

test-suite hspec-formatters-codewars-spec
type: exitcode-stdio-1.0
default-language: GHC2021
main-is: Main.hs
hs-source-dirs: test src
build-depends:
base ==4.*
, hspec ==2.*
, hspec-core ==2.*
, text ==1.*
exposed-modules:
Test.Hspec.Formatters.Codewars
default-language:
Haskell2010
, base >=4 && <5
, hspec >=2.8 && <3
, hspec-core >=2.8 && <3
, text >=2 && <3

other-modules:
Spec
Spec.ExampleSpec
Test.Hspec.Formatters.Codewars

build-tool-depends: hspec-discover:hspec-discover >=2 && <3
62 changes: 30 additions & 32 deletions src/Test/Hspec/Formatters/Codewars.hs
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
{-# LANGUAGE OverloadedStrings #-}
module Test.Hspec.Formatters.Codewars
(
codewars
) where

import Data.Text (pack, unpack, replace)
module Test.Hspec.Formatters.Codewars (codewars) where

import Test.Hspec.Formatters (Formatter (..),
FailureReason (..),
formatException,
silent,
writeLine)
import Data.Text (pack, replace, unpack)

codewars :: Formatter
codewars = silent {
exampleGroupStarted = \_ name -> do
writeLine ""
writeLine $ escapeLF $ "<DESCRIBE::>" ++ name

, exampleGroupDone = writeLine "\n<COMPLETEDIN::>"
import Test.Hspec.Core.Formatters.V1 (
FailureReason (..),
Formatter (..),
formatException,
silent,
writeLine,
)

, exampleSucceeded = \(_, name) _ -> do
writeLine ""
writeLine $ escapeLF $ "<IT::>" ++ name
writeLine "\n<PASSED::>Test Passed"
writeLine "\n<COMPLETEDIN::>"

, exampleFailed = \(_, name) _ reason -> do
writeLine ""
writeLine $ escapeLF $ "<IT::>" ++ name
writeLine ""
writeLine $ escapeLF $ reasonAsString reason
writeLine "\n<COMPLETEDIN::>"
}
codewars :: Formatter
codewars =
silent
{ exampleGroupStarted = \_ name -> do
writeLine ""
writeLine $ escapeLF $ "<DESCRIBE::>" ++ name
, exampleGroupDone = writeLine "\n<COMPLETEDIN::>"
, exampleSucceeded = \(_, name) _ -> do
writeLine ""
writeLine $ escapeLF $ "<IT::>" ++ name
writeLine "\n<PASSED::>Test Passed"
writeLine "\n<COMPLETEDIN::>"
, exampleFailed = \(_, name) _ reason -> do
writeLine ""
writeLine $ escapeLF $ "<IT::>" ++ name
writeLine ""
writeLine $ escapeLF $ reasonAsString reason
writeLine "\n<COMPLETEDIN::>"
}

reasonAsString :: FailureReason -> String
reasonAsString reason =
Expand All @@ -44,9 +42,9 @@ reasonAsString reason =
ExpectedButGot (Just src) expected got ->
"<FAILED::>" ++ src ++ " expected " ++ expected ++ " but got " ++ got
Error Nothing err ->
"<ERROR::>" ++ (formatException err)
"<ERROR::>" ++ formatException err
Error (Just s) err ->
"<ERROR::>" ++ s ++ (formatException err)
"<ERROR::>" ++ s ++ formatException err

escapeLF :: String -> String
escapeLF = unpack . replace "\n" "<:LF:>" . pack
9 changes: 9 additions & 0 deletions test/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Main where

import Test.Hspec.Runner
import Test.Hspec.Formatters.Codewars (codewars)

import qualified Spec

main :: IO ()
main = hspecWith defaultConfig {configFormatter = Just codewars} Spec.spec
1 change: 1 addition & 0 deletions test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --module-name=Spec #-}
11 changes: 11 additions & 0 deletions test/Spec/ExampleSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Spec.ExampleSpec where

import Test.Hspec

spec :: Spec
spec = describe "ExampleSpec" $ do
it "can parse integers" $ do
read "10" `shouldBe` (10 :: Int)

it "can parse floating-point numbers" $ do
read "2.5" `shouldBe` (2.5 :: Float)

0 comments on commit a905e36

Please sign in to comment.