diff --git a/src/core/resume-factory.js b/src/core/resume-factory.js index 0710bb9..b5ca938 100644 --- a/src/core/resume-factory.js +++ b/src/core/resume-factory.js @@ -67,7 +67,7 @@ Definition of the ResumeFactory class. // Load and parse the resume JSON var info = _parse( src, opts, emitter ); - if( info.error ) return info; + if( info.fluenterror ) return info; // Determine the resume format: FRESH or JRS var json = info.json; @@ -123,6 +123,8 @@ Definition of the ResumeFactory class. inner: e, raw: rawData, file: fileName, shouldExit: false }; eve && eve.err( ex.fluenterror, ex ); + if( opts.throw ) throw ex; + return ex; } } diff --git a/src/verbs/analyze.js b/src/verbs/analyze.js index d637643..8566999 100644 --- a/src/verbs/analyze.js +++ b/src/verbs/analyze.js @@ -40,13 +40,16 @@ Implementation of the 'analyze' verb for HackMyResume. function analyze( sources, dst, opts ) { this.stat('begin'); if( !sources || !sources.length ) throw { fluenterror: 3 }; + var nlzrs = _loadInspectors(); + _.each(sources, function(src) { var result = ResumeFactory.loadOne( src, { - format: 'FRESH', objectify: true, throw: false - }); - result.error || _analyze.call(this, result, nlzrs, opts ); + format: 'FRESH', objectify: true + }, this); + result.fluenterror || _analyze.call(this, result, nlzrs, opts ); }, this); + this.stat('end'); } diff --git a/src/verbs/build.js b/src/verbs/build.js index c7aee50..c7df84d 100644 --- a/src/verbs/build.js +++ b/src/verbs/build.js @@ -67,7 +67,7 @@ Implementation of the 'build' verb for HackMyResume. // Load the theme...we do this first because the theme choice (FRESH or // JSON Resume) determines what format we'll convert the resume to. this.stat( HME.beforeTheme, { theme: _opts.theme }); - var tFolder = verifyTheme( _opts.theme ); + var tFolder = verifyTheme.call( this, _opts.theme ); var theme = loadTheme( tFolder ); this.stat( HME.afterTheme, { theme: theme }); diff --git a/src/verbs/validate.js b/src/verbs/validate.js index 4e22531..0408a6f 100644 --- a/src/verbs/validate.js +++ b/src/verbs/validate.js @@ -57,8 +57,8 @@ Implementation of the 'validate' verb for HackMyResume. var ret = { file: src, isValid: false }; // If there was an error reading the resume - if( src.error ) { - if( opts.assert ) throw { fluenterror: HACKMYSTATUS.invalid }; + if( src.fluenterror ) { + if( opts.assert ) throw src; return ret; } diff --git a/test/test-cli.js b/test/test-cli.js new file mode 100644 index 0000000..8d13228 --- /dev/null +++ b/test/test-cli.js @@ -0,0 +1,76 @@ +/** +CLI test routines for HackMyResume. +@module test-cli.js +*/ + + + +var chai = require('chai') + , should = chai.should() + , HMRMAIN = require('../src/cli/main') + , CHALK = require('chalk') + , FS = require('fs') + , PATH = require('path') + , PKG = require('../package.json') + , _ = require('underscore'); + + + +var gather = ''; +var ConsoleLogOrg = console.log; +var ProcessExitOrg = process.exit; +var commandRetVal = 0; + + +describe('Testing Ouput interface', function () { + + // TODO: use sinon + // Replacement for process.exit() + function MyProcessExit( retVal ) { + commandRetVal = retVal; + } + + // HackMyResume CLI stub. Handle a single HMR invocation. + function HackMyResumeStub( argsString ) { + + var args = argsString.split(' '); + args.unshift( process.argv[1] ); + args.unshift( process.argv[0] ); + process.exit = MyProcessExit; + + try { + var HMRMAIN = require('../src/cli/main'); + HMRMAIN( args ); + } + catch( ex ) { + require('../src/cli/error').err( ex, false ); + //if(ex.stack || (ex.inner && ex.inner.stacl)) + //console.log(ex.stack || ex.inner.stack); + } + process.exit = ProcessExitOrg; + + } + + // Run a test through the stub, gathering console.log output into "gather" + // and testing against it. + function run( args, expErr ) { + var title = args; + it( 'Testing: "' + title + '"\n\n', function() { + commandRetVal = 0; + HackMyResumeStub( args ); + commandRetVal.should.equal( parseInt(expErr, 10) ); + }); + } + + var lines = FS.readFileSync( PATH.join( __dirname, './test-hmr.txt'), 'utf8').split('\n'); + lines.forEach(function(l){ + if( l && l.trim() ) { + if(l[0] !== '#') { + var lineInfo = l.split('|'); + var errCode = lineInfo[0]; + run( lineInfo.length > 1 ? lineInfo[1] : '', errCode ); + } + } + }); + +}); diff --git a/test/test-hmr.txt b/test/test-hmr.txt new file mode 100644 index 0000000..c380b1c --- /dev/null +++ b/test/test-hmr.txt @@ -0,0 +1,20 @@ +0| +3|build +8|new +3|analyze +3|convert +3|validate +5|notacommand +4|--help +4|-h +4|--debug +4|-d +14|build doesnt-exist.json +14|analyze doesnt-exist.json +7|convert doesnt-exist.json +14|validate doesnt-exist.json +1|build doesnt-exist.json -t not-a-theme +1|build doesnt-exist.json -t node_modules/not-a-theme +0|new test/sandbox/cli-test/new-empty-resume.auto.json +0|new test/sandbox/cli-test/new-empty-resume.jrs.json -f jrs +0|new test/sandbox/cli-test/new-empty-resume.fresh.json -f fresh diff --git a/test/test-stdout.js b/test/test-stdout.js index e383697..b95cd71 100644 --- a/test/test-stdout.js +++ b/test/test-stdout.js @@ -1,3 +1,10 @@ +/** +Output test routines for HackMyResume. +@module test-stdout.js +*/ + + + var chai = require('chai') , expect = chai.expect , HMRMAIN = require('../src/cli/main') @@ -7,23 +14,29 @@ var chai = require('chai') , PKG = require('../package.json') , _ = require('underscore'); + + var gather = ''; var ConsoleLogOrg = console.log; var ProcessExitOrg = process.exit; + + describe('Testing Ouput interface', function () { - - + // TODO: use sinon + // Replacement for console.log function MyConsoleLog( msg ) { gather += Array.prototype.slice.call(arguments).join(' '); ConsoleLogOrg.apply(this, arguments); } + // Replacement for process.exit() function MyProcessExit() { } + // HackMyResume CLI stub. Handle a single HMR invocation. function HackMyResumeStub( args ) { console.log = MyConsoleLog; @@ -45,6 +58,8 @@ describe('Testing Ouput interface', function () { } + // Run a test through the stub, gathering console.log output into "gather" + // and testing against it. function run( title, args, tests ) { it( title, function() { @@ -78,7 +93,8 @@ describe('Testing Ouput interface', function () { run('BUILD should display an error on a broken resume', ['build', - 'node_modules/fresh-test-resumes/src/johnny-trouble.broken.fresh.json' + 'node_modules/fresh-test-resumes/src/johnny-trouble.broken.fresh.json', + '-t', 'modern' ], [ title, 'Error: Invalid or corrupt JSON on line' ]); run('CONVERT should output a tip when no source is specified',