Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Code Cleanup #452

Merged
merged 1 commit into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
frameworks/javascript/angular/
frameworks/java
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ services:
entrypoint: ''
command: bash

chapel-runner:
image: codewars/chapel-runner
volumes:
- ./lib:/runner/lib
- ./examples:/runner/examples
- ./frameworks:/runner/frameworks
- ./test:/runner/test
entrypoint: ''
command: bash

# LANGUAGE SPECIFIC HELPERS
javascript:
image: codewars/node-runner
Expand Down
2 changes: 1 addition & 1 deletion docker/alt.docker
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ RUN mocha -t 3000 test/runners/php_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/chapel.docker
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ WORKDIR /runner
USER codewarrior

RUN mocha -t 10000 test/runners/chapel_spec.js
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 2 additions & 0 deletions docker/crystal.docker
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ ADD frameworks/crystal/formatter.cr /home/codewarrior/crystal/formatter.cr
USER codewarrior

RUN mocha -t 10000 test/runners/crystal_spec.js

ENTRYPOINT ["node"]
2 changes: 2 additions & 0 deletions docker/dart.docker
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ RUN ln -s /home/codewarrior /workspace
USER codewarrior

RUN mocha -t 10000 test/runners/dart_spec.js

ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/dotnet.docker
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ RUN mono -V

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/erlang.docker
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ RUN mocha -t 5000 test/runners/{erlang,elixir}_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/esolangs.docker
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ RUN mocha -t 10000 test/runners/bf_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/func.docker
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ RUN mocha -t 5000 test/runners/{ocaml,racket}_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/go.docker
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ RUN mocha -t 5000 test/runners/go_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "17", "node"]
ENTRYPOINT ["node"]
6 changes: 3 additions & 3 deletions docker/haskell.docker
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN cabal update
RUN cabal install cabal-install

# Install Haskell Packages
# To install additional packages use "RUN cabal install <pkg-name>"
# To install additional packages use "RUN cabal install <pkg-name>"
RUN cabal install split ifelse
RUN cabal install persistent-sqlite persistent-template
RUN cabal install haskell-src-exts lens
Expand All @@ -38,7 +38,7 @@ RUN cabal install hspec hspec-core hspec-discover
# Haskell stuff end.
# =========================================================================

# Add the package json first to a tmp directory and build,
# Add the package json first to a tmp directory and build,
# copy over so that we dont rebuild every time
USER root
ADD package.json /tmp/package.json
Expand All @@ -55,4 +55,4 @@ RUN mocha -t 10000 test/runners/haskell_spec.js

# timeout is a fallback in case an error with node
# prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/julia.docker
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ RUN mocha -t 5000 test/runners/julia_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/jvm.docker
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ RUN mocha -t 10000 test/runners/{clojure,groovy,scala,kotlin}_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/lua.docker
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ RUN mocha -t 5000 test/runners/lua_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/node.docker
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ RUN mocha -t 10000 test/runners/typescript_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/objc.docker
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ RUN mocha -t 5000 test/runners/objc_spec.js

# timeout is a fallback in case an error with node
# prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/ocaml.docker
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ RUN /home/codewarrior/run_ocaml.sh mocha -t 5000 test/runners/ocaml_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["/home/codewarrior/run_ocaml.sh", "timeout", "15", "node"]
ENTRYPOINT ["/home/codewarrior/run_ocaml.sh", "node"]
2 changes: 1 addition & 1 deletion docker/python.docker
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ RUN mocha -t 5000 test/runners/python_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
4 changes: 2 additions & 2 deletions docker/ruby.docker
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ ENV USER codewarrior
ENV HOME /home/codewarrior

RUN mocha -t 5000 test/runners/ruby_spec.js
#RUN mocha -t 5000 test/runners/sql_spec.js
RUN mocha -t 5000 test/runners/shell_spec.js
#RUN mocha -t 5000 test/runners/sql_spec.js
RUN sh /runner/lib/cleanup.sh

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 2 additions & 0 deletions docker/rust.docker
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ RUN ln -s /home/codewarrior /workspace
USER codewarrior

RUN mocha -t 10000 test/runners/rust_spec.js

ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/swift.docker
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ RUN mocha -t 5000 test/runners/swift_spec.js

# timeout is a fallback in case an error with node
# prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
2 changes: 1 addition & 1 deletion docker/systems.docker
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ RUN mocha -t 5000 test/runners/{c,cpp}_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
ENTRYPOINT ["node"]
24 changes: 12 additions & 12 deletions frameworks/javascript/cw-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,18 @@ try {
// additional code is injected and line numbers will not match.
trace: function(ex) {
return (ex.stack || ex.toString() || '')
.toString()
// remove file names (ie: (/cli-runner/...))
.replace(/\s\(.*\)/g, '')
// remove at [eval] statements
.replace(/(at)*( Object.)*\s*[(]?\[eval\].*(:\d*)*[)]?\n/g, '')
// remove stack trace beyond the Module information
.replace(/at Module[\w\s.:\d\n]*/g, '')
// remove at Object.<anonymous>
.replace(/\t*at Object.<\w*>\n/g, '')
// handleError is used to wrap top level code, so lets remove it so that it doesn't
// confuse users who won't understand why it is there.
.replace('at Object.Test.handleError', '');
.toString()
// remove file names (ie: (/cli-runner/...))
.replace(/\s\(.*\)/g, '')
// remove at [eval] statements
.replace(/(at)*( Object.)*\s*[(]?\[eval\].*(:\d*)*[)]?\n/g, '')
// remove stack trace beyond the Module information
.replace(/at Module[\w\s.:\d\n]*/g, '')
// remove at Object.<anonymous>
.replace(/\t*at Object.<\w*>\n/g, '')
// handleError is used to wrap top level code, so lets remove it so that it doesn't
// confuse users who won't understand why it is there.
.replace('at Object.Test.handleError', '');
},
pass: function() {
_expect(true);
Expand Down
10 changes: 5 additions & 5 deletions frameworks/javascript/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ module.exports.format = function format(obj, options) {
*/
module.exports.escapeHtml = function escapeHtml(html) {
return String(html)
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/runners/arm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports.run = function run(opts, cb) {
solutionFile = util.codeWriteSync('arm', opts.solution + '\n', dir, 'solution.s'),
objectFile = solutionFile.replace(/\.[^\.]+$/, '.o'),
armCommand = ['arm-linux-gnueabi-as', solutionFile, '-o', objectFile].join(' '),
// Check for whether we need to link against libc
// Check for whether we need to link against libc
linker = opts.solution.search(/\.glob[a]?l\W+_start/) == -1 ? "arm-linux-gnueabi-gcc-4.7" : "arm-linux-gnueabi-ld",
linkerCommand = [linker, objectFile, '-o', executable].join(' ');
util.exec(armCommand, function() {
Expand Down
15 changes: 8 additions & 7 deletions lib/runners/c.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ module.exports.run = function run(opts, cb) {
},
sanitizeStdErr: function(error) {
error = error || '';
return error.replace(/clang.*-std=c[^\s]+/g, '')
.replace(/Error: Command failed:/g, '')
.replace(/\/tmp.*(solution\.c|solution)[:0-9]*/g, '')
.replace('\n', '')
.replace(' ', ' ')
.replace(opts.setup || '', '')
.replace(opts.fixture || '', '');
return error
.replace(/clang.*-std=c[^\s]+/g, '')
.replace(/Error: Command failed:/g, '')
.replace(/\/tmp.*(solution\.c|solution)[:0-9]*/g, '')
.replace('\n', '')
.replace(' ', ' ')
.replace(opts.setup || '', '')
.replace(opts.fixture || '', '');
}
});
};
Expand Down
14 changes: 9 additions & 5 deletions lib/runners/chapel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports.run = function run(opts, cb) {
if (opts.setup) handleSetup(opts, dir);
const executable = path.join(dir, 'solution');
const solutionFile = util.codeWriteSync('chpl', opts.solution, dir, 'solution.chpl');

compile([solutionFile, '-o', executable], function(error, stdout, stderr) {
if (error) return fail(error, stdout, stderr);
opts.publish('stdout', stdout);
Expand All @@ -30,20 +31,23 @@ module.exports.run = function run(opts, cb) {
opts.solution,
opts.fixture,
].join('\n'), dir, 'solution.chpl');

compile([solutionFile, '-o', executable], function(error, stdout, stderr) {
if (error) return fail(error, stdout, stderr);
opts.publish('stdout', stdout);

runCode({name: executable, args: []});
});
},

sanitizeStdErr: function(error) {
error = error || '';
return error.replace(/\/tmp.*(solution\.chpl|solution)[:0-9]*/g, '')
.replace(/Error: Command failed:/g, '')
.replace(/error: uncaught error/g, '')
.replace('\n', '')
.replace(' ', ' ');
return error
.replace(/\/tmp.*(solution\.chpl|solution)[:0-9]*/g, '')
.replace(/Error: Command failed:/g, '')
.replace(/error: uncaught error/g, '')
.replace('\n', '')
.replace(' ', ' ');
}
});
};
Expand Down
6 changes: 3 additions & 3 deletions lib/runners/clojure.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ module.exports.run = function run(opts, cb) {
// HACK: don't know clojure well enough to fix issue within actual runner, but it is escaping line breaks when it shouldn't
sanitizeStdOut: function(stdout) {
return stdout
.replace(/\<:LF:\>\<PASSED::\>/g, '\n<PASSED::>')
.replace(/\<:LF:\>\<FAILED::\>/g, '\n<FAILED::>')
.replace(/\<:LF:\>\<ERROR::\>/g, '\n<ERROR::>');
.replace(/\<:LF:\>\<PASSED::\>/g, '\n<PASSED::>')
.replace(/\<:LF:\>\<FAILED::\>/g, '\n<FAILED::>')
.replace(/\<:LF:\>\<ERROR::\>/g, '\n<ERROR::>');

}
});
Expand Down
15 changes: 8 additions & 7 deletions lib/runners/cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ module.exports.run = function run(opts, cb) {

sanitizeStdErr: function(error) {
error = error || '';
return error.replace(/clang.*-std=c[^\s]+/g, '')
.replace(/Error: Command failed:/g, '')
.replace(/\/tmp.*(solution\.cpp|solution)[:0-9]*/g, '')
.replace('\n', '')
.replace(' ', ' ')
.replace(opts.setup || '', '')
.replace(opts.fixture || '', '');
return error
.replace(/clang.*-std=c[^\s]+/g, '')
.replace(/Error: Command failed:/g, '')
.replace(/\/tmp.*(solution\.cpp|solution)[:0-9]*/g, '')
.replace('\n', '')
.replace(' ', ' ')
.replace(opts.setup || '', '')
.replace(opts.fixture || '', '');
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion lib/runners/fsharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var shovel = require('../shovel'),
csharpFrameworksPath = path.resolve(__dirname, '..', '..', 'frameworks', 'csharp'),
fuchuPath = path.resolve(fsharpFrameworksPath, 'Fuchu', 'lib', 'Fuchu'),

// Fuchu references exception classes from these libs
// Fuchu references exception classes from these libs
nunitAssemblies = ['nunit.core.dll', 'nunit.core.interfaces.dll', 'nunit.util.dll', 'nunit.framework.dll', 'Newtonsoft.Json.dll', 'Qualified.dll'],
nunitPath = path.resolve(csharpFrameworksPath, 'nunit', 'bin'),
gallioPath = path.resolve(fsharpFrameworksPath, 'Gallio', 'lib', 'NET40'),
Expand Down
2 changes: 1 addition & 1 deletion lib/runners/gas.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports.run = function(opts, cb) {
solutionFile = util.codeWriteSync('gas', opts.solution + '\n', dir, 'solution.s'),
objectFile = solutionFile.replace(/\.[^\.]+$/, '.o'),
gasCommand = ['gcc', '-c', solutionFile, '-o', objectFile].join(' '),
// Check for whether we need to link against libc
// Check for whether we need to link against libc
linker = opts.solution.search(/\.global\W+_start/) == -1 ? "gcc" : "ld",
linkerCommand = [linker, objectFile, '-o', executable].join(' ');
util.exec(gasCommand, function() {
Expand Down
5 changes: 3 additions & 2 deletions lib/runners/haskell.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ module.exports.run = function run(opts, cb) {
if (opts.setup) codeWriteSync('haskell', opts.setup, haskellCodeDir);
var solutionFileName = codeWriteSync('haskell', opts.solution, haskellCodeDir, "Main.hs"),
fixtureFileName = solutionFileName.split('/').pop() == "Main.hs" ?
codeWriteSync('haskell', opts.fixture, haskellCodeDir) :
codeWriteSync('haskell', opts.fixture, haskellCodeDir, "Main.hs");
codeWriteSync('haskell', opts.fixture, haskellCodeDir) :
codeWriteSync('haskell', opts.fixture, haskellCodeDir, "Main.hs");

process.env["solutionFileName"] = solutionFileName;

runCode({
Expand Down
13 changes: 7 additions & 6 deletions lib/runners/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ module.exports.run = function run(opts, cb) {
},
sanitizeStdErr: function(error) {
error = error || '';
return error.replace(/(\()?\/codewars\/[(\w\/-\d.js:) ;]*/g, '')
.replace(/( Object. )?[\(]?\[eval\][-:\w\d\)]* at/g, '')
.replace(/Module._compile.*/g, '')
.replace('Object.Test.handleError ', '')
.replace(opts.setup || '', '')
.replace(opts.fixture || '', '');
return error
.replace(/(\()?\/codewars\/[(\w\/-\d.js:) ;]*/g, '')
.replace(/( Object. )?[\(]?\[eval\][-:\w\d\)]* at/g, '')
.replace(/Module._compile.*/g, '')
.replace('Object.Test.handleError ', '')
.replace(opts.setup || '', '')
.replace(opts.fixture || '', '');
},
sanitizeStdOut: function(stdout) {
return this.sanitizeStdErr(stdout);
Expand Down
2 changes: 1 addition & 1 deletion lib/runners/lisp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports.run = function run(opts, cb) {
var lispCodeDir = temp.mkdirSync('lisp'),
args = [
'--noinform', // Disable banner
'--disable-ldb', // Disable the low-level debugger
'--disable-ldb', // Disable the low-level debugger
'--lose-on-corruption', // Don't try to recover
'--non-interactive' // No REPL
];
Expand Down
2 changes: 1 addition & 1 deletion lib/runners/nasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports.run = function run(opts, cb) {
solutionFile = util.codeWriteSync('nasm', opts.solution + '\n', dir, 'solution.asm'),
nasmCommand = ['nasm', '-felf64', solutionFile].join(' '),
objectFile = solutionFile.replace(/\.[^\.]+$/, '.o'),
// Check for whether we need to link against libc
// Check for whether we need to link against libc
linker = opts.solution.search(/global\W+_start/) == -1 ? "gcc" : "ld",
linkerCommand = [linker, objectFile, '-o', executable].join(' ');
util.exec(nasmCommand, function() {
Expand Down
Loading