diff --git a/hie.yaml b/hie.yaml index 8733a0ca2..59a9fcd18 100644 --- a/hie.yaml +++ b/hie.yaml @@ -41,3 +41,5 @@ cradle: component: "hledger-web:lib" - path: "hledger-web/app/" component: "hledger-web:exe:hledger-web" + - path: "hledger-web/test/" + component: "hledger-web:test:test" diff --git a/hledger-web/hledger-web.cabal b/hledger-web/hledger-web.cabal index 43a254345..6a8562638 100644 --- a/hledger-web/hledger-web.cabal +++ b/hledger-web/hledger-web.cabal @@ -4,7 +4,7 @@ cabal-version: 1.12 -- -- see: https://github.com/sol/hpack -- --- hash: 1d9dc492e44eb37e5c5db8a8d8d21ca089c3035b4f4fa72d95696d51613400be +-- hash: 929ce1d9b5d6a14f13fa77dd3a21d8772a58c1e13310e4940510878718fa4d96 name: hledger-web version: 1.19.99 @@ -222,3 +222,22 @@ executable hledger-web if flag(threaded) ghc-options: -threaded default-language: Haskell2010 + +test-suite test + type: exitcode-stdio-1.0 + main-is: test.hs + hs-source-dirs: + test + ghc-options: -Wall -fwarn-tabs -Wcompat -Wincomplete-uni-patterns -Wincomplete-record-updates -Wredundant-constraints + cpp-options: -DVERSION="1.19.99" + build-depends: + base + , hledger-web + , hspec + , yesod + , yesod-test + if (flag(dev)) || (flag(library-only)) + cpp-options: -DDEVELOPMENT + if flag(dev) + ghc-options: -O0 + default-language: Haskell2010 diff --git a/hledger-web/package.yaml b/hledger-web/package.yaml index c386a7279..d79bc28e9 100644 --- a/hledger-web/package.yaml +++ b/hledger-web/package.yaml @@ -158,15 +158,15 @@ executables: - condition: flag(threaded) ghc-options: -threaded -# 2018/06 not building and not testing anything useful, disabled for now -# tests: -# test: -# source-dirs: test -# main: test.hs -# other-modules: [] # prevent double compilation, https://github.com/sol/hpack/issues/188 -# cpp-options: -DVERSION="1.19.99" -# dependencies: -# - base -# - hledger-web -# - hspec -# - yesod-test +tests: + test: + source-dirs: test + main: test.hs + other-modules: [] # prevent double compilation, https://github.com/sol/hpack/issues/188 + cpp-options: -DVERSION="1.19.99" + dependencies: + - base + - hledger-web + - hspec + - yesod + - yesod-test diff --git a/hledger-web/test/HomeTest.hs b/hledger-web/test/HomeTest.hs deleted file mode 100644 index ad762a345..000000000 --- a/hledger-web/test/HomeTest.hs +++ /dev/null @@ -1,25 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -module HomeTest - ( homeSpecs - ) where - -import TestImport - -homeSpecs :: Specs -homeSpecs = - ydescribe "Some hledger-web tests" $ - - yit "serves a reasonable-looking register page" $ do - get RegisterR - statusIs 200 - bodyContains "accounts" - - -- post "/" $ do - -- addNonce - -- fileByLabel "Choose a file" "tests/main.hs" "text/plain" -- talk about self-reference - -- byLabel "What's on the file?" "Some Content" - - -- statusIs 200 - -- htmlCount ".message" 1 - -- htmlAllContain ".message" "Some Content" - -- htmlAllContain ".message" "text/plain" diff --git a/hledger-web/test/TestImport.hs b/hledger-web/test/TestImport.hs deleted file mode 100644 index 19d1f3edc..000000000 --- a/hledger-web/test/TestImport.hs +++ /dev/null @@ -1,12 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -module TestImport - ( module Yesod.Test - , module Foundation - , Specs - ) where - -import Yesod.Test - -import Foundation - -type Specs = YesodSpec App diff --git a/hledger-web/test/test.hs b/hledger-web/test/test.hs index e1b237e09..982910488 100644 --- a/hledger-web/test/test.hs +++ b/hledger-web/test/test.hs @@ -7,21 +7,44 @@ module Main where -- cabal missing-home-modules workaround from hledger-lib needed here ? -- {-# LANGUAGE PackageImports #-} -import Import +import Test.Hspec (hspec) import Yesod.Default.Config import Yesod.Test -import Test.Hspec (hspec) -import Application (makeFoundation) +import Hledger.Web.Application (makeFoundation) +import Hledger.Web.Foundation +import Hledger.Web.Settings (parseExtra) import Hledger.Web.WebOptions (defwebopts) -import HomeTest - main :: IO () main = do - conf <- Yesod.Default.Config.loadConfig $ (configSettings Testing) - { csParseExtra = parseExtra - } - foundation <- makeFoundation conf defwebopts - hspec $ do - yesodSpec foundation $ do - homeSpecs + conf <- Yesod.Default.Config.loadConfig $ + (configSettings Testing){ csParseExtra = parseExtra } + foundation <- makeFoundation conf defwebopts + hspec $ yesodSpec foundation specs + +-- https://hackage.haskell.org/package/yesod-test/docs/Yesod-Test.html + +specs :: YesodSpec App +specs = do + ydescribe "hledger-web basic functionality" $ do + + yit "serves a reasonable-looking journal page" $ do + get JournalR + statusIs 200 + bodyContains "Add a transaction" + + yit "serves a reasonable-looking register page" $ do + get RegisterR + statusIs 200 + bodyContains "accounts" + + -- post "/" $ do + -- addNonce + -- fileByLabel "Choose a file" "tests/main.hs" "text/plain" -- talk about self-reference + -- byLabel "What's on the file?" "Some Content" + + -- statusIs 200 + -- htmlCount ".message" 1 + -- htmlAllContain ".message" "Some Content" + -- htmlAllContain ".message" "text/plain" +