diff --git a/.idea/runConfigurations/All_Mocha_Tests.xml b/.idea/runConfigurations/All_Mocha_Tests.xml index d88b64134..1106dab01 100644 --- a/.idea/runConfigurations/All_Mocha_Tests.xml +++ b/.idea/runConfigurations/All_Mocha_Tests.xml @@ -1,6 +1,6 @@ - project + /opt/compiler-explorer/node/bin/node $PROJECT_DIR$/node_modules/mocha $PROJECT_DIR$ diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4b66eb079..8587ff055 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -72,3 +72,4 @@ From oldest to newest contributor, we would like to thank: - [Paul Scharnofske](https://github.com/asynts) - [Sebastian Staffa](https://github.com/Staff-d) - [Andreas Jonson](https://github.com/andjo403) +- [Sam Clegg](https://github.com/sbc100) diff --git a/etc/config/c++.amazon.properties b/etc/config/c++.amazon.properties index 5d99cf858..8285a2c47 100644 --- a/etc/config/c++.amazon.properties +++ b/etc/config/c++.amazon.properties @@ -1,4 +1,4 @@ -compilers=&gcc86:&icc:&clang:&rvclang:&cl:&cross:&ellcc:&zapcc:www.godbolt.ms@443:&djggp +compilers=&gcc86:&icc:&clang:&rvclang:&wasmclang:&cl:&cross:&ellcc:&zapcc:www.godbolt.ms@443:&djggp defaultCompiler=g91 demangler=/opt/compiler-explorer/gcc-8.2.0/bin/c++filt objdumper=/opt/compiler-explorer/gcc-8.2.0/bin/objdump @@ -210,6 +210,14 @@ compiler.rv64clang.exe=/opt/compiler-explorer/clang-trunk/bin/clang++ compiler.rv64clang.name=RISC-V rv64gc clang (trunk) compiler.rv64clang.options=-target riscv64 -march=rv64gc -mabi=lp64 +# Clang for WebAssembly +group.wasmclang.compilers=wasm32clang +group.wasmclang.groupName=Clang WebAssembly +group.wasmclang.supportsBinary=false +compiler.wasm32clang.exe=/opt/compiler-explorer/clang-trunk/bin/clang++ +compiler.wasm32clang.name=WebAssembly clang (trunk) +compiler.wasm32clang.options=-target wasm32 + # icc for x86 group.icc.compilers=icc1301:icc16:icc17:icc18:icc19:icc191 group.icc.intelAsm=-masm=intel diff --git a/etc/config/compiler-explorer.beta.properties b/etc/config/compiler-explorer.beta.properties index 0efc0cdaa..1ba5dd60c 100644 --- a/etc/config/compiler-explorer.beta.properties +++ b/etc/config/compiler-explorer.beta.properties @@ -3,3 +3,4 @@ httpRoot=/beta urlShortenService=none storageSolution=s3 motdUrl=https://s3.dualstack.us-east-1.amazonaws.com/compiler-explorer/motd/motd-beta.json +supportsExecute=true diff --git a/etc/config/d.amazon.properties b/etc/config/d.amazon.properties index c3a6d27ad..273a0eec7 100644 --- a/etc/config/d.amazon.properties +++ b/etc/config/d.amazon.properties @@ -63,7 +63,7 @@ group.dmd.compilerType=dmd group.dmd.groupName=DMD2 group.dmd.binaryHideFuncRe=^(_.*|\.text.*|(de)?register_tm_clones|frame_dummy|.*@plt)$ group.dmd.optionsBlacklistRe=^((@|-conf|-debuglib|-defaultlib|-D|-H|-I|-J|-o|-run|-X).*)$ -group.dmd.demangler=d/demangle +group.dmd.demangler=/opt/compiler-explorer/demanglers/d/demangle group.dmd.postProcess=/opt/compiler-explorer/dmd-2.078.3/dmd2/linux/bin64/obj2asm group.dmd.isSemVer=true group.dmd.baseName=dmd diff --git a/etc/config/haskell.amazon.properties b/etc/config/haskell.amazon.properties index 3176dd93f..692db79c2 100644 --- a/etc/config/haskell.amazon.properties +++ b/etc/config/haskell.amazon.properties @@ -1,5 +1,6 @@ compilers=&ghc defaultCompiler=ghc862 +demangler=/opt/compiler-explorer/demanglers/haskell/demangle group.ghc.compilers=ghc802:ghc841:ghc842:ghc843:ghc844:ghc861:ghc862 group.ghc.isSemVer=true diff --git a/etc/config/rust.amazon.properties b/etc/config/rust.amazon.properties index 6b6f514c1..5d0552ab7 100644 --- a/etc/config/rust.amazon.properties +++ b/etc/config/rust.amazon.properties @@ -1,6 +1,7 @@ compilers=&rust objdumper=/opt/compiler-explorer/gcc-8.1.0/bin/objdump defaultCompiler=r1340 +demangler=/opt/compiler-explorer/demanglers/rust/bin/rustfilt group.rust.compilers=r1340:r1330:r1320:r1310:r1300:r1290:r1280:r1271:r1270:r1260:r1250:r1240:r1230:r1220:r1210:r1200:r1190:r1180:r1170:r1160:r1151:r1140:r1130:r1120:r1110:r1100:r190:r180:r170:r160:r150:r140:r130:r120:r110:r100:nightly:beta group.rust.compilerType=rust group.rust.isSemVer=true diff --git a/etc/firejail/sandbox.profile b/etc/firejail/sandbox.profile index 13927f2d0..a724ce4e5 100644 --- a/etc/firejail/sandbox.profile +++ b/etc/firejail/sandbox.profile @@ -10,7 +10,13 @@ memory-deny-write-execute # Using seccomp.keep seems to turn things into a whitelist #seccomp.keep ptrace -# TODO need to launder the environment more before executing +# Remove some env vars, mostly to stop people emailing me about them +# SUDO_COMMAND is one with actual somewhat sensitive info +rmenv SUDO_COMMAND +rmenv SUDO_USER +rmenv SUDO_UID +rmenv SUDO_GID +rmenv DBUS_SESSION_BUS_ADDRESS # TODO are these appropriate values? # rlimit-nproc seems not to be as useful as we want; it _seems_ to count *all* processes diff --git a/etc/firejail/standard.inc b/etc/firejail/standard.inc index a1e9e83e2..27d136190 100644 --- a/etc/firejail/standard.inc +++ b/etc/firejail/standard.inc @@ -20,11 +20,6 @@ x11 none shell none disable-mnt -# blacklisting this directory to ensure the "cwd" of the process is not valid when executed. -# this forces firejail to chdir("~") before running, which we rely on. Also good hygiene in -# general, even though the image is pretty much open source. -blacklist /compiler-explorer-image - blacklist /sbin blacklist /usr/local/sbin blacklist /initrd* diff --git a/lib/base-compiler.js b/lib/base-compiler.js index 9dab967ab..75098a0d6 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -123,8 +123,9 @@ class BaseCompiler { return this.exec(compiler, options, execOptions).then(result => { result.inputFilename = inputFilename; - result.stdout = utils.parseOutput(result.stdout, inputFilename); - result.stderr = utils.parseOutput(result.stderr, inputFilename); + const transformedInput = result.filenameTransform(inputFilename); + result.stdout = utils.parseOutput(result.stdout, transformedInput); + result.stderr = utils.parseOutput(result.stderr, transformedInput); return result; }); } @@ -351,7 +352,7 @@ class BaseCompiler { }; }); }).catch((err) => { - logger.debug("Tried to get executable from cache, but got an error: ", err); + logger.debug("Tried to get executable from cache, but got an error: ", {err}); return this.buildExecutableInFolder(key, dirPath).then(result => { if (result.code !== 0) { @@ -831,7 +832,7 @@ Please select another pass or change filters.`; result.asm = postResult.stdout; if (postResult.code !== 0) { result.asm = ``; - logger.error("Error during post-processing", result); + logger.error("Error during post-processing: ", result); } return result; } diff --git a/lib/compilers/dmd.js b/lib/compilers/dmd.js index 8ee342277..b4d96198b 100644 --- a/lib/compilers/dmd.js +++ b/lib/compilers/dmd.js @@ -37,7 +37,9 @@ class DMDCompiler extends BaseCompiler { } execPostProcess(result, postProcesses, outputFilename, maxSize) { - return this.exec(postProcesses[0], ["-l", path.relative(process.cwd(), outputFilename)], {maxOutput: maxSize}) + const dirPath = path.dirname(outputFilename); + const lPath = path.basename(outputFilename); + return this.exec(postProcesses[0], ["-l", lPath], {customCwd: dirPath, maxOutput: maxSize}) .then(postResult => this.handlePostProcessResult(result, postResult)); } diff --git a/lib/exec.js b/lib/exec.js index 3471a31a1..2cbb66223 100644 --- a/lib/exec.js +++ b/lib/exec.js @@ -37,7 +37,10 @@ function setupOnError(stream, name) { }); } -function executeDirect(command, args, options) { +function executeDirect(command, args, options, filenameTransform) { + // filename transform is expected to have been pre-applied by the caller. + // it is passed through here only so clients can see it in the result. + filenameTransform = filenameTransform || (x => x); options = options || {}; const maxOutput = options.maxOutput || 1024 * 1024; const timeoutMs = options.timeoutMs || 0; @@ -117,10 +120,11 @@ function executeDirect(command, args, options) { if (code === null) code = -1; if (timeout !== undefined) clearTimeout(timeout); const result = { - code: code, + code, + okToCache, + filenameTransform, stdout: streams.stdout, - stderr: streams.stderr, - okToCache: okToCache + stderr: streams.stderr }; logger.debug("Execution", {type: "executed", command: command, args: args, result: result}); resolve(result); @@ -132,16 +136,16 @@ function executeDirect(command, args, options) { function sandboxFirejail(command, args, options) { - logger.info("Sandbox execution via firejail", command, args); + logger.info("Sandbox execution via firejail", {command, args}); const execPath = path.dirname(command); const execName = path.basename(command); const jailingOptions = [ '--quiet', + '--deterministic-exit-code', + '--terminate-orphans', '--profile=etc/firejail/sandbox.profile', - // '--debug', - // TODO: If no cwd, just `--private` '--private=/tmp/private-home', else infer... - // hack for now: which relies on knowing the execPath will be in the private temp directory. `--private=${execPath}`, + '--private-cwd', `./${execName}` ].concat(args); command = 'firejail'; @@ -302,7 +306,7 @@ function executeWineDirect(command, args, options) { function executeFirejail(command, args, options) { options = options || {}; const firejail = execProps("firejail"); - const baseOptions = ['--quiet']; + const baseOptions = ['--quiet', '--deterministic-exit-code', '--terminate-orphans']; if (needsWine(command)) { logger.debug("WINE execution via firejail", {command, args}); options.env = applyWineEnv(options.env); @@ -317,15 +321,21 @@ function executeFirejail(command, args, options) { logger.debug("Regular execution via firejail", {command, args}); baseOptions.push('--profile=etc/firejail/execute.profile'); + let filenameTransform; if (options.customCwd) { baseOptions.push(`--private=${options.customCwd}`); - args = args.map(opt => opt.replace(options.customCwd, ".")); + const replacement = options.customCwd; + filenameTransform = opt => opt.replace(replacement, "."); + args = args.map(filenameTransform); delete options.customCwd; + // TODO: once it's supported properly in our patched firejail, make this option common to both customCwd and + // non-customCwd code paths. + baseOptions.push('--private-cwd'); } else { baseOptions.push('--private'); } baseOptions.push(command); - return executeDirect(firejail, baseOptions.concat(args), options); + return executeDirect(firejail, baseOptions.concat(args), options, filenameTransform); } function executeNone(command, args, options) { diff --git a/lib/handlers/compile.js b/lib/handlers/compile.js index a96688a6e..7ef33108f 100644 --- a/lib/handlers/compile.js +++ b/lib/handlers/compile.js @@ -299,7 +299,7 @@ class CompileHandler { } }, error => { - logger.error("Error during compilation", error); + logger.error("Error during compilation: ", error); if (typeof (error) !== "string") { if (error.code) { if (typeof (error.stderr) === "string") { diff --git a/package-lock.json b/package-lock.json index ab1d9b6d7..f2803e695 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1095,22 +1095,17 @@ } }, "chai": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/chai/-/chai-3.5.0.tgz", - "integrity": "sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc=", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", + "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", "dev": true, "requires": { - "assertion-error": "^1.0.1", - "deep-eql": "^0.1.3", - "type-detect": "^1.0.0" - }, - "dependencies": { - "type-detect": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-1.0.0.tgz", - "integrity": "sha1-diIXzAbbJY7EiQihKY6LlRIejqI=", - "dev": true - } + "assertion-error": "^1.1.0", + "check-error": "^1.0.2", + "deep-eql": "^3.0.1", + "get-func-name": "^2.0.0", + "pathval": "^1.1.0", + "type-detect": "^4.0.5" } }, "chai-as-promised": { @@ -1748,20 +1743,12 @@ "dev": true }, "deep-eql": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", - "integrity": "sha1-71WKyrjeJSBs1xOQbXTlaTDrafI=", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", + "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", "dev": true, "requires": { - "type-detect": "0.1.1" - }, - "dependencies": { - "type-detect": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-0.1.1.tgz", - "integrity": "sha1-C6XsKohWQORw6k6FBZcZANrFiCI=", - "dev": true - } + "type-detect": "^4.0.0" } }, "deep-equal": { diff --git a/package.json b/package.json index d18814311..0f9d62661 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ }, "devDependencies": { "aws-sdk-mock": "^1.7.0", - "chai": "3.5.x", + "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "chai-http": "^4.2.1", "codecov": "^3.0.0", diff --git a/static/colour.js b/static/colour.js index 2733413e7..d71cf6bb8 100644 --- a/static/colour.js +++ b/static/colour.js @@ -1,25 +1,25 @@ // Copyright (c) 2016, Matt Godbolt // All rights reserved. -// -// Redistribution and use in source and binary forms, with or without +// +// Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, +// +// * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. "use strict"; @@ -45,7 +45,7 @@ function applyColours(editor, colours, schemeName, prevDecorations) { range: new monaco.Range(line, 1, line, 1), options: { isWholeLine: true, - className: scheme.name + "-" + (ordinal % scheme.count) + className: "line-linkage " + scheme.name + "-" + (ordinal % scheme.count) } }; }); diff --git a/static/colours.css b/static/colours.css index 9c616a5de..0b77a201c 100644 --- a/static/colours.css +++ b/static/colours.css @@ -3,169 +3,169 @@ */ /* rainbow is 12 Set3 */ .rainbow-0 { - background: rgba(141, 211, 199, 0.35) !important; + background: rgba(141, 211, 199, 0.35); } .rainbow-1 { - background: rgba(255, 255, 179, 0.35) !important; + background: rgba(255, 255, 179, 0.35); } .rainbow-2 { - background: rgba(190, 186, 218, 0.35) !important; + background: rgba(190, 186, 218, 0.35); } .rainbow-3 { - background: rgba(251, 128, 114, 0.35) !important; + background: rgba(251, 128, 114, 0.35); } .rainbow-4 { - background: rgba(128, 177, 211, 0.35) !important; + background: rgba(128, 177, 211, 0.35); } .rainbow-5 { - background: rgba(253, 180, 98, 0.35) !important; + background: rgba(253, 180, 98, 0.35); } .rainbow-6 { - background: rgba(179, 222, 105, 0.35) !important; + background: rgba(179, 222, 105, 0.35); } .rainbow-7 { - background: rgba(252, 205, 229, 0.35) !important; + background: rgba(252, 205, 229, 0.35); } .rainbow-8 { - background: rgba(217, 217, 217, 0.35) !important; + background: rgba(217, 217, 217, 0.35); } .rainbow-9 { - background: rgba(188, 128, 189, 0.35) !important; + background: rgba(188, 128, 189, 0.35); } .rainbow-10 { - background: rgba(204, 234, 197, 0.35) !important; + background: rgba(204, 234, 197, 0.35); } .rainbow-11 { - background: rgba(255, 237, 111, 0.35) !important; + background: rgba(255, 237, 111, 0.35); } /* rainbow2 is 12 Paired */ .rainbow2-0 { - background: rgba(166, 206, 227, 0.35) !important; + background: rgba(166, 206, 227, 0.35); } .rainbow2-1 { - background: rgba(31, 120, 180, 0.35) !important; + background: rgba(31, 120, 180, 0.35); } .rainbow2-2 { - background: rgba(178, 223, 138, 0.35) !important; + background: rgba(178, 223, 138, 0.35); } .rainbow2-3 { - background: rgba(51, 160, 44, 0.35) !important; + background: rgba(51, 160, 44, 0.35); } .rainbow2-4 { - background: rgba(251, 154, 153, 0.35) !important; + background: rgba(251, 154, 153, 0.35); } .rainbow2-5 { - background: rgba(227, 26, 28, 0.35) !important; + background: rgba(227, 26, 28, 0.35); } .rainbow2-6 { - background: rgba(253, 191, 111, 0.35) !important; + background: rgba(253, 191, 111, 0.35); } .rainbow2-7 { - background: rgba(255, 127, 0, 0.35) !important; + background: rgba(255, 127, 0, 0.35); } .rainbow2-8 { - background: rgba(202, 178, 214, 0.35) !important; + background: rgba(202, 178, 214, 0.35); } .rainbow2-9 { - background: rgba(106, 61, 154, 0.35) !important; + background: rgba(106, 61, 154, 0.35); } .rainbow2-10 { - background: rgba(255, 255, 153, 0.35) !important; + background: rgba(255, 255, 153, 0.35); } .rainbow2-11 { - background: rgba(177, 89, 40, 0.35) !important; + background: rgba(177, 89, 40, 0.35); } /* earth is 'BrBG' */ .earth-0 { - background: rgba(140, 81, 10, 0.35) !important; + background: rgba(140, 81, 10, 0.35); } .earth-1 { - background: rgba(191, 129, 45, 0.35) !important; + background: rgba(191, 129, 45, 0.35); } .earth-2 { - background: rgba(223, 194, 125, 0.35) !important; + background: rgba(223, 194, 125, 0.35); } .earth-3 { - background: rgba(246, 232, 195, 0.35) !important; + background: rgba(246, 232, 195, 0.35); } .earth-4 { - background: rgba(245, 245, 245, 0.35) !important; + background: rgba(245, 245, 245, 0.35); } .earth-5 { - background: rgba(199, 234, 229, 0.35) !important; + background: rgba(199, 234, 229, 0.35); } .earth-6 { - background: rgba(128, 205, 193, 0.35) !important; + background: rgba(128, 205, 193, 0.35); } .earth-7 { - background: rgba(53, 151, 143, 0.35) !important; + background: rgba(53, 151, 143, 0.35); } .earth-8 { - background: rgba(1, 102, 94, 0.35) !important; + background: rgba(1, 102, 94, 0.35); } /* Greens and blues is Paired */ .green-blue-0 { - background: rgba(166, 206, 227, 0.35) !important; + background: rgba(166, 206, 227, 0.35); } .green-blue-1 { - background: rgba(31, 120, 180, 0.35) !important; + background: rgba(31, 120, 180, 0.35); } .green-blue-2 { - background: rgba(178, 223, 138, 0.35) !important; + background: rgba(178, 223, 138, 0.35); } .green-blue-3 { - background: rgba(51, 160, 44, 0.35) !important; + background: rgba(51, 160, 44, 0.35); } /* Gray shades */ .gray-shade-0 { - background: rgba(190, 190, 190, 0.35) !important; + background: rgba(190, 190, 190, 0.15); } .gray-shade-1 { - background: rgba(150, 150, 150, 0.35) !important; + background: rgba(150, 150, 150, 0.15); } .gray-shade-2 { - background: rgba(110, 110, 110, 0.35) !important; + background: rgba(110, 110, 110, 0.15); } .gray-shade-3 { - background: rgba(70, 70, 70, 0.35) !important; + background: rgba(70, 70, 70, 0.15); } diff --git a/static/explorer.css b/static/explorer.css index 71f88b8f9..002b6181a 100644 --- a/static/explorer.css +++ b/static/explorer.css @@ -225,7 +225,7 @@ pre.content.wrap { left: 3px; } -.linked-code-decoration-inline { +.linked-code-decoration-column { font-weight: 600; } diff --git a/static/panes/compiler.js b/static/panes/compiler.js index 492e9d073..35e1f2f8f 100644 --- a/static/panes/compiler.js +++ b/static/panes/compiler.js @@ -165,10 +165,6 @@ function Compiler(hub, container, state) { }); } -Compiler.prototype.clearEditorsLinkedLines = function () { - this.eventHub.emit('editorSetDecoration', this.sourceEditorId, -1, false); -}; - Compiler.prototype.getGroupsInUse = function () { return _.chain(this.getCurrentLangCompilers()) .map() @@ -365,12 +361,9 @@ Compiler.prototype.initEditorActions = function () { run: _.bind(function (ed) { var desiredLine = ed.getPosition().lineNumber - 1; var source = this.assembly[desiredLine].source; - if (source.file === null) { + if (source !== null && source.file === null) { // a null file means it was the user's source - this.eventHub.emit('editorSetDecoration', this.sourceEditorId, source.line, true); - } else { - // TODO: some indication this asm statement came from elsewhere - this.eventHub.emit('editorSetDecoration', this.sourceEditorId, -1, false); + this.eventHub.emit('editorLinkLine', this.sourceEditorId, source.line, -1, true); } }, this) }); @@ -1120,6 +1113,7 @@ Compiler.prototype.initListeners = function () { this.eventHub.on('resendCompilation', this.onResendCompilation, this); this.eventHub.on('findCompilers', this.sendCompiler, this); this.eventHub.on('compilerSetDecorations', this.onCompilerSetDecorations, this); + this.eventHub.on('panesLinkLine', this.onPanesLinkLine, this); this.eventHub.on('settingsChange', this.onSettingsChange, this); this.eventHub.on('requestCompilation', this.onRequestCompilation, this); @@ -1169,26 +1163,9 @@ Compiler.prototype.initCallbacks = function () { .on('change', optionsChange) .on('keyup', optionsChange); - this.mouseMoveThrottledFunction = _.throttle(_.bind(this.onMouseMove, this), 250); + this.mouseMoveThrottledFunction = _.throttle(_.bind(this.onMouseMove, this), 50); this.outputEditor.onMouseMove(_.bind(function (e) { this.mouseMoveThrottledFunction(e); - if (this.linkedFadeTimeoutId !== -1) { - clearTimeout(this.linkedFadeTimeoutId); - this.linkedFadeTimeoutId = -1; - } - }, this)); - - this.outputEditor.onMouseLeave(_.bind(function () { - this.linkedFadeTimeoutId = setTimeout(_.bind(function () { - this.clearEditorsLinkedLines(); - this.linkedFadeTimeoutId = -1; - }, this), 5000); - }, this)); - - this.outputEditor.onMouseUp(_.bind(function () { - if (this.getEffectiveFilters().binary) { - this.setBinaryMargin(); - } }, this)); this.outputEditor.onContextMenu(_.bind(function () { @@ -1317,11 +1294,22 @@ Compiler.prototype.getCompilerName = function () { return this.compiler ? this.compiler.name : 'No compiler set'; }; + +Compiler.prototype.getLanguageName = function () { + var lang = options.languages[this.currentLangId]; + return lang ? lang.name : '?'; +}; + +Compiler.prototype.getPaneName = function () { + var langName = this.getLanguageName(); + var compName = this.getCompilerName(); + return compName + ' (Editor #' + this.sourceEditorId + ', Compiler #' + this.id + ') ' + langName; +}; + Compiler.prototype.updateCompilerName = function () { - var name = options.languages[this.currentLangId].name; var compilerName = this.getCompilerName(); var compilerVersion = this.compiler ? this.compiler.version : ''; - this.container.setTitle(compilerName + ' (Editor #' + this.sourceEditorId + ', Compiler #' + this.id + ') ' + name); + this.container.setTitle(this.getPaneName()); this.shortCompilerName.text(compilerName); this.setCompilerVersionPopover(compilerVersion); }; @@ -1345,6 +1333,42 @@ Compiler.prototype.updateDecorations = function () { this.prevDecorations, _.flatten(_.values(this.decorations))); }; +Compiler.prototype.clearLinkedLines = function () { + this.decorations.linkedCode = []; + this.updateDecorations(); +}; + +Compiler.prototype.onPanesLinkLine = function (compilerId, lineNumber, revealLine, sender) { + if (Number(compilerId) === this.id) { + var lineNums = []; + _.each(this.assembly, function (asmLine, i) { + if (asmLine.source && asmLine.source.file === null && asmLine.source.line === lineNumber) { + lineNums.push(i + 1); + } + }); + if (revealLine && lineNums[0]) this.outputEditor.revealLineInCenter(lineNums[0]); + var lineClass = sender !== this.getPaneName() ? 'linked-code-decoration-line' : ''; + this.decorations.linkedCode = _.map(lineNums, function (line) { + return { + range: new monaco.Range(line, 1, line, 1), + options: { + isWholeLine: true, + linesDecorationsClassName: 'linked-code-decoration-margin', + className: lineClass + } + }; + }); + if (this.linkedFadeTimeoutId !== -1) { + clearTimeout(this.linkedFadeTimeoutId); + } + this.linkedFadeTimeoutId = setTimeout(_.bind(function () { + this.clearLinkedLines(); + this.linkedFadeTimeoutId = -1; + }, this), 5000); + this.updateDecorations(); + } +}; + Compiler.prototype.onCompilerSetDecorations = function (id, lineNums, revealLine) { if (Number(id) === this.id) { if (revealLine && lineNums[0]) this.outputEditor.revealLineInCenter(lineNums[0]); @@ -1457,11 +1481,13 @@ function getAsmInfo(opcode) { Compiler.prototype.onMouseMove = function (e) { if (e === null || e.target === null || e.target.position === null) return; if (this.settings.hoverShowSource === true && this.assembly) { + this.clearLinkedLines(); var hoverAsm = this.assembly[e.target.position.lineNumber - 1]; if (hoverAsm) { // We check that we actually have something to show at this point! - this.eventHub.emit('editorSetDecoration', this.sourceEditorId, hoverAsm.source && !hoverAsm.source.file ? - hoverAsm.source.line : -1, false); + var sourceLine = hoverAsm.source && !hoverAsm.source.file ? hoverAsm.source.line : -1; + this.eventHub.emit('editorLinkLine', this.sourceEditorId, sourceLine, -1, false); + this.eventHub.emit('panesLinkLine', this.id, sourceLine, false, this.getPaneName()); } } var currentWord = this.outputEditor.getModel().getWordAtPosition(e.target.position); diff --git a/static/panes/editor.js b/static/panes/editor.js index e7f922be8..0a8f57cef 100644 --- a/static/panes/editor.js +++ b/static/panes/editor.js @@ -240,6 +240,7 @@ Editor.prototype.initCallbacks = function () { this.eventHub.on('compileResult', this.onCompileResponse, this); this.eventHub.on('selectLine', this.onSelectLine, this); this.eventHub.on('editorSetDecoration', this.onEditorSetDecoration, this); + this.eventHub.on('editorLinkLine', this.onEditorLinkLine, this); this.eventHub.on('settingsChange', this.onSettingsChange, this); this.eventHub.on('conformanceViewOpen', this.onConformanceViewOpen, this); this.eventHub.on('conformanceViewClose', this.onConformanceViewClose, this); @@ -251,31 +252,21 @@ Editor.prototype.initCallbacks = function () { this.updateState(); }, this)); - this.editor.onMouseLeave(_.bind(function () { - this.fadeTimeoutId = setTimeout(_.bind(function () { - this.clearCompilerLinkedLines(); - this.fadeTimeoutId = -1; - }, this), 5000); - }, this)); - - this.mouseMoveThrottledFunction = _.throttle(_.bind(function (e) { - if (e !== null && e.target !== null && this.settings.hoverShowSource && e.target.position !== null) { - this.tryCompilerLinkLine(e.target.position.lineNumber, false); - } - }, this), 250); + this.mouseMoveThrottledFunction = _.throttle(_.bind(this.onMouseMove, this), 50); this.editor.onMouseMove(_.bind(function (e) { this.mouseMoveThrottledFunction(e); - // This can't be throttled or we can clear a timeout where we're already outside - if (this.fadeTimeoutId !== -1) { - clearTimeout(this.fadeTimeoutId); - this.fadeTimeoutId = -1; - } }, this)); this.eventHub.on('initialised', this.maybeEmitChange, this); }; +Editor.prototype.onMouseMove = function (e) { + if (e !== null && e.target !== null && this.settings.hoverShowSource && e.target.position !== null) { + this.tryPanesLinkLine(e.target.position.lineNumber, false); + } +}; + Editor.prototype.initButtons = function (state) { this.fontScale = new FontScale(this.domRoot, state, this.editor); this.languageBtn = this.domRoot.find('.change-language'); @@ -378,21 +369,14 @@ Editor.prototype.changeLanguage = function (newLang) { this.selectize.setValue(newLang); }; -Editor.prototype.clearCompilerLinkedLines = function () { - _.each(this.asmByCompiler, _.bind(function (asms, compilerId) { - this.eventHub.emit('compilerSetDecorations', compilerId, -1, false); - }, this)); +Editor.prototype.clearLinkedLine = function () { + this.decorations.linkedCode = []; + this.updateDecorations(); }; -Editor.prototype.tryCompilerLinkLine = function (thisLineNumber, reveal) { +Editor.prototype.tryPanesLinkLine = function (thisLineNumber, reveal) { _.each(this.asmByCompiler, _.bind(function (asms, compilerId) { - var targetLines = []; - _.each(asms, function (asmLine, i) { - if (asmLine.source && asmLine.source.file === null && asmLine.source.line === thisLineNumber) { - targetLines.push(i + 1); - } - }); - this.eventHub.emit('compilerSetDecorations', compilerId, targetLines, reveal); + this.eventHub.emit('panesLinkLine', compilerId, thisLineNumber, reveal); }, this)); }; @@ -457,13 +441,13 @@ Editor.prototype.initEditorActions = function () { this.editor.addAction({ id: 'viewasm', - label: 'Scroll to assembly', + label: 'Reveal linked code', keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10], keybindingContext: null, contextMenuGroupId: 'navigation', contextMenuOrder: 1.5, run: _.bind(function (ed) { - this.tryCompilerLinkLine(ed.getPosition().lineNumber, true); + this.tryPanesLinkLine(ed.getPosition().lineNumber, true); }, this) }); }; @@ -714,10 +698,43 @@ Editor.prototype.onSelectLine = function (id, lineNum) { } }; +Editor.prototype.onEditorLinkLine = function (editorId, lineNum, columnNum, reveal) { + if (Number(editorId) === this.id) { + if (reveal && lineNum) this.editor.revealLineInCenter(lineNum); + this.decorations.linkedCode = lineNum === -1 || !lineNum ? [] : [{ + range: new monaco.Range(lineNum, 1, lineNum, 1), + options: { + isWholeLine: true, + linesDecorationsClassName: 'linked-code-decoration-margin', + className: 'linked-code-decoration-line' + } + }]; + + if (lineNum > 0 && columnNum !== -1) { + this.decorations.linkedCode.push({ + range: new monaco.Range(lineNum, columnNum, lineNum, columnNum + 1), + options: { + isWholeLine: false, + inlineClassName: 'linked-code-decoration-column' + } + }); + } + + if (this.fadeTimeoutId !== -1) { + clearTimeout(this.fadeTimeoutId); + } + this.fadeTimeoutId = setTimeout(_.bind(function () { + this.clearLinkedLine(); + this.fadeTimeoutId = -1; + }, this), 5000); + + this.updateDecorations(); + } +}; + Editor.prototype.onEditorSetDecoration = function (id, lineNum, reveal) { if (Number(id) === this.id) { - if (reveal && lineNum) - this.editor.revealLineInCenter(lineNum); + if (reveal && lineNum) this.editor.revealLineInCenter(lineNum); this.decorations.linkedCode = lineNum === -1 || !lineNum ? [] : [{ range: new monaco.Range(lineNum, 1, lineNum, 1), options: { @@ -790,8 +807,12 @@ Editor.prototype.onLanguageChange = function (newLangId) { } }; +Editor.prototype.getPaneName = function () { + return this.currentLanguage.name + " source #" + this.id; +}; + Editor.prototype.updateTitle = function () { - this.container.setTitle(this.currentLanguage.name + " source #" + this.id); + this.container.setTitle(this.getPaneName()); }; // Called every time we change language, so we get the relevant code diff --git a/static/panes/ir-view.js b/static/panes/ir-view.js index 001671243..766084e50 100644 --- a/static/panes/ir-view.js +++ b/static/panes/ir-view.js @@ -36,7 +36,10 @@ function Ir(hub, container, state) { this.eventHub = hub.createEventHub(); this.domRoot = container.getElement(); this.domRoot.html($('#ir').html()); - this._currentDecorations = []; + + this.decorations = {}; + this.prevDecorations = []; + this.irEditor = monaco.editor.create(this.domRoot.find(".monaco-placeholder")[0], { fontFamily: 'Consolas, "Liberation Mono", Courier, monospace', value: "", @@ -57,6 +60,8 @@ function Ir(hub, container, state) { this._compilerName = state.compilerName; this._editorid = state.editorid; + this.settings = {}; + this.colours = []; this.irCode = []; this.lastColours = []; @@ -64,6 +69,7 @@ function Ir(hub, container, state) { this.initButtons(state); this.initCallbacks(); + this.initEditorActions(); if (state && state.irOutput) { this.showIrResults(state.irOutput); @@ -77,6 +83,25 @@ function Ir(hub, container, state) { }); } +Ir.prototype.initEditorActions = function () { + this.irEditor.addAction({ + id: 'viewsource', + label: 'Scroll to source', + keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10], + keybindingContext: null, + contextMenuGroupId: 'navigation', + contextMenuOrder: 1.5, + run: _.bind(function (ed) { + var desiredLine = ed.getPosition().lineNumber - 1; + var source = this.irCode[desiredLine].source; + if (source !== null && source.file === null) { + // a null file means it was the user's source + this.eventHub.emit('editorLinkLine', this._editorid, source.line, -1, true); + } + }, this) + }); +}; + Ir.prototype.initButtons = function (state) { this.fontScale = new FontScale(this.domRoot, state, this.irEditor); @@ -84,6 +109,12 @@ Ir.prototype.initButtons = function (state) { }; Ir.prototype.initCallbacks = function () { + this.linkedFadeTimeoutId = -1; + this.mouseMoveThrottledFunction = _.throttle(_.bind(this.onMouseMove, this), 50); + this.irEditor.onMouseMove(_.bind(function (e) { + this.mouseMoveThrottledFunction(e); + }, this)); + this.fontScale.on('change', _.bind(this.updateState, this)); this.container.on('destroy', this.close, this); @@ -91,6 +122,7 @@ Ir.prototype.initCallbacks = function () { this.eventHub.on('compileResult', this.onCompileResponse, this); this.eventHub.on('compiler', this.onCompiler, this); this.eventHub.on('colours', this.onColours, this); + this.eventHub.on('panesLinkLine', this.onPanesLinkLine, this); this.eventHub.on('compilerClose', this.onCompilerClose, this); this.eventHub.on('settingsChange', this.onSettingsChange, this); this.eventHub.emit('irViewOpened', this._compilerid); @@ -113,9 +145,8 @@ Ir.prototype.onCompileResponse = function (id, compiler, result) { if (this._compilerid !== id) return; if (result.hasIrOutput) { this.showIrResults(result.irOutput); - } - else if (compiler.supportsIrView) { - this.showIrResults([{text:""}]); + } else if (compiler.supportsIrView) { + this.showIrResults([{text: ""}]); } // Why call this explicitly instead of just listening to the "colours" event? @@ -123,10 +154,12 @@ Ir.prototype.onCompileResponse = function (id, compiler, result) { this.onColours(this._compilerid, this.lastColours, this.lastColourScheme); }; +Ir.prototype.getPaneName = function () { + return this._compilerName + " IR Viewer (Editor #" + this._editorid + ", Compiler #" + this._compilerid + ")"; +}; + Ir.prototype.setTitle = function () { - this.container.setTitle( - this._compilerName + " IR Viewer (Editor #" + this._editorid + ", Compiler #" + this._compilerid + ")" - ); + this.container.setTitle(this.getPaneName()); }; Ir.prototype.showIrResults = function (irCode) { @@ -196,14 +229,72 @@ Ir.prototype.onCompilerClose = function (id) { }; Ir.prototype.onSettingsChange = function (newSettings) { + this.settings = newSettings; this.irEditor.updateOptions({ contextmenu: newSettings.useCustomContextMenu, minimap: { enabled: newSettings.showMinimap - } + }, + fontFamily: newSettings.editorsFFont }); }; +Ir.prototype.onMouseMove = function (e) { + if (e === null || e.target === null || e.target.position === null) return; + if (this.settings.hoverShowSource === true && this.irCode) { + this.clearLinkedLines(); + var hoverCode = this.irCode[e.target.position.lineNumber - 1]; + if (hoverCode) { + // We check that we actually have something to show at this point! + var sourceLine = hoverCode.source && !hoverCode.source.file ? hoverCode.source.line : -1; + this.eventHub.emit('editorLinkLine', this._editorid, sourceLine, -1, false); + this.eventHub.emit('panesLinkLine', this._compilerid, sourceLine, false, this.getPaneName()); + } + } +}; + +Ir.prototype.updateDecorations = function () { + this.prevDecorations = this.irEditor.deltaDecorations( + this.prevDecorations, _.flatten(_.values(this.decorations))); +}; + +Ir.prototype.clearLinkedLines = function () { + this.decorations.linkedCode = []; + this.updateDecorations(); +}; + +Ir.prototype.onPanesLinkLine = function (compilerId, lineNumber, revealLine, sender) { + if (Number(compilerId) === this._compilerid) { + var lineNums = []; + _.each(this.irCode, function (irLine, i) { + if (irLine.source && irLine.source.file === null && irLine.source.line === lineNumber) { + var line = i + 1; + lineNums.push(line); + } + }); + if (revealLine && lineNums[0]) this.irEditor.revealLineInCenter(lineNums[0]); + var lineClass = sender !== this.getPaneName() ? 'linked-code-decoration-line' : ''; + this.decorations.linkedCode = _.map(lineNums, function (line) { + return { + range: new monaco.Range(line, 1, line, 1), + options: { + isWholeLine: true, + linesDecorationsClassName: 'linked-code-decoration-margin', + className: lineClass + } + }; + }); + if (this.linkedFadeTimeoutId !== -1) { + clearTimeout(this.linkedFadeTimeoutId); + } + this.linkedFadeTimeoutId = setTimeout(_.bind(function () { + this.clearLinkedLines(); + this.linkedFadeTimeoutId = -1; + }, this), 5000); + this.updateDecorations(); + } +}; + Ir.prototype.close = function () { this.eventHub.unsubscribe(); this.eventHub.emit("irViewClosed", this._compilerid); diff --git a/static/panes/output.js b/static/panes/output.js index a0eaf71f9..039a614e6 100644 --- a/static/panes/output.js +++ b/static/panes/output.js @@ -121,7 +121,9 @@ Output.prototype.onCompileResult = function (id, compiler, result) { this.contentRoot.empty(); _.each((result.stdout || []).concat(result.stderr || []), function (obj) { - this.add(this.normalAnsiToHtml.toHtml(obj.text), obj.tag ? obj.tag.line : obj.line); + var lineNumber = obj.tag ? obj.tag.line : obj.line; + var columnNumber = obj.tag ? obj.tag.column : -1; + this.add(this.normalAnsiToHtml.toHtml(obj.text), lineNumber, columnNumber); }, this); this.add("Compiler returned: " + result.code); @@ -151,7 +153,7 @@ Output.prototype.programOutput = function (msg, color) { elem.css("color", color); }; -Output.prototype.add = function (msg, lineNum) { +Output.prototype.add = function (msg, lineNum, column) { var elem = $('

').appendTo(this.contentRoot); if (lineNum) { elem.html( @@ -159,14 +161,14 @@ Output.prototype.add = function (msg, lineNum) { .prop('href', 'javascript:;') .html(msg) .click(_.bind(function (e) { - this.eventHub.emit('editorSetDecoration', this.editorId, lineNum, true); + this.eventHub.emit('editorLinkLine', this.editorId, lineNum, column, true); // do not bring user to the top of index.html // http://stackoverflow.com/questions/3252730 e.preventDefault(); return false; }, this)) .on('mouseover', _.bind(function () { - this.eventHub.emit('editorSetDecoration', this.editorId, lineNum, false); + this.eventHub.emit('editorLinkLine', this.editorId, lineNum, column, false); }, this)) ); } else { diff --git a/static/settings.js b/static/settings.js index 3c964267d..485997d4b 100644 --- a/static/settings.js +++ b/static/settings.js @@ -143,7 +143,13 @@ function setupSettings(root, settings, onChange, langId) { add(root.find('.hoverShowSource'), 'hoverShowSource', true, Checkbox); add(root.find('.hoverShowAsmDoc'), 'hoverShowAsmDoc', true, Checkbox); var themeSelect = root.find('.theme'); - add(themeSelect, 'theme', themes.default.id, Select, + + var defaultThemeId = themes.default.id; + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + defaultThemeId = themes.dark.id; + } + + add(themeSelect, 'theme', defaultThemeId, Select, _.map(themes, function (theme) { return {label: theme.id, desc: theme.name}; }) diff --git a/static/themes/dark-theme.css b/static/themes/dark-theme.css index ca36dd9ee..a843b6a4f 100644 --- a/static/themes/dark-theme.css +++ b/static/themes/dark-theme.css @@ -79,6 +79,14 @@ a.navbar-brand img.logo.normal { background-color: #333 !important; } +.linked-code-decoration-line { + background: rgb(40, 80, 116) !important; +} + +.linked-code-decoration-inline { + background: #121212 !important; +} + .linked-code-decoration-margin { background: #433b4b !important; } @@ -98,6 +106,7 @@ a.navbar-brand img.logo.normal { .selectize-control.single .selectize-input { color: #f2f2f2 !important; background: #666 linear-gradient(to bottom, #555, #222) !important; + text-shadow: none !important; } .selectize-dropdown { @@ -301,8 +310,9 @@ input { } .community-advert { - background: #a1a1a1 !important; - border-color: #006400 + color: white; + background: #474747 !important; + border-color: #006400; } .community-advert button { diff --git a/static/themes/default-theme.css b/static/themes/default-theme.css index 658996b10..f43547145 100644 --- a/static/themes/default-theme.css +++ b/static/themes/default-theme.css @@ -73,6 +73,14 @@ a.navbar-brand img.logo.normal { background: lightblue; } +.linked-code-decoration-inline { + background: lightblue; +} + +.linked-code-decoration-line { + background: lightblue !important; +} + .font-option { background: white; } diff --git a/test/exec-tests.js b/test/exec-tests.js index 0133382c3..3dfb3417f 100644 --- a/test/exec-tests.js +++ b/test/exec-tests.js @@ -22,26 +22,36 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -var chai = require('chai'), +const chai = require('chai'), chaiAsPromised = require("chai-as-promised"), exec = require('../lib/exec'); chai.use(chaiAsPromised); chai.should(); +function testExecOutput(x) { + // Work around chai not being able to deepEquals with a function + x.filenameTransform.should.be.a('function'); + delete x.filenameTransform; + return x; +} + if (process.platform !== 'win32') { // POSIX describe('Executes external commands', () => { it('supports output', () => { - return exec.execute('echo', ['hello', 'world'], {}).should.eventually.deep.equals( - { - code: 0, - okToCache: true, - stderr: "", - stdout: "hello world\n" - }); + return exec.execute('echo', ['hello', 'world'], {}) + .then(testExecOutput) + .should.eventually.deep.equals( + { + code: 0, + okToCache: true, + stderr: "", + stdout: "hello world\n" + }); }); it('limits output', () => { return exec.execute('echo', ['A very very very very very long string'], {maxOutput: 10}) + .then(testExecOutput) .should.eventually.deep.equals( { code: 0, @@ -52,6 +62,7 @@ if (process.platform !== 'win32') { // POSIX }); it('handles failing commands', () => { return exec.execute('false', [], {}) + .then(testExecOutput) .should.eventually.deep.equals( { code: 1, @@ -62,6 +73,7 @@ if (process.platform !== 'win32') { // POSIX }); it('handles timouts', () => { return exec.execute('sleep', ['5'], {timeoutMs: 10}) + .then(testExecOutput) .should.eventually.deep.equals( { code: -1, @@ -75,7 +87,9 @@ if (process.platform !== 'win32') { // POSIX .should.be.rejectedWith("ENOENT"); }); it('handles input', () => { - return exec.execute('cat', [], {input: "this is stdin"}).should.eventually.deep.equals( + return exec.execute('cat', [], {input: "this is stdin"}) + .then(testExecOutput) + .should.eventually.deep.equals( { code: 0, okToCache: true, @@ -88,7 +102,9 @@ if (process.platform !== 'win32') { // POSIX describe('Executes external commands', () => { // note: we use powershell, since echo is a builtin, and false doesn't exist it('supports output', () => { - return exec.execute('powershell', ['-Command', 'echo "hello world"'], {}).should.eventually.deep.equals( + return exec.execute('powershell', ['-Command', 'echo "hello world"'], {}) + .then(testExecOutput) + .should.eventually.deep.equals( { code: 0, okToCache: true, @@ -98,6 +114,7 @@ if (process.platform !== 'win32') { // POSIX }); it('limits output', () => { return exec.execute('powershell', ['-Command', 'echo "A very very very very very long string"'], {maxOutput: 10}) + .then(testExecOutput) .should.eventually.deep.equals( { code: 0, @@ -108,6 +125,7 @@ if (process.platform !== 'win32') { // POSIX }); it('handles failing commands', () => { return exec.execute('powershell', ['-Command', 'function Fail { exit 1 }; Fail'], {}) + .then(testExecOutput) .should.eventually.deep.equals( { code: 1, @@ -118,6 +136,7 @@ if (process.platform !== 'win32') { // POSIX }); it('handles timouts', () => { return exec.execute('powershell', ['-Command', '"sleep 5"'], {timeoutMs: 10}) + .then(testExecOutput) .should.eventually.deep.equals( { code: 1,