1
1
mirror of https://github.com/qfpl/applied-fp-course.git synced 2024-11-26 06:38:40 +03:00
applied-fp-course/level03
Sean Chalmers 959eb576aa Issue Fixes & More feedback driven development
Fixes: #15, #13, #14, #11, #8

Add the IDEAS to a 'Suggestions' section in the FUTURE_PLANS file.

* Updated the cabal instructions for level 03
* Removed the duplicated config loading in level 05
* Add the implementations for File.hs for levels 06 & 07
* Renamed the slightly misleading 'readObject' function
* Fixed the capitalisation of init and close DB functions between levels
  04 & 05.
2018-01-22 11:40:11 +10:00
..
bin Updates based on course run feedback. 2018-01-16 12:36:57 +10:00
src/FirstApp Updates based on course run feedback. 2018-01-16 12:36:57 +10:00
tests Remove obsolete test comment 2018-01-17 13:49:47 +11:00
changelog.md change changelog files to lowercase 2017-09-01 11:17:26 +10:00
default.nix Overhauled nix file setup to be more like the other QFPL projects. 2017-09-18 10:14:29 +10:00
level03.cabal Updates based on course run feedback. 2018-01-16 12:36:57 +10:00
level03.nix Updates based on course run feedback. 2018-01-16 12:36:57 +10:00
LICENCE update copyright notice 2017-09-12 11:51:26 +10:00
README.md Issue Fixes & More feedback driven development 2018-01-22 11:40:11 +10:00
Setup.hs Added third stage exercise 2017-08-09 15:59:16 +10:00
stack.yaml Add stack.yaml files for all directories. 2018-01-10 10:33:56 +10:00
test.json Updates based on course run feedback. 2018-01-16 12:36:57 +10:00

Level 03

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.

NB: Including Test Library Dependencies

For a cabal sandbox:

$ cabal sandbox init
$ cabal install --only-dependencies --enable-tests
$ cabal configure --enable-tests

For a stack environment:

$ stack build --test

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!

ghcid can also help out when you're writing your tests. Since normally the source and other packages that are listed in a test-suite configuration section in the Cabal file are not loaded. You can manually tell ghcid to load and examine these files with the following command:

$ ghcid -c "cabal repl level03"

# Or for using ghcid to check your tests
$ ghcid -c "cabal repl level03-tests"

# A note for sandboxed ghcid, you may need to provide an
# explicit path to the binary:
$ .cabal-sandbox/bin/ghcid -c "cabal repl level03-tests"

It should work with stack as well:

$ ghcid -c "stack repl level03-tests"

Please read the ghciddocumentation for installation and usage instructions. The FAQ provides some useful tips.