Re: [Snowdrift-dev] [PATCH] Port Snowdrift tests from HSpec to Tasty

2017-07-08 Thread Aaron Wolf
On 07/08/2017 01:41 AM, fr33domlo...@riseup.net wrote:
> From: fr33domlover 
> 
> ---
>  website/Snowdrift.cabal   | 12 +++-
>  website/test/AlertsSpec.hs|  6 +++---
>  website/test/AuthSiteSpec.hs  |  8 
>  website/test/DiscourseSpec.hs | 35 ---
>  website/test/HandlerSpec.hs   |  6 +++---
>  website/test/SampleSpec.hs|  6 +++---
>  website/test/Spec.hs  |  1 -
>  website/test/StripeMock.hs|  2 +-
>  website/test/Tasty.hs |  1 +
>  website/test/TestImport.hs|  4 ++--
>  10 files changed, 40 insertions(+), 41 deletions(-)
>  delete mode 100644 website/test/Spec.hs
>  create mode 100644 website/test/Tasty.hs
> 
> diff --git a/website/Snowdrift.cabal b/website/Snowdrift.cabal
> index 1f1ffc5..c7be912 100644
> --- a/website/Snowdrift.cabal
> +++ b/website/Snowdrift.cabal
> @@ -152,7 +152,7 @@ executable Snowdrift
>  -- test-suite test {{{1
>  test-suite test
>  type:   exitcode-stdio-1.0
> -main-is:Spec.hs
> +main-is:Tasty.hs
>  hs-source-dirs: test
>  ghc-options:-Wall
>  
> @@ -178,24 +178,26 @@ test-suite test
>  -- build-depends {{{2
>  build-depends:
>  Snowdrift
> --- For htmlHasLink (should move upstream)
> -, HUnit >= 1.3.1.1
>  , base
>  , bytestring
>  , classy-prelude
>  , classy-prelude-yesod
>  , cryptonite
> -, hspec >= 2.0.0
>  , http-types
>  , memory
>  , persistent
>  , persistent-postgresql
>  , postgresql-simple
> -, QuickCheck
>  , quickcheck-text
>  , shakespeare
>  , stripe-core
>  , stripe-haskell
> +, tasty
> +, tasty-discover
> +-- For htmlHasLink (should move upstream)
> +, tasty-hunit
> +, tasty-hspec
> +, tasty-quickcheck
>  , text >= 1.2.2.1
>  , wai-extra
>  , yesod
> diff --git a/website/test/AlertsSpec.hs b/website/test/AlertsSpec.hs
> index 62235e8..cf0d9c5 100644
> --- a/website/test/AlertsSpec.hs
> +++ b/website/test/AlertsSpec.hs
> @@ -1,4 +1,4 @@
> -module AlertsSpec (spec) where
> +module AlertsSpec (spec_alerts) where
>  
>  import TestImport
>  import Alerts
> @@ -20,8 +20,8 @@ alertSite = LiteApp go
>  withAlertSite :: SpecWith (TestApp LiteApp) -> Spec
>  withAlertSite = before $ pure (alertSite, id)
>  
> -spec :: Spec
> -spec = withAlertSite $
> +spec_alerts :: Spec
> +spec_alerts = withAlertSite $
>  it "adds an alert" $ do
>  get getR
>  htmlCount ".alert" 0
> diff --git a/website/test/AuthSiteSpec.hs b/website/test/AuthSiteSpec.hs
> index e962fce..a251a9e 100644
> --- a/website/test/AuthSiteSpec.hs
> +++ b/website/test/AuthSiteSpec.hs
> @@ -4,13 +4,13 @@
>  {-# LANGUAGE ScopedTypeVariables #-}
>  {-# LANGUAGE ViewPatterns #-}
>  {-# OPTIONS_GHC -fno-warn-unused-binds #-}
> -module AuthSiteSpec (spec) where
> +module AuthSiteSpec (spec_authSite) where
>  
>  import TestImport hiding (Handler)
>  import Database.Persist.Sql hiding (get)
>  import Database.Persist.Postgresql (pgConnStr)
>  import Network.Wai.Test (SResponse(..))
> -import Test.HUnit (assertBool)
> +import Test.Tasty.HUnit (assertBool)
>  import Yesod hiding (get)
>  import Yesod.Default.Config2 (ignoreEnv, loadYamlSettings)
>  import qualified Data.Text as T
> @@ -171,8 +171,8 @@ withBob = beforeWith makeBob
>  
>  -- ** The actual tests!
>  
> -spec :: Spec
> -spec = mainSpecs >> authRouteSpec
> +spec_authSite :: Spec
> +spec_authSite = mainSpecs >> authRouteSpec
>  
>  -- | Having this defined separately is clumsy. It should be moved back into
>  -- the right spot. The problem is that it needs a different value of
> diff --git a/website/test/DiscourseSpec.hs b/website/test/DiscourseSpec.hs
> index f00c084..e4cc0b0 100644
> --- a/website/test/DiscourseSpec.hs
> +++ b/website/test/DiscourseSpec.hs
> @@ -13,30 +13,27 @@ import Crypto.MAC.HMAC (HMAC, hmac)
>  import Data.ByteArray (ByteArray, ByteArrayAccess)
>  import Data.ByteArray.Encoding (Base(Base16, Base64URLUnpadded), 
> convertToBase)
>  import Data.Text.Arbitrary ()
> -import Test.Hspec.QuickCheck (prop)
> -import Test.QuickCheck (Arbitrary, arbitrary, choose, oneof, vectorOf, 
> NonEmptyList(..))
> +import Test.Tasty.QuickCheck (Arbitrary, arbitrary, choose, oneof, vectorOf, 
> NonEmptyList(..))
>  
>  import qualified Data.ByteString.Char8 as Char8
>  
>  {-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}
>  
> -spec :: Spec
> -spec = do
> -prop "validateSig" $ \(NonEmpty secret) (NonEmpty payload) -> do
> -let secret' = pack secret
> -payload' = pack payload
> -
> -validateSig (DiscourseSecret secret') payload'
> -(base16 (hmac secret' payload' :: HMAC SHA256))
> -
> -prop "parsePayload" $ \(Nonce nonce) (Url url) -> do
> -let payload = "nonce=" <> nonce <> 

[Snowdrift-dev] [PATCH] Port Snowdrift tests from HSpec to Tasty

2017-07-08 Thread fr33domlover
From: fr33domlover 

---
 website/Snowdrift.cabal   | 12 +++-
 website/test/AlertsSpec.hs|  6 +++---
 website/test/AuthSiteSpec.hs  |  8 
 website/test/DiscourseSpec.hs | 35 ---
 website/test/HandlerSpec.hs   |  6 +++---
 website/test/SampleSpec.hs|  6 +++---
 website/test/Spec.hs  |  1 -
 website/test/StripeMock.hs|  2 +-
 website/test/Tasty.hs |  1 +
 website/test/TestImport.hs|  4 ++--
 10 files changed, 40 insertions(+), 41 deletions(-)
 delete mode 100644 website/test/Spec.hs
 create mode 100644 website/test/Tasty.hs

diff --git a/website/Snowdrift.cabal b/website/Snowdrift.cabal
index 1f1ffc5..c7be912 100644
--- a/website/Snowdrift.cabal
+++ b/website/Snowdrift.cabal
@@ -152,7 +152,7 @@ executable Snowdrift
 -- test-suite test {{{1
 test-suite test
 type:   exitcode-stdio-1.0
-main-is:Spec.hs
+main-is:Tasty.hs
 hs-source-dirs: test
 ghc-options:-Wall
 
@@ -178,24 +178,26 @@ test-suite test
 -- build-depends {{{2
 build-depends:
 Snowdrift
--- For htmlHasLink (should move upstream)
-, HUnit >= 1.3.1.1
 , base
 , bytestring
 , classy-prelude
 , classy-prelude-yesod
 , cryptonite
-, hspec >= 2.0.0
 , http-types
 , memory
 , persistent
 , persistent-postgresql
 , postgresql-simple
-, QuickCheck
 , quickcheck-text
 , shakespeare
 , stripe-core
 , stripe-haskell
+, tasty
+, tasty-discover
+-- For htmlHasLink (should move upstream)
+, tasty-hunit
+, tasty-hspec
+, tasty-quickcheck
 , text >= 1.2.2.1
 , wai-extra
 , yesod
diff --git a/website/test/AlertsSpec.hs b/website/test/AlertsSpec.hs
index 62235e8..cf0d9c5 100644
--- a/website/test/AlertsSpec.hs
+++ b/website/test/AlertsSpec.hs
@@ -1,4 +1,4 @@
-module AlertsSpec (spec) where
+module AlertsSpec (spec_alerts) where
 
 import TestImport
 import Alerts
@@ -20,8 +20,8 @@ alertSite = LiteApp go
 withAlertSite :: SpecWith (TestApp LiteApp) -> Spec
 withAlertSite = before $ pure (alertSite, id)
 
-spec :: Spec
-spec = withAlertSite $
+spec_alerts :: Spec
+spec_alerts = withAlertSite $
 it "adds an alert" $ do
 get getR
 htmlCount ".alert" 0
diff --git a/website/test/AuthSiteSpec.hs b/website/test/AuthSiteSpec.hs
index e962fce..a251a9e 100644
--- a/website/test/AuthSiteSpec.hs
+++ b/website/test/AuthSiteSpec.hs
@@ -4,13 +4,13 @@
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE ViewPatterns #-}
 {-# OPTIONS_GHC -fno-warn-unused-binds #-}
-module AuthSiteSpec (spec) where
+module AuthSiteSpec (spec_authSite) where
 
 import TestImport hiding (Handler)
 import Database.Persist.Sql hiding (get)
 import Database.Persist.Postgresql (pgConnStr)
 import Network.Wai.Test (SResponse(..))
-import Test.HUnit (assertBool)
+import Test.Tasty.HUnit (assertBool)
 import Yesod hiding (get)
 import Yesod.Default.Config2 (ignoreEnv, loadYamlSettings)
 import qualified Data.Text as T
@@ -171,8 +171,8 @@ withBob = beforeWith makeBob
 
 -- ** The actual tests!
 
-spec :: Spec
-spec = mainSpecs >> authRouteSpec
+spec_authSite :: Spec
+spec_authSite = mainSpecs >> authRouteSpec
 
 -- | Having this defined separately is clumsy. It should be moved back into
 -- the right spot. The problem is that it needs a different value of
diff --git a/website/test/DiscourseSpec.hs b/website/test/DiscourseSpec.hs
index f00c084..e4cc0b0 100644
--- a/website/test/DiscourseSpec.hs
+++ b/website/test/DiscourseSpec.hs
@@ -13,30 +13,27 @@ import Crypto.MAC.HMAC (HMAC, hmac)
 import Data.ByteArray (ByteArray, ByteArrayAccess)
 import Data.ByteArray.Encoding (Base(Base16, Base64URLUnpadded), convertToBase)
 import Data.Text.Arbitrary ()
-import Test.Hspec.QuickCheck (prop)
-import Test.QuickCheck (Arbitrary, arbitrary, choose, oneof, vectorOf, 
NonEmptyList(..))
+import Test.Tasty.QuickCheck (Arbitrary, arbitrary, choose, oneof, vectorOf, 
NonEmptyList(..))
 
 import qualified Data.ByteString.Char8 as Char8
 
 {-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}
 
-spec :: Spec
-spec = do
-prop "validateSig" $ \(NonEmpty secret) (NonEmpty payload) -> do
-let secret' = pack secret
-payload' = pack payload
-
-validateSig (DiscourseSecret secret') payload'
-(base16 (hmac secret' payload' :: HMAC SHA256))
-
-prop "parsePayload" $ \(Nonce nonce) (Url url) -> do
-let payload = "nonce=" <> nonce <> "_sso_url=" <> encodeUtf8 url
-parsePayload (base64 payload)
-`shouldBe`
-Right DiscoursePayload
-{ dpNonce = nonce
-, dpUrl   = url
-}
+prop_validateSig (NonEmpty secret) (NonEmpty payload) = do
+let secret' = pack secret
+payload' = pack 

[Snowdrift-dev] [PATCH] Port Snowdrift tests from HSpec to Tasty

2017-07-01 Thread fr33domlover
From: fr33domlover 

---
 website/Snowdrift.cabal   | 11 ++-
 website/test/AlertsSpec.hs|  6 +++---
 website/test/AuthSiteSpec.hs  |  8 
 website/test/DiscourseSpec.hs | 35 ---
 website/test/HandlerSpec.hs   |  6 +++---
 website/test/SampleSpec.hs|  6 +++---
 website/test/Spec.hs  |  1 -
 website/test/StripeMock.hs|  2 +-
 website/test/Tasty.hs |  1 +
 website/test/TestImport.hs|  4 ++--
 10 files changed, 39 insertions(+), 41 deletions(-)
 delete mode 100644 website/test/Spec.hs
 create mode 100644 website/test/Tasty.hs

diff --git a/website/Snowdrift.cabal b/website/Snowdrift.cabal
index 1f1ffc5..6504edf 100644
--- a/website/Snowdrift.cabal
+++ b/website/Snowdrift.cabal
@@ -152,7 +152,7 @@ executable Snowdrift
 -- test-suite test {{{1
 test-suite test
 type:   exitcode-stdio-1.0
-main-is:Spec.hs
+main-is:Tasty.hs
 hs-source-dirs: test
 ghc-options:-Wall
 
@@ -178,24 +178,25 @@ test-suite test
 -- build-depends {{{2
 build-depends:
 Snowdrift
--- For htmlHasLink (should move upstream)
-, HUnit >= 1.3.1.1
 , base
 , bytestring
 , classy-prelude
 , classy-prelude-yesod
 , cryptonite
-, hspec >= 2.0.0
 , http-types
 , memory
 , persistent
 , persistent-postgresql
 , postgresql-simple
-, QuickCheck
 , quickcheck-text
 , shakespeare
 , stripe-core
 , stripe-haskell
+, tasty
+-- For htmlHasLink (should move upstream)
+, tasty-hunit
+, tasty-hspec
+, tasty-quickcheck
 , text >= 1.2.2.1
 , wai-extra
 , yesod
diff --git a/website/test/AlertsSpec.hs b/website/test/AlertsSpec.hs
index 62235e8..cf0d9c5 100644
--- a/website/test/AlertsSpec.hs
+++ b/website/test/AlertsSpec.hs
@@ -1,4 +1,4 @@
-module AlertsSpec (spec) where
+module AlertsSpec (spec_alerts) where
 
 import TestImport
 import Alerts
@@ -20,8 +20,8 @@ alertSite = LiteApp go
 withAlertSite :: SpecWith (TestApp LiteApp) -> Spec
 withAlertSite = before $ pure (alertSite, id)
 
-spec :: Spec
-spec = withAlertSite $
+spec_alerts :: Spec
+spec_alerts = withAlertSite $
 it "adds an alert" $ do
 get getR
 htmlCount ".alert" 0
diff --git a/website/test/AuthSiteSpec.hs b/website/test/AuthSiteSpec.hs
index e962fce..a251a9e 100644
--- a/website/test/AuthSiteSpec.hs
+++ b/website/test/AuthSiteSpec.hs
@@ -4,13 +4,13 @@
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE ViewPatterns #-}
 {-# OPTIONS_GHC -fno-warn-unused-binds #-}
-module AuthSiteSpec (spec) where
+module AuthSiteSpec (spec_authSite) where
 
 import TestImport hiding (Handler)
 import Database.Persist.Sql hiding (get)
 import Database.Persist.Postgresql (pgConnStr)
 import Network.Wai.Test (SResponse(..))
-import Test.HUnit (assertBool)
+import Test.Tasty.HUnit (assertBool)
 import Yesod hiding (get)
 import Yesod.Default.Config2 (ignoreEnv, loadYamlSettings)
 import qualified Data.Text as T
@@ -171,8 +171,8 @@ withBob = beforeWith makeBob
 
 -- ** The actual tests!
 
-spec :: Spec
-spec = mainSpecs >> authRouteSpec
+spec_authSite :: Spec
+spec_authSite = mainSpecs >> authRouteSpec
 
 -- | Having this defined separately is clumsy. It should be moved back into
 -- the right spot. The problem is that it needs a different value of
diff --git a/website/test/DiscourseSpec.hs b/website/test/DiscourseSpec.hs
index f00c084..e4cc0b0 100644
--- a/website/test/DiscourseSpec.hs
+++ b/website/test/DiscourseSpec.hs
@@ -13,30 +13,27 @@ import Crypto.MAC.HMAC (HMAC, hmac)
 import Data.ByteArray (ByteArray, ByteArrayAccess)
 import Data.ByteArray.Encoding (Base(Base16, Base64URLUnpadded), convertToBase)
 import Data.Text.Arbitrary ()
-import Test.Hspec.QuickCheck (prop)
-import Test.QuickCheck (Arbitrary, arbitrary, choose, oneof, vectorOf, 
NonEmptyList(..))
+import Test.Tasty.QuickCheck (Arbitrary, arbitrary, choose, oneof, vectorOf, 
NonEmptyList(..))
 
 import qualified Data.ByteString.Char8 as Char8
 
 {-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}
 
-spec :: Spec
-spec = do
-prop "validateSig" $ \(NonEmpty secret) (NonEmpty payload) -> do
-let secret' = pack secret
-payload' = pack payload
-
-validateSig (DiscourseSecret secret') payload'
-(base16 (hmac secret' payload' :: HMAC SHA256))
-
-prop "parsePayload" $ \(Nonce nonce) (Url url) -> do
-let payload = "nonce=" <> nonce <> "_sso_url=" <> encodeUtf8 url
-parsePayload (base64 payload)
-`shouldBe`
-Right DiscoursePayload
-{ dpNonce = nonce
-, dpUrl   = url
-}
+prop_validateSig (NonEmpty secret) (NonEmpty payload) = do
+let secret' = pack secret
+payload' = pack payload
+
+validateSig