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

Commit 3081219

Browse files
authored
Merge pull request #409 from kazk/feature/lua-setup-code
[Lua] Add "Preloaded" code support
2 parents 05b3112 + b628a54 commit 3081219

File tree

4 files changed

+216
-148
lines changed

4 files changed

+216
-148
lines changed

docker/lua.docker

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ RUN mkdir -p /runner && cp -a /tmp/node_modules /runner
2424
COPY . /runner
2525
WORKDIR /runner
2626

27-
COPY frameworks/lua /home/codewarrior/lua
28-
RUN chown -R codewarrior:codewarrior /home/codewarrior/lua
29-
3027
USER codewarrior
3128
ENV USER=codewarrior HOME=/home/codewarrior
3229

frameworks/lua/codewars.lua

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@ return function(options)
66
end
77

88
local function onDescribeStart(element, parent)
9-
print('<DESCRIBE::>' .. element.name)
9+
print('\n<DESCRIBE::>' .. element.name)
1010
return nil, true
1111
end
1212
local function onDescribeEnd(element, parent)
13-
local s = '<COMPLETEDIN::>%.4f'
13+
local s = '\n<COMPLETEDIN::>%.4f'
1414
print(s:format(1000*element.duration))
1515
return nil, true
1616
end
1717

1818
local function onTestStart(element, parent)
19-
print('<IT::>' .. element.name)
19+
print('\n<IT::>' .. element.name)
2020
return nil, true
2121
end
2222
local function onTestEnd(element, parent, status, trace)
2323
if status == 'success' then
24-
print('<PASSED::>Test Passed')
24+
print('\n<PASSED::>Test Passed')
2525
end
26-
local s = '<COMPLETEDIN::>%.4f'
26+
local s = '\n<COMPLETEDIN::>%.4f'
2727
print(s:format(1000*element.duration))
2828
return nil, true
2929
end
3030

3131
local function onTestFailure(element, parent, message, debug)
32-
print('<FAILED::>Test Failed')
32+
print('\n<FAILED::>Test Failed')
3333
-- remove '/home/codewarrior/lua/fixture.lua:\d+: ' from message
34-
print('<LOG:ESC:>' .. escape(message:sub(message:find(' ') + 1)))
34+
print('\n<LOG:ESC:>' .. escape(message:sub(message:find(' ') + 1)))
3535
return nil, true
3636
end
3737

3838
local function onTestError(element, parent, message, debug)
39-
print('<ERROR::>Test Error')
40-
print('<LOG:ESC:Traceback>' .. escape(message))
39+
print('\n<ERROR::>Test Error')
40+
print('\n<LOG:ESC:Traceback>' .. escape(message))
4141
return nil, true
4242
end
4343

4444
local function onError(element, parent, message, debug)
4545
if element.descriptor ~= 'it' then
46-
print('<ERROR::>Error')
47-
print('<LOG:ESC:>' .. escape(message))
46+
print('\n<ERROR::>Error')
47+
print('\n<LOG:ESC:>' .. escape(message))
4848
end
4949
return nil, true
5050
end

lib/runners/lua.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
var shovel = require('../shovel'),
2-
writeFileSync = require('../util').writeFileSync;
1+
"use strict";
2+
3+
const shovel = require('../shovel');
4+
const writeFileSync = require('../util').writeFileSync;
35

46
module.exports.run = function run(opts, cb) {
5-
const dir = '/home/codewarrior/lua';
67
shovel.start(opts, cb, {
7-
solutionOnly: function(runCode) {
8+
solutionOnly(runCode) {
89
runCode({
910
name: 'lua',
10-
args: [writeFileSync(dir, 'solution.lua', opts.solution, true)]
11+
args: [writeFileSync(opts.dir, 'solution.lua', opts.solution, true)],
12+
options: {cwd: opts.dir}
1113
});
1214
},
13-
testIntegration: function(runCode) {
14-
writeFileSync(dir, 'solution.lua', opts.solution, true);
15+
16+
testIntegration(runCode) {
17+
writeFileSync(opts.dir, 'solution.lua', opts.solution, true);
18+
if (opts.setup) writeFileSync(opts.dir, 'setup.lua', opts.setup, true);
1519
runCode({
1620
name: 'busted',
1721
args: [
18-
writeFileSync(dir, 'fixture.lua', opts.fixture, true),
19-
`--output=codewars.lua`,
22+
writeFileSync(opts.dir, 'fixture.lua', opts.fixture, true),
23+
'--output=/runner/frameworks/lua/codewars.lua'
2024
],
21-
options: {cwd: dir}
25+
options: {cwd: opts.dir}
2226
});
2327
}
2428
});

0 commit comments

Comments
 (0)