2 * (C) Copyright 2008 John J. Foerch
4 * Use, modification, and distribution are subject to the terms specified in the
8 function assert (got) {
10 throw new Error("expected a true value, got <"+got+">.");
14 function assert_equals (got, expect) {
16 throw new Error("expected <"+expect+">, got <"+got+">.");
20 function assert_error (fn) {
26 throw new Error("expected an error calling <"+fn+">.");
29 function assert_null (got) {
31 throw new Error("expected null, got <"+got+">.");
35 function assert_not (got) {
37 throw new Error("expected a false value, got <"+got+">.");
41 function assert_objects_equal (got, expect) {
42 if (typeof(got) != "object" || typeof(expect) != "object" ||
43 got === null || expect === null)
45 return assert_equals(got, expect);
47 if (got.constructor !== expect.constructor)
48 throw new Error("objects are of different type");
49 var expectkeys = [i for (i in expect)];
50 var gotkeys = [i for (i in got)];
51 if (gotkeys.length != expectkeys.length)
52 throw new Error("objects have different property counts");
53 for (var i in expectkeys) {
54 assert_objects_equal(got[i], expect[i]);
60 function walnut_results () {
65 function walnut_run (suite) {
66 var results = new walnut_results();
67 if (suite.suite_setup)
69 for (var k in suite) {
70 if (k.substr(0,5) == 'test_') {
87 if (suite.suite_teardown)
88 suite.suite_teardown();
89 dumpln(results.run+" run, "+results.failed+" failed");