Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- run:
name: Installing dependencies
command: stack build --only-dependencies
command: stack build --only-dependencies -j1 --fast

- save_cache:
key: v1-stack-{{ checksum "stack.yaml" }}
Expand Down
2 changes: 0 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ tutorialsCompiler = pandocCompilerWith defaultTutorialsReaderOptions defaultHaky

defaultTutorialsReaderOptions :: ReaderOptions
defaultTutorialsReaderOptions = defaultHakyllReaderOptions
{ readerSmart = False
}

compressJsCompiler :: Compiler (Item String)
compressJsCompiler = do
Expand Down
25 changes: 24 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
resolver: lts-9.21
resolver: lts-18.4
extra-deps:
- pandoc-2.11.4
- hakyll-4.14.0.0
- commonmark-extensions-0.2.0.4
- commonmark-pandoc-0.2.0.1
- hslua-module-text-0.3.0.1
- QuickCheck-2.14
- hslua-1.2.0@sha256:6992fa588bd73866dba332593a35c17be325fd359f787ecb669589815a4095c8,11023
- citeproc-0.3.0.9@sha256:e3652bf23caf01c976c87d549885b1e9e4a3a86363494cd82669230e0d4da8ba,5590
- commonmark-0.1.1.4@sha256:8717891c53c124ff64187c463619450241a41c0951cda2a43267d40f78992362,3278
- jira-wiki-markup-1.3.5@sha256:ec02fa8ff9750f46026a18f4c805f6a7b97fe2207977227822dd20e99b8e6c49,3819
- pandoc-types-1.22@sha256:15512ce011555ee720820f11cac0598317293406da5812337cbb1550d144e3bd,4071
- skylighting-0.10.5.2@sha256:90645e4d79dd832591e04e7c31b20cbbf125bfc796df0b7d77faee48f2073fb2,10155
- skylighting-core-0.10.5.2@sha256:a5575661cdcea1741eb6ecf4e9f627ddcfa746b8451506f6140ea7f3b639c61a,8048
- rfc5051-0.2@sha256:da5d77731f2ac6fe313a67919419b0833e09cd7f1a81869ed82a54dbf8962bf2,1678
- xml-conduit-1.9.1.1@sha256:7213a64462d669f5ca55534a78a9b19c1d3757a605756e1f5065fa7c611493c1,3010
- cryptonite-0.27@sha256:c3a9c8ce11e654a9d5bee827b089d4b50587272828d0c52a85362a58667a916c,18163
- file-embed-0.0.13.0@sha256:a819e90b91cab919ffef5895ab6e1b2a44eac395a585f489b0c289a4a12d1c54,1396
- haddock-library-1.9.0@sha256:4e533a5d93627eb0d6ad6d06cb0db3ac8424d2ad5c71b13582c892d2c9ae491e,4061
- optparse-applicative-0.15.1.0@sha256:29ff6146aabf54d46c4c8788e8d1eadaea27c94f6d360c690c5f6c93dac4b07e,4810
- doctemplates-0.9@sha256:eb0bf957ba8571746f36f07ceca43d311a0e390a9fdcfde6909f9f9be85b3b28,3125
- random-1.1@sha256:7b67624fd76ddf97c206de0801dc7e888097e9d572974be9b9ea6551d76965df,1777
- splitmix-0.0.5@sha256:4a49661be63f5aea0e132e9ab51be918789bb4dceb4ab9b15b85ba9cbbef5999,5412
164 changes: 159 additions & 5 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,164 @@
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
packages:
- completed:
hackage: pandoc-2.11.4@sha256:72ff2d50048fe7c11ef67bc936f7fdb986282e72edbb5647db1ab63e415c8bc5,40050
pantry-tree:
size: 118526
sha256: 2856fb6c5d6948f3c58f50b3883535f62321db3cceb7b58cd9dd1e6082a0e570
original:
hackage: pandoc-2.11.4
- completed:
hackage: hakyll-4.14.0.0@sha256:28aab547aa94202d486328aa4bbcd02ecbefc4e5d42dfa15e8137b731a4f5d55,9059
pantry-tree:
size: 8272
sha256: b5dff3f9f3c9bc32b154d8f5b30f88fc12f88a32dd7a10ac7f16584af5059b3f
original:
hackage: hakyll-4.14.0.0
- completed:
hackage: commonmark-extensions-0.2.0.4@sha256:6a437bcfa3c757af4262b71336513619990eafb5cfdc33e57a499c93ad225608,3184
pantry-tree:
size: 2928
sha256: ac8993e356edabc65a40d6c6909696c5f2dfe2a5298089da820c29ca75852360
original:
hackage: commonmark-extensions-0.2.0.4
- completed:
hackage: commonmark-pandoc-0.2.0.1@sha256:529c6e2c6cabf61558b66a28123eafc1d90d3324be29819f59f024e430312c1f,1105
pantry-tree:
size: 326
sha256: d9954a15f73c8fe55a5097e1cc0957fa626d340ef36e2beefb8caae66008c3dc
original:
hackage: commonmark-pandoc-0.2.0.1
- completed:
hackage: hslua-module-text-0.3.0.1@sha256:e245d7bf9746101664dcde9c33b1c8cd792d404fddb8d9346ae6abb6b971dd93,1741
pantry-tree:
size: 415
sha256: 70932f637ef2a81024d43270f3b28ce870d7b43c405fb399d51d07f170da76ea
original:
hackage: hslua-module-text-0.3.0.1
- completed:
hackage: QuickCheck-2.14@sha256:3f536a4b86bef7ec39025f04ef8d76c5ac5a78ba0b42e660b25d0a8f9c811045,7004
pantry-tree:
size: 2203
sha256: 7067593c50ff2e5e83c637ac73009f4bd8f43c29ff256e976bbb14674033abe9
original:
hackage: QuickCheck-2.14
- completed:
hackage: hslua-1.2.0@sha256:6992fa588bd73866dba332593a35c17be325fd359f787ecb669589815a4095c8,11023
pantry-tree:
size: 7715
sha256: c91eedb82abaeac285a45b6571de5ab7dd0b70f4a9d406ef1cc6d092bcc6c56d
original:
hackage: hslua-1.2.0@sha256:6992fa588bd73866dba332593a35c17be325fd359f787ecb669589815a4095c8,11023
- completed:
hackage: citeproc-0.3.0.9@sha256:e3652bf23caf01c976c87d549885b1e9e4a3a86363494cd82669230e0d4da8ba,5590
pantry-tree:
size: 79427
sha256: 8bc862a4764bb91909f2ad16b84b61ab257889159371dfc20bd8bf69a83f4ad2
original:
hackage: citeproc-0.3.0.9@sha256:e3652bf23caf01c976c87d549885b1e9e4a3a86363494cd82669230e0d4da8ba,5590
- completed:
hackage: commonmark-0.1.1.4@sha256:8717891c53c124ff64187c463619450241a41c0951cda2a43267d40f78992362,3278
pantry-tree:
size: 1346
sha256: f1ea43f7c14b13c7f0d5edb2b6f2a9e4c766e1860969694aaa3699952652d070
original:
hackage: commonmark-0.1.1.4@sha256:8717891c53c124ff64187c463619450241a41c0951cda2a43267d40f78992362,3278
- completed:
hackage: jira-wiki-markup-1.3.5@sha256:ec02fa8ff9750f46026a18f4c805f6a7b97fe2207977227822dd20e99b8e6c49,3819
pantry-tree:
size: 1180
sha256: 8aa4f1f7397d3ffa05db7a05715ebc56f4ade36f245cd52019c38167666b6ee0
original:
hackage: jira-wiki-markup-1.3.5@sha256:ec02fa8ff9750f46026a18f4c805f6a7b97fe2207977227822dd20e99b8e6c49,3819
- completed:
hackage: pandoc-types-1.22@sha256:15512ce011555ee720820f11cac0598317293406da5812337cbb1550d144e3bd,4071
pantry-tree:
size: 737
sha256: 28e43150f4bb0d4d880cf92ade20fefcd8705ee95cfe4a1d0bb5efd320982a9d
original:
hackage: pandoc-types-1.22@sha256:15512ce011555ee720820f11cac0598317293406da5812337cbb1550d144e3bd,4071
- completed:
hackage: skylighting-0.10.5.2@sha256:90645e4d79dd832591e04e7c31b20cbbf125bfc796df0b7d77faee48f2073fb2,10155
pantry-tree:
size: 10982
sha256: d1c6f232631a849df67f58885460aace4b4f7ef6418ab95e146299aecd68f3db
original:
hackage: skylighting-0.10.5.2@sha256:90645e4d79dd832591e04e7c31b20cbbf125bfc796df0b7d77faee48f2073fb2,10155
- completed:
hackage: skylighting-core-0.10.5.2@sha256:a5575661cdcea1741eb6ecf4e9f627ddcfa746b8451506f6140ea7f3b639c61a,8048
pantry-tree:
size: 13826
sha256: 76d9c2aa6bc30e398cd4000be6e06f9a72241229e57c69d44c3f47be2c67a8ad
original:
hackage: skylighting-core-0.10.5.2@sha256:a5575661cdcea1741eb6ecf4e9f627ddcfa746b8451506f6140ea7f3b639c61a,8048
- completed:
hackage: rfc5051-0.2@sha256:da5d77731f2ac6fe313a67919419b0833e09cd7f1a81869ed82a54dbf8962bf2,1678
pantry-tree:
size: 446
sha256: 191a30a13590a14dc8f606ff945298fee6afbb093a49bc5db71dbaf066f01930
original:
hackage: rfc5051-0.2@sha256:da5d77731f2ac6fe313a67919419b0833e09cd7f1a81869ed82a54dbf8962bf2,1678
- completed:
hackage: xml-conduit-1.9.1.1@sha256:7213a64462d669f5ca55534a78a9b19c1d3757a605756e1f5065fa7c611493c1,3010
pantry-tree:
size: 836
sha256: f1d88705f6f5368a5861251f5b32f59374a2aaa979079fb8a128bd15f830da75
original:
hackage: xml-conduit-1.9.1.1@sha256:7213a64462d669f5ca55534a78a9b19c1d3757a605756e1f5065fa7c611493c1,3010
- completed:
hackage: cryptonite-0.27@sha256:c3a9c8ce11e654a9d5bee827b089d4b50587272828d0c52a85362a58667a916c,18163
pantry-tree:
size: 22989
sha256: 6eeff10404aecc9028ed21e107d92dd58616dc2d1c4413c04a6dc3ce3fc3ca40
original:
hackage: cryptonite-0.27@sha256:c3a9c8ce11e654a9d5bee827b089d4b50587272828d0c52a85362a58667a916c,18163
- completed:
hackage: file-embed-0.0.13.0@sha256:a819e90b91cab919ffef5895ab6e1b2a44eac395a585f489b0c289a4a12d1c54,1396
pantry-tree:
size: 477
sha256: 6c8f71ca993658844b93a2120f2ff1536400e705890a6fbf0f4e9889ff502649
original:
hackage: file-embed-0.0.13.0@sha256:a819e90b91cab919ffef5895ab6e1b2a44eac395a585f489b0c289a4a12d1c54,1396
- completed:
hackage: haddock-library-1.9.0@sha256:4e533a5d93627eb0d6ad6d06cb0db3ac8424d2ad5c71b13582c892d2c9ae491e,4061
pantry-tree:
size: 3645
sha256: 71412858b03ccaf2d535ef7bc109f01ae7b20d89877ced2a6ca2998c239dbd67
original:
hackage: haddock-library-1.9.0@sha256:4e533a5d93627eb0d6ad6d06cb0db3ac8424d2ad5c71b13582c892d2c9ae491e,4061
- completed:
hackage: optparse-applicative-0.15.1.0@sha256:29ff6146aabf54d46c4c8788e8d1eadaea27c94f6d360c690c5f6c93dac4b07e,4810
pantry-tree:
size: 2904
sha256: 04ad3816bc580cbe0834d3d1f4729ddd386abfe31b43e5b14968885f636d1b0d
original:
hackage: optparse-applicative-0.15.1.0@sha256:29ff6146aabf54d46c4c8788e8d1eadaea27c94f6d360c690c5f6c93dac4b07e,4810
- completed:
hackage: doctemplates-0.9@sha256:eb0bf957ba8571746f36f07ceca43d311a0e390a9fdcfde6909f9f9be85b3b28,3125
pantry-tree:
size: 2421
sha256: db06db0bf8c9620f4fc4884e154848046827fabd43d31fb4b56b419793b9fd35
original:
hackage: doctemplates-0.9@sha256:eb0bf957ba8571746f36f07ceca43d311a0e390a9fdcfde6909f9f9be85b3b28,3125
- completed:
hackage: random-1.1@sha256:7b67624fd76ddf97c206de0801dc7e888097e9d572974be9b9ea6551d76965df,1777
pantry-tree:
size: 637
sha256: 14a1b01728c5584e87c9fa00746a66e28ffd89dd2c0eabd334c8463953496e1b
original:
hackage: random-1.1@sha256:7b67624fd76ddf97c206de0801dc7e888097e9d572974be9b9ea6551d76965df,1777
- completed:
hackage: splitmix-0.0.5@sha256:4a49661be63f5aea0e132e9ab51be918789bb4dceb4ab9b15b85ba9cbbef5999,5412
pantry-tree:
size: 1148
sha256: b41d4f60cfabab8b02840906191013ee06fe2357371103a471c7cc55eda9e462
original:
hackage: splitmix-0.0.5@sha256:4a49661be63f5aea0e132e9ab51be918789bb4dceb4ab9b15b85ba9cbbef5999,5412
snapshots:
- completed:
size: 537868
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/9/21.yaml
sha256: 0a3be91c2bce851de4755003cfb1d85d62b6f90276231fcc305729c0c5c864a9
original: lts-9.21
size: 585817
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/4.yaml
sha256: ea3a318eafa9e9cc56bfbe46099fd0d54d32641ab7bbe1d182ed8f5de39f804c
original: lts-18.4
38 changes: 19 additions & 19 deletions tutorials/elm/testing/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ For this tutorial, the subject under test is a simple guessing number program. I

1) Define a module and the necessary imports:

```haskell
```elm
module GuessNumber exposing (..)

import Browser
Expand All @@ -88,7 +88,7 @@ import Random as R

2) Define the model (`Model`) and the types of messages (`Msg`) for the program:

```haskell
```elm
type alias Model =
{ guess: Int -- Random number to be guessed
, isInvalid : Bool -- Simple flag to check if the input is a number or not
Expand All @@ -104,7 +104,7 @@ type Msg

3) Define the `view` function:

```haskell
```elm
view : Model -> H.Html Msg
view model =
H.div []
Expand Down Expand Up @@ -170,7 +170,7 @@ viewGuess int = H.li [][ H.text <| "Already tried " ++ String.fromInt int ]

4) Define the `update` function, which updates the state of the program based on the messages:

```haskell
```elm
update : Msg -> Model -> (Model, Eff)
update msg model =
case msg of
Expand All @@ -189,7 +189,7 @@ update msg model =

5) Define `init` which represents the initial state of the program:

```haskell
```elm
init : flags -> (Model, Eff)
init _ = (
{ guess = 0
Expand All @@ -201,7 +201,7 @@ init _ = (

If you've tried Elm before, you might be wondering about `Eff`. Usually the `update` function returns `Model` or `(Model, Cmd Msg)`. In this case, `Eff` is just a type that represents the effects in our program. It looks like this:

```haskell
```elm
type Eff = NoOP | GenRndGuess ({ onGenerate: Int -> Msg })
```

Expand All @@ -210,7 +210,7 @@ Currently, the details of `Cmd msg` are not available. So, `Eff` is necessary to
Finally, define `main` which plugs everything together. Of course, `main` needs `update` to match the type `Msg -> Model -> (Model Cmd Msg)` and `init` to match `flags -> (Model, Cmd Msg)`. Consequently, we need a way to convert `Eff` back into `Cmd Msg`. The function `run` will do that:


```haskell
```elm
run : Eff -> Cmd Msg
run eff =
case eff of
Expand All @@ -221,7 +221,7 @@ run eff =

Then, we can define `main` like this:

```haskell
```elm
main : Program () Model Msg
main =
Browser.element {
Expand All @@ -241,15 +241,15 @@ Elm is a functional and type safe programming language. Additionally, it avoids

`GuessState` will hold our attempts or the correct number guessed, and `Attempt` will wrap a correct or wrong attempt:

```haskell
```elm
type GuessState = RightGuess Int | Attempts (S.Set Int)

type Attempt = Correct Int | Wrong Int
```

The smart constructor `mkAttempt` can be used to insert attempts into the `GuessState` data structure:

```haskell
```elm
mkAttempt : Int -> Int -> Attempt
mkAttempt guess attempt =
attempt |>
Expand All @@ -271,7 +271,7 @@ insert attempt guessList =

We can write expectations and fuzzy tests to unit test our code. First, let's define a testing module with the following definition and imports:

```haskell
```askell
module Test.GuessNumber exposing (..)

import GuessNumber as GN
Expand All @@ -294,7 +294,7 @@ We can cover unit test cases using the [expectation module][Expect]. For example
1. `insert` returns a `RightGuess` when the input is `Correct`.
1. `insert` appends `Wrong` attempts to the set of `Attempts`.

```haskell
```elm
describe "insert
[
describe "given a correct attempt"
Expand All @@ -319,7 +319,7 @@ These tests are simple in that they only cover specific cases of what `insert` d
### Fuzzy tests
[Property tests or fuzzy tests][property-tests] will increase our confidence in our code because they test multiple scenarios to make sure that a property is satisfied. For example, test that `insert` leaves the game state the same after a correct attempt, it does not matter which is the following attempt. We can write this property test using the [Fuzz module][Fuzz].

```haskell
```elm
fuzzTest : Test
fuzzTest =
describe "props insert"
Expand All @@ -338,7 +338,7 @@ There is much more to say about [property tests][elm-fuzz-testing], but that cou

We could add some unit tests for `update` and `view`:

```haskell
```elm
updateTests : Test
updateTests =
describe "update"
Expand Down Expand Up @@ -389,7 +389,7 @@ Ok, let's write them!

I mentioned earlier that `Cmd` details are not reveled, so we had to create an intermediate type (`Eff`) that can help us to simulate the effects in our test module. We already defined the effects for our program in `run`, now let's do the same for our tests.

```haskell
```elm
perform : msg -> PT.SimulatedEffect msg
perform = STask.perform identity << STask.succeed

Expand Down Expand Up @@ -424,7 +424,7 @@ Let's implement the first test case following these steps:
1. Click on the button `"Guess!"`, and
1. Expect to see the message `"Invalid"`.

```haskell
```elm
test "with an invalid input shows message" <|
\() ->
start
Expand All @@ -441,7 +441,7 @@ Now, the second test case:
1. Make some wrong attempts, and
1. Expect to see the wrong attempts listed.

```haskell
```elm
test "shows list of wrong messages" <|
\() ->
start
Expand All @@ -467,7 +467,7 @@ Finally, our last test case follows these steps:
1. Insert the input text `"10"`, and
1. Expect to see the message: `"You guessed 10 correctly"`.

```haskell
```elm
test "shows message when guess is correct" <|
\() ->
start
Expand All @@ -488,7 +488,7 @@ These integration tests provide the following benefits:
1. They add more confidence to our code base.
1. We can create simple helpers to reduce the tests even more. After all, the actions are composable. For example:

```haskell
```elm
clickWithInput input = PT.fillIn "number" "Number" input |> PT.clickButton "Guess!"
```

Expand Down