Merge pull request #141 from hegemonic/strict-fix

--strict option doesn't work correctly
This commit is contained in:
Michael Mathews 2012-07-05 12:42:46 -07:00
commit 110644f3e2
3 changed files with 16 additions and 19 deletions

View File

@ -12,8 +12,7 @@ var common = {
var argParser = new common.args.ArgParser(), var argParser = new common.args.ArgParser(),
ourOptions, ourOptions,
defaults = { defaults = {
destination: './out/', destination: './out/'
strict: true
}; };
argParser.addOption('t', 'template', true, 'The name of the template to use. Default: the "default" template'); argParser.addOption('t', 'template', true, 'The name of the template to use. Default: the "default" template');
@ -23,7 +22,7 @@ argParser.addOption('T', 'test', false, 'Run all tests and quit.');
argParser.addOption('d', 'destination', true, 'The path to the output folder. Use "console" to dump data to the console. Default: console'); argParser.addOption('d', 'destination', true, 'The path to the output folder. Use "console" to dump data to the console. Default: console');
argParser.addOption('p', 'private', false, 'Display symbols marked with the @private tag. Default: false.'); argParser.addOption('p', 'private', false, 'Display symbols marked with the @private tag. Default: false.');
argParser.addOption('r', 'recurse', false, 'Recurse into subdirectories when scanning for source code files.'); argParser.addOption('r', 'recurse', false, 'Recurse into subdirectories when scanning for source code files.');
argParser.addOption('s', 'strict', false, 'Exit immediately if a doclet is incomplete or contains errors. Default: true'); argParser.addOption('l', 'lenient', false, 'Continue to generate output if a doclet is incomplete or contains errors. Default: false.');
argParser.addOption('h', 'help', false, 'Print this message and quit.'); argParser.addOption('h', 'help', false, 'Print this message and quit.');
argParser.addOption('X', 'explain', false, 'Dump all found doclet internals to console and quit.'); argParser.addOption('X', 'explain', false, 'Dump all found doclet internals to console and quit.');
argParser.addOption('q', 'query', true, 'Provide a querystring to define custom variable names/values to add to the options hash.'); argParser.addOption('q', 'query', true, 'Provide a querystring to define custom variable names/values to add to the options hash.');

View File

@ -86,15 +86,15 @@ exports.Tag = function(tagTitle, tagBody, meta) {
} }
} }
// validate the tag. for strict validation, throw an exception; otherwise, log a warning. // validate the tag. in lenient mode, log a warning; otherwise, throw an exception.
try { try {
jsdoc.tag.validator.validate(this, meta); jsdoc.tag.validator.validate(this, meta);
} }
catch (e) { catch (e) {
if (env.opts.strict) { if (env.opts.lenient) {
throw e;
} else {
console.log(e); console.log(e);
} else {
throw e;
} }
} }
} }

View File

@ -8,31 +8,29 @@ describe("jsdoc/tag", function() {
return tag; return tag;
} }
it("has strict validation enabled by default", function() { it("is strict, not lenient, by default", function() {
expect(badTag).toThrow(); expect(badTag).toThrow();
}); });
it("throws an exception for bad tags if strict validation is enabled", function() { it("throws an exception for bad tags if the lenient option is not enabled", function() {
var strict = !!env.opts.strict; var lenient = !!env.opts.lenient;
env.opts.strict = true;
env.opts.lenient = false;
expect(badTag).toThrow(); expect(badTag).toThrow();
env.opts.strict = strict; env.opts.lenient = lenient;
}); });
it("doesn't throw an exception for bad tags if strict validation is disabled", function() { it("doesn't throw an exception for bad tags if the lenient option is enabled", function() {
/*jshint evil: true */ /*jshint evil: true */
var strict = !!env.opts.strict, var lenient = !!env.opts.lenient,
log = new Function(console.log); log = eval(console.log);
console.log = function() {}; console.log = function() {};
env.opts.strict = false;
env.opts.lenient = true;
expect(badTag).not.toThrow(); expect(badTag).not.toThrow();
env.opts.strict = strict; env.opts.lenient = lenient;
console.log = log; console.log = log;
}); });
}); });