Three years is long enough to forget a lot so I managed to forget that I got this working with python shortly after writing this blog post. Writing this down so I don’t forget again.
- Download the smlunit github project. (at a minimum you need the smlunit file and the lib directory)
- Download the asserts file and put it in your directory (or elsewhere and refer to it from there)
- Write a simple function in a file named helloWorld.sml:
fun hello(name : string) = "Hello " ^ name
- Write a simple test in a file named helloWorldTest.sml:
use "asserts.sml"; use "helloWorld.sml"; assertEqual "hello" (hello("Jeanne")) "did it work?";
- Run it:
Jjeanne$ ./smlunit helloWorldTest.sml did it work?..........................................................FAIL Expected: "Hello Jeanne" Actual: "hello" --------------------------------------- Ran 1 test in 0.204 seconds (1 failure)
- It didn’t work! Fix the expected string in the test (should be assertEqual “Hello Jeanne”…
- Run the test again
jeanne$ ./smlunit helloWorldTest.sml did it work?............................................................OK --------------------------- Ran 1 test in 0.207 seconds
- Success!