smlunit hello world – with a python dependency

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.

  1. Download the smlunit github project. (at a minimum you need the smlunit file and the lib directory)
  2. Download the asserts file and put it in your directory (or elsewhere and refer to it from there)
  3. Write a simple function in a file named helloWorld.sml:
    fun hello(name : string) = "Hello " ^ name
  4. Write a simple test in a file named helloWorldTest.sml:
    use "asserts.sml";
    use "helloWorld.sml";
    
    assertEqual "hello" (hello("Jeanne")) "did it work?";
  5. Run it:
    Jjeanne$ ./smlunit helloWorldTest.sml 
    did it work?..........................................................FAIL
        Expected: "Hello Jeanne"
        Actual: "hello"
    
    ---------------------------------------
    Ran 1 test in 0.204 seconds (1 failure)
    
  6. It didn’t work! Fix the expected string in the test (should be assertEqual “Hello Jeanne”…
  7. Run the test again
    jeanne$ ./smlunit helloWorldTest.sml 
    did it work?............................................................OK
    
    ---------------------------
    Ran 1 test in 0.207 seconds
    
  8. Success!

Leave a Reply

Your email address will not be published. Required fields are marked *