How to make command line assertions without elm test in Elm 0.18?
I had dozens of Elm 0.17 programs to experiment with the language. Each script contains simple assertions, and the program did and did all of the assertions, and the program would have succeeded (process exit code 0) or failed (process exit code not 0). Here's an example:
module Main exposing (..)
import ElmTest exposing (runSuite, suite, defaultTest, assertEqual)
import List exposing (map)
boss = { name = "Alice", salary = 200000 }
worker = { name = "Bob", salary = 50000, supervisor = boss }
newWorker = { worker | name = "Carol" }
payrollTax : { a | salary : Float } -> Float
payrollTax { salary } = salary * 0.15
main = runSuite <| suite "Exploring records" <| map defaultTest
[ assertEqual "Alice" (.name boss)
, assertEqual boss worker.supervisor
, assertEqual 7500.0 (payrollTax worker)
, assertEqual boss newWorker.supervisor
]
Back to Elm 0.17, I would just run
$ elm make records.elm --output tests.js && node tests.js
And great, I would see if the tests worked!
I finally decided to run elm upgrade
to get to 0.18, and now (without much surprise) all these things are broken. Apparently the whole concept has elm-test
now completely changed! Surely elm upgrade
did a good job of updating myelm-package.json
"dependencies": {
"elm-community/elm-test": "4.0.0 <= v < 5.0.0",
but a new module no longer has ElmTest
and runSuite
and friends. I read the documents and see what we have now Test
, Expect
and Fuzz
what is good. But it seems that now we have to run
elm test init
and then
elm test
to detect and run all tests. Instead of writing an application with, main
we now, I believe, should put tests in the test directory as modules, exposing the object Test
. Then run elm test
.
But I am not trying to run tests! I just want to write small scripts that make assertions about language features. I have done this in several dozen other languages ββand I find it a great way to learn.
How, then, in Elm 0.18, can I create a program that I can run with elm make
or similar, that runs from the command line and has assertions? (I understand Elm is not for command line programs, but it was easy to do in 0.17, so how can I do something like that in 0.18?
source to share
You were using an older version of this library. runSuite, assertions, etc. from version 1.0.0 and current version is 4.0.0+.
I recommend you read the 0.17 to 0.18 Upgrade Guide and the docs for elm-community / elm-test latest
Hope this helps.
source to share