aboutsummaryrefslogtreecommitdiff
path: root/test/sandbox.js
blob: 2ce9f6e1718136c9e90dbecb58b4c786b3c17d92 (about) (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
80
81
82
83
var semver = require("semver");
var vm = require("vm");

function safe_log(arg, level) {
    if (arg) switch (typeof arg) {
      case "function":
        return arg.toString();
      case "object":
        if (/Error$/.test(arg.name)) return arg.toString();
        arg.constructor.toString();
        if (level--) for (var key in arg) {
            if (!Object.getOwnPropertyDescriptor(arg, key).get) {
                arg[key] = safe_log(arg[key], level);
            }
        }
    }
    return arg;
}

var FUNC_TOSTRING = [
    "Function.prototype.toString = Function.prototype.valueOf = function() {",
    "    var id = 100000;",
    "    return function() {",
    '        if (this === Array) return "[Function: Array]";',
    '        if (this === Object) return "[Function: Object]";',
    "        var i = this.name;",
    '        if (typeof i != "number") {',
    "            i = ++id;",
].concat(Object.getOwnPropertyDescriptor(Function.prototype, "name").configurable ? [
    '            Object.defineProperty(this, "name", {',
    "                get: function() {",
    "                    return i;",
    "                }",
    "            });",
] : [], [
    "        }",
    '        return "[Function: " + i + "]";',
    "    }",
    "}();",
    'Object.defineProperty(Function.prototype, "valueOf", { enumerable: false });',
]).join("\n");
exports.run_code = function(code) {
    var stdout = "";
    var original_write = process.stdout.write;
    process.stdout.write = function(chunk) {
        stdout += chunk;
    };
    try {
        vm.runInNewContext([
            FUNC_TOSTRING,
            "!function() {",
            code,
            "}();",
        ].join("\n"), {
            console: {
                log: function(msg) {
                    if (arguments.length == 1 && typeof msg == "string") {
                        return console.log("%s", msg);
                    }
                    return console.log.apply(console, [].map.call(arguments, function(arg) {
                        return safe_log(arg, 3);
                    }));
                }
            }
        }, { timeout: 5000 });
        return stdout;
    } catch (ex) {
        return ex;
    } finally {
        process.stdout.write = original_write;
    }
};
exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expected, actual) {
    if (typeof expected != typeof actual) return false;
    if (typeof expected != "string") {
        if (expected.name != actual.name) return false;
        expected = expected.message.slice(expected.message.lastIndexOf("\n") + 1);
        actual = actual.message.slice(actual.message.lastIndexOf("\n") + 1);
    }
    return expected == actual;
} : function(expected, actual) {
    return typeof expected == typeof actual && expected.toString() == actual.toString();
};
gexps (these procedures were only used for their side-effects). * gnu/services/messaging.scm (serialize-field, serialize-field-list, enclose-quotes, serialize-raw-content, serialize-ssl-configuration, serialize-virtualhost-configuration-list, serialize-int-component-configuration-list, serialize-ext-component-configuration-list, serialize-virtualhost-configuration, serialize-int-component-configuration, serialize-ext-component-configuration, serialize-prosody-configuration): Return strings or string-valued gexps and stop printing. (prosody-activation): Use SERIALIZE-PROSODY-CONFIGURATION's return value with MIXED-TEXT-FILE instead of using its output with PLAIN-FILE. (serialize-non-negative-integer, serialize-non-negative-integer-list): Convert numbers to strings. (file-object?, serialize-file-object, file-object-list?, serialize-file-object-list): New procedures. (ssl-configuration)[capath, cafile], (prosody-configuration)[plugin-paths, groups-file]: Replace FILE-NAME with FILE-OBJECT. * guix/gexp.scm (file-like?): New exported procedure. Clément Lassieur 2018-01-15doc: Deprecate 'bitlbee-service' procedure....* gnu/services/messaging.scm (bitlbee-service): Mark as deprecated. * doc/guix.texi (Messaging Services): Document 'bitlbee-service-type' and 'bitlbee-configuration'. Remove 'bitlbee-service'. Ludovic Courtès 2018-01-15services: bitlbee: Move to (gnu services messaging)....* gnu/services/networking.scm (<bitlbee-configuration>) (bitlbee-shepherd-service, %bitlbee-accounts, %bitlbee-activation) (bitlbee-service-type, bitlbee-service): Move to... * gnu/services/messaging.scm: ... here. * doc/guix.texi (Networking Services): Move 'bitlbee-service' doc to... (Messaging Services): ... here. Ludovic Courtès 2017-12-24services: messaging: Use HTTPS for prosody.im URLs....* gnu/services/messaging.scm (prosody-configuration): Use HTTPS whenever referring to prosody.im URLs in documentation. * doc/guix.texi (Messaging Services): Likewise. Tobias Geerinckx-Rice 2017-11-28services: configuration: Show default values of list types....* doc/guix.texi (Messaging Services): Regenerate it. * gnu/services/configuration.scm (show-default?): Check VAL rather than DEFAULT. * gnu/services/messaging.scm (show-default?): Check VAL rather than DEFAULT. (prosody-configuration)[modules-enabled]: Remove default value from docstring. Clément Lassieur 2017-11-26services: prosody: Add support for disable-sasl-mechanisms....* doc/guix.texi (Messaging Services): Update accordingly. * gnu/services/messaging.scm (prosody-configuration)[disable-sasl-mechanisms]: New field. Clément Lassieur 2017-11-26services: prosody: Allow to add raw content to the config file....* doc/guix.texi (Messaging Services): Update accordingly. * gnu/services/messaging.scm (prosody-configuration)[raw-content]: New field. (raw-content?, serialize-raw-content): New procedures. Clément Lassieur 2017-11-26services: prosody: Add support for http-max-content-size....* doc/guix.texi (Messaging Services): Update accordingly. * gnu/services/messaging.scm (prosody-configuration)[http-max-content-size]: New field. Clément Lassieur 2017-11-26services: prosody: Add support for http-external-url....* doc/guix.texi (Messaging Services): Update accordingly. * gnu/services/messaging.scm (prosody-configuration)[http-external-url]: New field. Clément Lassieur 2017-11-26services: prosody: Adapt to Prosody 0.10.0....* doc/guix.texi (Messaging Services): Add "mam" as a module example. Document 'prosodyctl check'. Replace 'prosodyctl cert request' with 'prosodyctl cert import'. Regenerate it. * gnu/services/messaging.scm (serialize-module-list): Remove "posix" from the default modules list because it is now automatically loaded. (ssl-configuration)[key, certificate]: Remove them because they are now automatically located. Fix their docstrings. (%default-modules-enabled): Add "carbons" and "blocklist". (prosody-configuration)[certificates]: Set default directory from which certificates/keys will be automatically located. Clément Lassieur 2017-03-24services: Factorize define-maybe macro....* gnu/services/configuration.scm (id): New procedure extracted from define-configuration. (define-maybe): New exported procedure, moved from messaging.scm. * gnu/services/messaging.scm (define-maybe): Remove it. (id): Move declaration inside define-all-configurations which is now the only caller procedure. Signed-off-by: Clément Lassieur <clement@lassieur.org> Mathieu Othacehe 2017-03-08services: prosody: Use 'id' to introduce unhygienic top-level identifiers....* gnu/services/messaging.scm (define-all-configurations): Use 'id' to introduce raw/literal/unhygienic top-level identifiers. Fixes compilation with Guile 2.2. Ludovic Courtès 2017-03-08services: prosody: Make sure 'id' is available at expansion time....* gnu/services/messaging.scm (id): Use 'define-syntax-rule' instead of 'define' to make sure 'id' is available at expansion time. Ludovic Courtès 2017-02-10tests: Add 'prosody-service-type' test....* gnu/tests/messaging.scm: New file. * gnu/services/messaging.scm: New exported procedure. (<shepherd-service>)[provision]: Add 'xmpp-daemon'. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Clément Lassieur 2017-01-23services: prosody: Fix activation script....* gnu/services/messaging.scm (prosody-activation): Import (guix build utils) for 'mkdir-p'. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Clément Lassieur 2017-01-08gnu: Add Prosody service....* gnu/services/messaging.scm: New file. * gnu/services/configuration.scm: New exported procedures. * gnu/local.mk (GNU_SYSTEM_MODULES): Add gnu/services/messaging.scm. * doc/guix.texi (Messaging Services): New section. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Clément Lassieur