aboutsummaryrefslogtreecommitdiff
path: root/src/nbc/test-library.sml
diff options
context:
space:
mode:
authorCalvin <calvin@EESI>2013-03-15 15:26:20 -0400
committerCalvin <calvin@EESI>2013-03-15 15:26:20 -0400
commitb632667ce57af89691407bb8668e1512775278ae (patch)
treeb5742cef185f1cc4a7ba6005b5b4116ce7558a01 /src/nbc/test-library.sml
parent39e39f82cc38d71018882b0aaaf58255858a7c56 (diff)
nbc added
Diffstat (limited to 'src/nbc/test-library.sml')
-rw-r--r--src/nbc/test-library.sml50
1 files changed, 50 insertions, 0 deletions
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