@@ -3,19 +3,19 @@ var deepEqual = require('deep-eql')
33var execute = require ( 'workshopper-exercise/execute' )
44var exerciser = require ( 'workshopper-exercise' )
55var filecheck = require ( 'workshopper-exercise/filecheck' )
6+ var fs = require ( 'fs' )
7+ var os = require ( 'os' )
68var path = require ( 'path' )
79
8- var verbose = true , showInput = true , compareDisplays = false , initFx , wrapUpFx , customFx
10+ var verbose = true , showInput = true , initFx , wrapUpFx , customFx , wrapperModulePath
911
1012function runner ( ) {
11- var exercise = filecheck ( exerciser ( ) )
13+ var exercise = execute ( filecheck ( exerciser ( ) ) )
1214 var input = Array . prototype . slice . call ( arguments )
13- if ( compareDisplays ) {
14- exercise = compareStdOut ( exercise )
15- }
15+ var submittedFx , __
1616
1717 exercise . addProcessor ( function ( mode , callback ) {
18- var submittedFx , __ = exercise . __ . bind ( exercise )
18+ __ = exercise . __ . bind ( exercise )
1919 try {
2020 submittedFx = require ( path . resolve ( process . cwd ( ) , this . args [ 0 ] ) ) ;
2121 } catch ( e ) {
@@ -31,6 +31,31 @@ function runner() {
3131 this . emit ( 'fail' , __ ( 'fail.must_export_function' ) )
3232 return callback ( null , false )
3333 }
34+
35+ callback ( null , true )
36+ } ) ;
37+
38+ if ( wrapperModulePath ) {
39+ exercise . addSetup ( function setupWrapperModule ( mode , callback ) {
40+ this . solutionCommand = [ wrapperModulePath , this . solution ] . concat ( this . solutionArgs )
41+ this . submissionCommand = [ wrapperModulePath , this . submission ] . concat ( this . submissionArgs )
42+
43+ if ( input . length > 0 ) {
44+ var file = path . join ( os . tmpdir ( ) , path . basename ( this . solution ) ) + '.input.json'
45+ fs . writeFileSync ( file , JSON . stringify ( input ) , { encoding : 'utf-8' } )
46+ exercise . addCleanup ( function ( mode , pass , callback ) {
47+ fs . unlink ( file , callback )
48+ } )
49+ this . solutionCommand . splice ( 2 , 0 , file )
50+ this . submissionCommand . splice ( 2 , 0 , file )
51+ }
52+ process . nextTick ( callback )
53+ } )
54+
55+ return compareStdOut ( exercise )
56+ }
57+
58+ exercise . addProcessor ( function ( mode , callback ) {
3459 if ( initFx ) { initFx ( ) ; }
3560 var submittedResult = obtainResult ( submittedFx , input )
3661 if ( verbose ) {
@@ -59,7 +84,7 @@ function runner() {
5984 exercise . addVerifyProcessor ( wrapUpFx )
6085 }
6186
62- return execute ( exercise )
87+ return exercise
6388}
6489
6590function obtainResult ( fx , input ) {
@@ -70,11 +95,6 @@ function obtainResult(fx, input) {
7095 return fx . apply ( null , input )
7196}
7297
73- runner . compareDisplay = function compareDisplay ( ) {
74- compareDisplays = true
75- return this . quiet . apply ( this , arguments )
76- }
77-
7898runner . custom = function custom ( fx ) {
7999 customFx = fx
80100 return runner
@@ -95,6 +115,12 @@ runner.quiet = function quiet() {
95115 return runner . apply ( null , arguments )
96116}
97117
118+ runner . wrapWith = function wrapWith ( modulePath ) {
119+ verbose = false
120+ wrapperModulePath = modulePath
121+ return runner . apply ( null , Array . prototype . slice . call ( arguments , 1 ) )
122+ }
123+
98124runner . wrapUp = function wrapUp ( fx ) {
99125 wrapUpFx = fx
100126 return runner
0 commit comments