From 520548e8ecda0c018ffd612f24364f38a05b8f7b Mon Sep 17 00:00:00 2001 From: andys8 Date: Wed, 7 Sep 2022 16:05:14 +0200 Subject: [PATCH 1/3] Update to GHC 9.2 --- .gitignore | 23 ++++++++++ README.md | 7 +++ cabal.project.freeze | 49 +++++++++++++++++++++ hie.yaml | 6 +++ hspec-formatters-codewars.cabal | 51 ++++++++++++++-------- src/Test/Hspec/Formatters/Codewars.hs | 62 +++++++++++++-------------- test/Main.hs | 9 ++++ test/Spec.hs | 1 + test/Spec/ExampleSpec.hs | 11 +++++ 9 files changed, 169 insertions(+), 50 deletions(-) create mode 100644 cabal.project.freeze create mode 100644 hie.yaml create mode 100644 test/Main.hs create mode 100644 test/Spec.hs create mode 100644 test/Spec/ExampleSpec.hs diff --git a/.gitignore b/.gitignore index fd5ffbe..686c38d 100644 --- a/.gitignore +++ b/.gitignore @@ -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.* diff --git a/README.md b/README.md index cbb9737..f96e5a7 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/cabal.project.freeze b/cabal.project.freeze new file mode 100644 index 0000000..901b2c8 --- /dev/null +++ b/cabal.project.freeze @@ -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 diff --git a/hie.yaml b/hie.yaml new file mode 100644 index 0000000..1b91631 --- /dev/null +++ b/hie.yaml @@ -0,0 +1,6 @@ +cradle: + cabal: + - path: "src" + component: "lib:hspec-formatters-codewars" + - path: "test" + component: "hspec-formatters-codewars:test:hspec-formatters-codewars-spec" diff --git a/hspec-formatters-codewars.cabal b/hspec-formatters-codewars.cabal index e90aeab..bca4825 100644 --- a/hspec-formatters-codewars.cabal +++ b/hspec-formatters-codewars.cabal @@ -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://githuc.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 && <3 + , hspec-core >=2 && <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 && <3 + , hspec-core >=2 && <3 + , text >=2 && <3 + + other-modules: + Spec + Spec.ExampleSpec + Test.Hspec.Formatters.Codewars + + build-tool-depends: hspec-discover:hspec-discover >=2 && <3 diff --git a/src/Test/Hspec/Formatters/Codewars.hs b/src/Test/Hspec/Formatters/Codewars.hs index 7da641b..6e42a75 100644 --- a/src/Test/Hspec/Formatters/Codewars.hs +++ b/src/Test/Hspec/Formatters/Codewars.hs @@ -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 $ "" ++ name - -, exampleGroupDone = writeLine "\n" +import Test.Hspec.Core.Formatters.V1 ( + FailureReason (..), + Formatter (..), + formatException, + silent, + writeLine, + ) -, exampleSucceeded = \(_, name) _ -> do - writeLine "" - writeLine $ escapeLF $ "" ++ name - writeLine "\nTest Passed" - writeLine "\n" - -, exampleFailed = \(_, name) _ reason -> do - writeLine "" - writeLine $ escapeLF $ "" ++ name - writeLine "" - writeLine $ escapeLF $ reasonAsString reason - writeLine "\n" -} +codewars :: Formatter +codewars = + silent + { exampleGroupStarted = \_ name -> do + writeLine "" + writeLine $ escapeLF $ "" ++ name + , exampleGroupDone = writeLine "\n" + , exampleSucceeded = \(_, name) _ -> do + writeLine "" + writeLine $ escapeLF $ "" ++ name + writeLine "\nTest Passed" + writeLine "\n" + , exampleFailed = \(_, name) _ reason -> do + writeLine "" + writeLine $ escapeLF $ "" ++ name + writeLine "" + writeLine $ escapeLF $ reasonAsString reason + writeLine "\n" + } reasonAsString :: FailureReason -> String reasonAsString reason = @@ -44,9 +42,9 @@ reasonAsString reason = ExpectedButGot (Just src) expected got -> "" ++ src ++ " expected " ++ expected ++ " but got " ++ got Error Nothing err -> - "" ++ (formatException err) + "" ++ formatException err Error (Just s) err -> - "" ++ s ++ (formatException err) + "" ++ s ++ formatException err escapeLF :: String -> String escapeLF = unpack . replace "\n" "<:LF:>" . pack diff --git a/test/Main.hs b/test/Main.hs new file mode 100644 index 0000000..e0a0fa9 --- /dev/null +++ b/test/Main.hs @@ -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 diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 0000000..5416ef6 --- /dev/null +++ b/test/Spec.hs @@ -0,0 +1 @@ +{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --module-name=Spec #-} diff --git a/test/Spec/ExampleSpec.hs b/test/Spec/ExampleSpec.hs new file mode 100644 index 0000000..7fc1ea5 --- /dev/null +++ b/test/Spec/ExampleSpec.hs @@ -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) From 27bea771263d9b1c5fe3a21b5abc427fa172d3d0 Mon Sep 17 00:00:00 2001 From: andys8 Date: Thu, 8 Sep 2022 10:51:13 +0200 Subject: [PATCH 2/3] Higher hspec min version (2.8) --- hspec-formatters-codewars.cabal | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/hspec-formatters-codewars.cabal b/hspec-formatters-codewars.cabal index bca4825..bf5f89c 100644 --- a/hspec-formatters-codewars.cabal +++ b/hspec-formatters-codewars.cabal @@ -9,10 +9,10 @@ build-type: Simple library hs-source-dirs: src build-depends: - , base >=4 && <5 - , hspec >=2 && <3 - , hspec-core >=2 && <3 - , text >=2 && <3 + , base >=4 && <5 + , hspec >=2.8 && <3 + , hspec-core >=2.8 && <3 + , text >=2 && <3 exposed-modules: Test.Hspec.Formatters.Codewars default-language: GHC2021 @@ -23,10 +23,10 @@ test-suite hspec-formatters-codewars-spec main-is: Main.hs hs-source-dirs: test src build-depends: - , base >=4 && <5 - , hspec >=2 && <3 - , hspec-core >=2 && <3 - , text >=2 && <3 + , base >=4 && <5 + , hspec >=2.8 && <3 + , hspec-core >=2.8 && <3 + , text >=2 && <3 other-modules: Spec From 6941b69ec50499cca8172499fddc5a4656c906f6 Mon Sep 17 00:00:00 2001 From: kazk Date: Thu, 8 Sep 2022 11:15:31 -0700 Subject: [PATCH 3/3] Fix homepage url --- hspec-formatters-codewars.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hspec-formatters-codewars.cabal b/hspec-formatters-codewars.cabal index bf5f89c..c822e03 100644 --- a/hspec-formatters-codewars.cabal +++ b/hspec-formatters-codewars.cabal @@ -2,7 +2,7 @@ cabal-version: 2.4 name: hspec-formatters-codewars version: 0.1.0 synopsis: Hspec formatter for Codewars -homepage: https://githuc.com/codewars/hspec-formatters-codewars +homepage: https://github.com/codewars/hspec-formatters-codewars license: MIT build-type: Simple