Remove tests; just document how to add it (#50)
This commit is contained in:
parent
5cfb230f15
commit
9080aef7fb
7 changed files with 43 additions and 30 deletions
42
README.md
42
README.md
|
@ -53,6 +53,48 @@ git add . && git commit -m rename
|
|||
- Run `bin/test` to run the test suite.
|
||||
- Run the application without installing: `nix run github:srid/haskell-template` (or `nix run .` from checkout)
|
||||
|
||||
## Common workflows
|
||||
|
||||
### Adding tests
|
||||
|
||||
1. Split any logic code out of `Main.hs` into, say, a `Lib.hs`.
|
||||
1. Correspondingly, add `other-modules: Lib` to the "shared" section of your cabal file.
|
||||
1. Add `tests/Spec.hs` (example below):
|
||||
```haskell
|
||||
module Main where
|
||||
|
||||
import Lib qualified
|
||||
import Test.Hspec (describe, hspec, it, shouldContain)
|
||||
|
||||
main :: IO ()
|
||||
main = hspec $ do
|
||||
describe "Lib.hello" $ do
|
||||
it "contains the world emoji" $ do
|
||||
toString Lib.hello `shouldContain` "🌎"
|
||||
```
|
||||
1. Add the tests stanza to the cabal file:
|
||||
```cabal
|
||||
test-suite tests
|
||||
import: shared
|
||||
main-is: Spec.hs
|
||||
type: exitcode-stdio-1.0
|
||||
hs-source-dirs: tests
|
||||
build-depends: hspec
|
||||
```
|
||||
1. Update `hie.yaml` accordingly; for example, by adding,
|
||||
```yaml
|
||||
- path: "tests"
|
||||
component: "test:tests"
|
||||
```
|
||||
1. Add `bin/test` and `chmod a+x` it:
|
||||
```sh
|
||||
#!/usr/bin/env bash
|
||||
set -xe
|
||||
|
||||
exec nix develop -i -c ghcid -c "cabal repl test:tests" -T :main
|
||||
```
|
||||
1. Commit your changes to Git, and test it out by running `bin/test`.
|
||||
|
||||
## Discussions
|
||||
|
||||
Got questions? Ideas? Suggestions? Post them here: https://github.com/srid/haskell-template/discussions
|
||||
|
|
4
bin/test
4
bin/test
|
@ -1,4 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
set -xe
|
||||
|
||||
exec nix develop -i -c ghcid -c "cabal repl test:tests" -T :main
|
|
@ -92,16 +92,8 @@ common shared
|
|||
, with-utf8
|
||||
|
||||
hs-source-dirs: src
|
||||
other-modules: Lib
|
||||
default-language: Haskell2010
|
||||
|
||||
executable haskell-template
|
||||
import: shared
|
||||
main-is: Main.hs
|
||||
|
||||
test-suite tests
|
||||
import: shared
|
||||
main-is: Spec.hs
|
||||
type: exitcode-stdio-1.0
|
||||
hs-source-dirs: tests
|
||||
build-depends: hspec
|
||||
|
|
2
hie.yaml
2
hie.yaml
|
@ -2,5 +2,3 @@ cradle:
|
|||
cabal:
|
||||
- path: "src"
|
||||
component: "exe:haskell-template"
|
||||
- path: "tests"
|
||||
component: "test:tests"
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
module Lib (hello) where
|
||||
|
||||
hello :: Text
|
||||
hello = "Hello 🌎"
|
|
@ -1,6 +1,5 @@
|
|||
module Main where
|
||||
|
||||
import Lib qualified
|
||||
import Main.Utf8 qualified as Utf8
|
||||
|
||||
{- |
|
||||
|
@ -12,4 +11,4 @@ main :: IO ()
|
|||
main = do
|
||||
-- For withUtf8, see https://serokell.io/blog/haskell-with-utf8
|
||||
Utf8.withUtf8 $ do
|
||||
putTextLn Lib.hello
|
||||
putTextLn "Hello 🌎"
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
module Main where
|
||||
|
||||
import Lib qualified
|
||||
import Test.Hspec (describe, hspec, it, shouldContain)
|
||||
|
||||
main :: IO ()
|
||||
main = hspec $ do
|
||||
describe "Lib.hello" $ do
|
||||
it "contains the world emoji" $ do
|
||||
toString Lib.hello `shouldContain` "🌎"
|
Loading…
Reference in a new issue