Remove tests; just document how to add it (#50)

This commit is contained in:
Sridhar Ratnakumar 2022-09-01 20:04:57 -04:00 committed by GitHub
parent 5cfb230f15
commit 9080aef7fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 30 deletions

View file

@ -53,6 +53,48 @@ git add . && git commit -m rename
- Run `bin/test` to run the test suite. - Run `bin/test` to run the test suite.
- Run the application without installing: `nix run github:srid/haskell-template` (or `nix run .` from checkout) - 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 ## Discussions
Got questions? Ideas? Suggestions? Post them here: https://github.com/srid/haskell-template/discussions Got questions? Ideas? Suggestions? Post them here: https://github.com/srid/haskell-template/discussions

View file

@ -1,4 +0,0 @@
#!/usr/bin/env bash
set -xe
exec nix develop -i -c ghcid -c "cabal repl test:tests" -T :main

View file

@ -92,16 +92,8 @@ common shared
, with-utf8 , with-utf8
hs-source-dirs: src hs-source-dirs: src
other-modules: Lib
default-language: Haskell2010 default-language: Haskell2010
executable haskell-template executable haskell-template
import: shared import: shared
main-is: Main.hs 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

View file

@ -2,5 +2,3 @@ cradle:
cabal: cabal:
- path: "src" - path: "src"
component: "exe:haskell-template" component: "exe:haskell-template"
- path: "tests"
component: "test:tests"

View file

@ -1,4 +0,0 @@
module Lib (hello) where
hello :: Text
hello = "Hello 🌎"

View file

@ -1,6 +1,5 @@
module Main where module Main where
import Lib qualified
import Main.Utf8 qualified as Utf8 import Main.Utf8 qualified as Utf8
{- | {- |
@ -12,4 +11,4 @@ main :: IO ()
main = do main = do
-- For withUtf8, see https://serokell.io/blog/haskell-with-utf8 -- For withUtf8, see https://serokell.io/blog/haskell-with-utf8
Utf8.withUtf8 $ do Utf8.withUtf8 $ do
putTextLn Lib.hello putTextLn "Hello 🌎"

View file

@ -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` "🌎"