2 * (C) Copyright 2008 John J. Foerch
4 * Use, modification, and distribution are subject to the terms specified in the
10 function assert (got) {
12 throw new Error("expected a true value, got <"+got+">.");
16 function assert_equals (got, expect) {
18 throw new Error("expected <"+expect+">, got <"+got+">.");
22 function assert_error (fn) {
28 throw new Error("expected an error calling <"+fn+">.");
31 function assert_null (got) {
33 throw new Error("expected null, got <"+got+">.");
37 function assert_not (got) {
39 throw new Error("expected a false value, got <"+got+">.");
43 function assert_objects_equal (got, expect) {
44 if (typeof(got) != "object" || typeof(expect) != "object" ||
45 got === null || expect === null)
47 return assert_equals(got, expect);
49 if (got.constructor !== expect.constructor)
50 throw new Error("objects are of different type");
51 var expectkeys = [i for (i in expect)];
52 var gotkeys = [i for (i in got)];
53 if (gotkeys.length != expectkeys.length)
54 throw new Error("objects have different property counts");
55 for (var i in expectkeys) {
56 assert_objects_equal(got[i], expect[i]);
62 function walnut_results () {
67 function walnut_run (suite) {
68 var results = new walnut_results();
69 if (suite.suite_setup)
71 for (var k in suite) {
72 if (k.substr(0,5) == 'test_') {
89 if (suite.suite_teardown)
90 suite.suite_teardown();
91 dumpln(results.run+" run, "+results.failed+" failed");