File: runTsuite.js

package info (click to toggle)
libnginx-mod-js 0.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,808 kB
  • sloc: ansic: 114,096; perl: 8,447; javascript: 2,520; exp: 487; sh: 322; xml: 312; python: 181; makefile: 18
file content (87 lines) | stat: -rw-r--r-- 2,373 bytes parent folder | download
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
80
81
82
83
84
85
86
87
async function run(tlist) {
    function validate(t, r, i) {
        if (r.status == "fulfilled" && r.value === "SKIPPED") {
            return true;
        }

        if (r.status == "fulfilled" && !t[i].exception) {
            return r.value === "SUCCESS";
        }

        if (r.status == "rejected" && t[i].exception) {
            return true;
        }

        if (r.status == "rejected" && t[i].optional) {
            return r.reason.toString().startsWith("InternalError: not implemented");
        }

        return false;
    }

    function map(ts) {
        return ts.tests.map(t => {
            try {
                if (t.skip && t.skip()) {
                    return Promise.resolve("SKIPPED");
                }

                return ts.T(ts.prepare_args(t, ts.opts));

            } catch (e) {
                return Promise.reject(e);
            }
        });
    }

    for (let k = 0; k < tlist.length; k++) {
        let ts = tlist[k];

        if (ts.skip && ts.skip()) {
            continue;
        }

        let results = await Promise.allSettled(map(ts));
        let r = results.map((r, i) => { r.passed = validate(ts.tests, r, i); return r; });

        let passed = r.filter(r => r.passed).length;
        if (passed != ts.tests.length) {
            r.forEach((r, i) => {
                if (!r.passed) {
                    console.log(`   ${JSON.stringify(ts.tests[i])}\n    with reason: ${r.reason}`);
                }
            })

            console.log(`${ts.name} FAILED: [${passed}/${ts.tests.length}]`);
        }
    }
}

function merge(to, from) {
    let r = Object.assign(Array.isArray(to) ? [] : {}, to);
    Object.keys(from).forEach(v => {
        if (typeof r[v] == 'object' && typeof from[v] == 'object') {
            r[v] = merge(r[v], from[v]);

        } else if (typeof from[v] == 'object') {
            if (Buffer.isBuffer(from[v])) {
                r[v] = Buffer.from(from[v]);

            } else if (from[v] instanceof Uint8Array) {
                r[v] = new Uint8Array(from[v]);

            } else if (from[v] instanceof ArrayBuffer) {
                r[v] = new ArrayBuffer(from[v].byteLength);

            } else {
                r[v] = Object.assign(Array.isArray(from[v]) ? [] : {}, from[v]);
            }

        } else {
            r[v] = from[v];
        }
    })

    return r;
}