File: test.js

package info (click to toggle)
python-pattern 2.6%2Bgit20150109-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,672 kB
  • sloc: python: 53,865; xml: 11,965; ansic: 2,318; makefile: 94
file content (41 lines) | stat: -rw-r--r-- 1,161 bytes parent folder | download | duplicates (5)
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
function assert(expression) {
    /* Throws AssertException if the given expression evaluates to false.
     */
	if (!expression) throw "AssertException";
}

function TestCase() {
    /* TestCase objects have a setUp() and a tearDown() method, 
     * called before and after each test respectively.
     * Tests in a TestCase have method names starting with "test".
     */ 
    this.setUp = function() {
        return;
    };
    this.tearDown = function() {
        return;
    };
    this.testMethod = function() {
        assert(true == false);
    };	
}

function run(tests) {
    /* Executes each method which name starts with "test",
     * for each TestCase object in the given array.
     * Throws AssertException if the method fails.
     */
    for (var i=0; i < tests.length; i++) {
        for (var method in tests[i]) {
            if (method.substring(0,4) == "test") {
                tests[i].setUp();
                try {
                    tests[i][method]();
                } catch(e) {
                    console.error(e + " in " + method + "()");
                }
                tests[i].tearDown();
            }
        }
    }
}