From e42be1e8fe68d1be90f21b5bb5b51761f6a3c998 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 24 Feb 2016 17:07:45 -0800 Subject: [PATCH] doc,tools,test: lint doc-based addon tests PR-URL: https://github.com/nodejs/node/pull/5427 Fixes: https://github.com/nodejs/node/issues/5424 Reviewed-By: Roman Reiss Reviewed-By: Evan Lucas Reviewed-By: Myles Borins --- doc/api/addons.markdown | 22 +++++++++++----------- tools/doc/addon-verify.js | 6 ++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/doc/api/addons.markdown b/doc/api/addons.markdown index c9aea3915c..7f570eb706 100644 --- a/doc/api/addons.markdown +++ b/doc/api/addons.markdown @@ -317,7 +317,7 @@ Once compiled, the example Addon can be required and used from within Node.js: // test.js const addon = require('./build/Release/addon'); -console.log('This should be eight:', addon.add(3,5)); +console.log('This should be eight:', addon.add(3, 5)); ``` @@ -422,7 +422,7 @@ const addon = require('./build/Release/addon'); var obj1 = addon('hello'); var obj2 = addon('world'); -console.log(obj1.msg+' '+obj2.msg); // 'hello world' +console.log(obj1.msg + ' ' + obj2.msg); // 'hello world' ``` @@ -637,9 +637,9 @@ Test it with: const addon = require('./build/Release/addon'); var obj = new addon.MyObject(10); -console.log( obj.plusOne() ); // 11 -console.log( obj.plusOne() ); // 12 -console.log( obj.plusOne() ); // 13 +console.log(obj.plusOne()); // 11 +console.log(obj.plusOne()); // 12 +console.log(obj.plusOne()); // 13 ``` ### Factory of wrapped objects @@ -823,14 +823,14 @@ Test it with: const createObject = require('./build/Release/addon'); var obj = createObject(10); -console.log( obj.plusOne() ); // 11 -console.log( obj.plusOne() ); // 12 -console.log( obj.plusOne() ); // 13 +console.log(obj.plusOne()); // 11 +console.log(obj.plusOne()); // 12 +console.log(obj.plusOne()); // 13 var obj2 = createObject(20); -console.log( obj2.plusOne() ); // 21 -console.log( obj2.plusOne() ); // 22 -console.log( obj2.plusOne() ); // 23 +console.log(obj2.plusOne()); // 21 +console.log(obj2.plusOne()); // 22 +console.log(obj2.plusOne()); // 23 ``` diff --git a/tools/doc/addon-verify.js b/tools/doc/addon-verify.js index 792fd69eab..6aafb8f6fd 100644 --- a/tools/doc/addon-verify.js +++ b/tools/doc/addon-verify.js @@ -71,6 +71,12 @@ function verifyFiles(files, blockName, onprogress, ondone) { ); files = Object.keys(files).map(function(name) { + if (name === 'test.js') { + files[name] = `'use strict'; +require('../../common'); +${files[name]} +`; + } return { path: path.resolve(dir, name), name: name,