diff --git a/jsdoc.js b/jsdoc.js index 798b25ef..bac8f91a 100644 --- a/jsdoc.js +++ b/jsdoc.js @@ -66,6 +66,28 @@ env = { opts: {} }; + +/** @global + @param {string} filepath The path to the script file to include (read and execute). +*/ +function include(filepath) { + try { + filepath = include.resolve(filepath); + load(filepath); + } + catch (e) { + console.log('Cannot include "' + __dirname + '/' + filepath + '": '+e); + } +} +include.resolve = function(filepath) { + if (filepath.indexOf('/') === 0) { + return filepath; + } + + return __dirname + '/' + filepath; +} + + /** Data that must be shared across the entire application. @namespace @@ -108,23 +130,6 @@ function dump() { } } -/** @global - @param {string} filepath The path to the script file to include (read and execute). -*/ -function include(filepath) { - try { - if (filepath.indexOf('/') === 0) { - load(filepath); - } - else { - load(__dirname + '/' + filepath); - } - } - catch (e) { - console.log('Cannot include "' + __dirname + '/' + filepath + '": '+e); - } -} - /** Cause the VM running jsdoc to exit running. @param {number} [n = 0] The exit status. diff --git a/test/specs/jsdoc/functions/include.js b/test/specs/jsdoc/functions/include.js new file mode 100644 index 00000000..dbfa1694 --- /dev/null +++ b/test/specs/jsdoc/functions/include.js @@ -0,0 +1,22 @@ + +describe("include", function() { + + it("should be a function", function() { + expect(include).toBeDefined(); + expect(typeof include).toEqual('function'); + }); + + it("should have a static method named resolve", function() { + expect(include.resolve).toBeDefined(); + expect(typeof include.resolve).toEqual('function'); + }); + + it("should resolve absolute filepaths to themselves", function() { + expect( include.resolve('/a/b/c.js') ).toEqual('/a/b/c.js'); + }); + + it("should resolve relative filepaths relative to the __dirname", function() { + expect( include.resolve('a/b/c') ).toEqual(__dirname+'/'+'a/b/c'); + }); + +}); \ No newline at end of file