summaryrefslogtreecommitdiff
path: root/console/harness/framework.js
blob: 04164e18ceca3772a6fff3e661ac50fdd1388b65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2009 the Sputnik authors.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

function Test262Error(message) {
  this.message = message;
}

Test262Error.prototype.toString = function () {
  return "Test262 Error: " + this.message;
};

function testFailed(message) {
  throw new Test262Error(message);
}

function testPrint(message) {

}

/**
 * It is not yet clear that runTestCase should pass the global object
 * as the 'this' binding in the call to testcase.
 */
var runTestCase = (function(global) {
  return function(testcase) {
    if (!testcase.call(global)) {
      testFailed('test function returned falsy');
    }
  };
})(this);

function assertTruthy(value) {
  if (!value) {
    testFailed('test return falsy');
  }
}


/**
 * falsy means we expect no error.
 * truthy means we expect some error.
 * A non-empty string means we expect an error whose .name is that string.
 */
var expectedErrorName = false;

/**
 * What was thrown, or the string 'Falsy' if something falsy was thrown.
 * null if test completed normally.
 */
var actualError = null;

function testStarted(expectedErrName) {
  expectedErrorName = expectedErrName;
}

function testFinished() {
  var actualErrorName = actualError && (actualError.name ||
                                        'SomethingThrown');
  if (actualErrorName) {
    if (expectedErrorName) {
      if (typeof expectedErrorName === 'string') {
        if (expectedErrorName === actualErrorName) {
          return;
        }
        testFailed('Threw ' + actualErrorName +
                   ' instead of ' + expectedErrorName);
      }
      return;
    }
    throw actualError;
  }
  if (expectedErrorName) {
    if (typeof expectedErrorName === 'string') {
      testFailed('Completed instead of throwing ' +
                 expectedErrorName);
    }
    testFailed('Completed instead of throwing');
  }
}