From b632667ce57af89691407bb8668e1512775278ae Mon Sep 17 00:00:00 2001 From: Calvin Date: Fri, 15 Mar 2013 15:26:20 -0400 Subject: nbc added --- src/nbc/test-library.sml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/nbc/test-library.sml (limited to 'src/nbc/test-library.sml') diff --git a/src/nbc/test-library.sml b/src/nbc/test-library.sml new file mode 100644 index 0000000..6821e74 --- /dev/null +++ b/src/nbc/test-library.sml @@ -0,0 +1,50 @@ +signature TEST = sig + type test = + { + description: string + , expectedResult: string + , function: unit -> string + } + val single: test -> unit + val list: test list -> unit +end + +structure Test = struct + fun single {description, expectedResult, function} = + let + val actualResult = function () + in + if expectedResult = actualResult then + TextIO.output ( + TextIO.stdErr + , ( + description + ^ " succeeded.\n" + ) + ) + else ( + TextIO.output ( + TextIO.stdErr + , ( + description + ^ " was supposed to be " + ^ expectedResult + ^ ", but was actually " + ^ actualResult + ^ ".\n" + ) + ); OS.Process.exit OS.Process.failure + ) + end handle exception' => ( + TextIO.output ( + TextIO.stdErr + , ( + description + ^ " failed with exception " + ^ exnMessage exception' + ^ ".\n" + ) + ); OS.Process.exit OS.Process.failure + ) + fun list tests = app single tests +end -- cgit v1.2.3