I'm currently grading assignments for a course on SML. I've written some test cases to automatically check correctness of functions in the students' assignments, and I'd like to be able to import their code and then run the test cases against that code. I'm imagining something similar to python import semantics. Right now, the best solution I have is to copy-paste this code at the bottom of each assignment. Is this possible with SML?
The simplest way to load files in the SML/NJ interactive system (at the “-” prompt that you get when you run sml), is to call the use function, passing it the file name or path as a string. So to load two files we can call use twice, passing the appropriate file names. - use "wff-mod. sml"; - use "pc.
To start the SML interpreter at the terminal, type "sml" and press enter. If the left/right cursor keys don't work, run "rlwrap sml" instead. Using rlwrap also provides a history; use the up/down arrows to access previously entered lines. To exit SML, press CTRL+D (or CTRL+Z under Windows).
Save code in simple text files with a . sml extension (if you are on a Windows machine -- the editor Textpad is fairly nice: https://www.textpad.com/ . You can download an SML syntax definition file for syntax highlighting). Then, in the REPL, type use "path/filename.
Use use
:
use "filename.sml";
(* your test cases here *)
If you have the student solution in "student.sml" and your test cases in "tests.sml":
use "student.sml";
use "tests.sml";
Look at QCheck, a unit testing library for SML
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With