Reputation: 88378
I had dozens of Elm 0.17 programs for experimenting with the language. The scripts each featured simple assertions, and the program would execute and run all the assertions, and the program would succeed (process exit code 0) or fail (process exit code not 0). Here is 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 in Elm 0.17, I would just run
$ elm make records.elm --output tests.js && node tests.js
And great, I'd see if the tests worked!
I finally decided to run elm upgrade
to get to 0.18 and now (no real surprise) all those things are broken. Apparently, the whole concept of elm-test
is now completely changed! Of course, elm upgrade
did a nice job of updating my elm-package.json
"dependencies": {
"elm-community/elm-test": "4.0.0 <= v < 5.0.0",
but the new module does not have ElmTest
and runSuite
and friends anymore. I've read the docs and see that we now have Test
, Expect
, and Fuzz
, which is fine. But it seems that now we are supposed to run
elm test init
and then
elm test
to discover and run all the tests. Instead of writing an app with main
, we're now, I think, supposed to put tests in a test directory as modules exposing a Test
object. Then we run elm test
.
But I am not trying to run tests! I just want to write little scripts that make assertions about language features. I've done this in a couple dozen other languages and I find it a great way to learn.
How, then, in Elm 0.18, can I make a program that I can run with elm make
or similar, that runs from the command line and has assertions? (I realize Elm is not for command line programs, but this was easy to do in 0.17, so how can I do something similar in 0.18?
Upvotes: 3
Views: 166
Reputation: 175
You were using an old version of that library. runSuite, assertions, etc are from 1.0.0 version and the current version is 4.0.0+.
I recomend you read the Upgrading guide from 0.17 to 0.18 and the docs for elm-community/elm-test latest
I hope it helps.
Upvotes: 2