-
Notifications
You must be signed in to change notification settings - Fork 43
/
exercise.js
48 lines (34 loc) · 1.53 KB
/
exercise.js
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
var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var wrappedexec = require('workshopper-wrappedexec');
// the output will be long lines so make the comparison take that into account
exercise.longCompareOutput = true;
// checks that the submission file actually exists
exercise = filecheck(exercise);
// execute the solution and submission in parallel with spawn()
exercise = execute(exercise);
exercise = comparestdout(exercise)
exercise = wrappedexec(exercise);
exercise.wrapModule(require.resolve('./wrap'))
function rndport() {
return 1024 + Math.floor(Math.random() * 64511);
}
// set up the data file to be passed to the submission
exercise.addSetup(function (mode, callback) {
this.submissionPort = rndport();
this.solutionPort = this.submissionPort + 1;
this.submissionArgs.unshift(this.submissionPort);
this.solutionArgs.unshift(this.solutionPort);
this.submissionCommand = [ '--harmony', this.submission ].concat(this.submissionArgs);
this.solutionCommand = [ '--harmony', this.solution ].concat(this.solutionArgs);
process.nextTick(callback);
});
// check generators using
exercise.addVerifyProcessor(function (callback) {
var usedGenerators = exercise.wrapData.usedGenerators;
!usedGenerators && this.emit('fail', exercise.__('fail.didnt_use_generators'));
callback(null, usedGenerators);
})
module.exports = exercise;