00e02a3f9d
Made the error management for loading the JSON config file work as one might expect it should. Expanded the error reporting expectations to include specific file reading and JSON decoding errors. The difficulties that will be had in handling the multiple either values will motivate latter sections RE ExceptT (EitherT) transformers. However there is nothing here that should be beyond people that do not know how transformers work. Added more doctests to the different moving parts to make things a bit clearer. Added doctests to the cabal files and included a 'doctests.hs' to the tests section. default.nix files have been updated with the bonus dependency. |
||
---|---|---|
.. | ||
bin | ||
src/FirstApp | ||
tests | ||
appconfig.json | ||
changelog.md | ||
default.nix | ||
level04.cabal | ||
LICENSE | ||
README.md | ||
Setup.hs | ||
shell.nix | ||
test.json |
Level 04
In this exercise we're going to add some tests to our application. Because types are awesome, and tests are pretty good. But types AND tests is pretty much perfect.
These tests will not be awe inspiring, this exercise is primarily to introduce you to adding tests to your Haskell application. The setup of the Cabal file is already completed for you, but will be covered.
As is to be expected, there are multiple testing frameworks and packages available but we will only cover one here. We will use the HSpec framework, with the hspec-wai package to make our lives a bit easier.
Start in tests/Test.hs
.
Aside: Tool Introduction - ghcid
Additionally we'd like to introduce a command line tool that you may find useful for Haskell development; ghcid. This is a very lightweight tool that works for any project with a functioning cabal setup.
If you would like to use it, consult its documentation for how to install it,
and then in an spare open terminal window, navigate to the root of the Haskell
project and run $ ghcid
.
It will then attempt to build your project, if errors are found they will be
displayed. But more importantly you can go back to editing files in the project
and ghcid
will refresh in the background. Providing you with new error
messages or All Good
if it cannot find any errors.
ghcid
provides extremely fast feedback, allowing for a nice development
process with constant feedback about your changes. It is very useful in tandem
with type holes. Give it a try!