From 3727ae0d7dc940ee3b2bc238fc80cd3605954715 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Thu, 24 Dec 2015 13:56:03 +1100 Subject: [PATCH] test: use addon.md block headings as test dir names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit instead of doc-* PR-URL: https://github.com/nodejs/node/pull/4412 Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Johan Bergström --- .eslintignore | 2 +- .gitignore | 2 +- Makefile | 6 +++--- tools/doc/addon-verify.js | 34 ++++++++++++++++++++-------------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.eslintignore b/.eslintignore index e1376c84099aa2..1b91ccd4690648 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,7 +1,7 @@ lib/internal/v8_prof_polyfill.js lib/internal/v8_prof_processor.js lib/punycode.js -test/addons/doc-*/ +test/addons/??_*/ test/fixtures test/**/node_modules test/disabled diff --git a/.gitignore b/.gitignore index a0cfe00f32e230..f9a106d8f566e1 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,7 @@ ipch/ /npm.wxs /tools/msvs/npm.wixobj /tools/osx-pkg.pmdoc/index.xml -/test/addons/doc-*/ +/test/addons/??_*/ email.md deps/v8-* deps/icu diff --git a/Makefile b/Makefile index 02f4363ab35832..c337f006fb6f63 100644 --- a/Makefile +++ b/Makefile @@ -105,12 +105,12 @@ test/gc/node_modules/weak/build/Release/weakref.node: $(NODE_EXE) # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale. test/addons/.docbuildstamp: doc/api/addons.markdown - $(RM) -r test/addons/doc-*/ + $(RM) -r test/addons/??_*/ $(NODE) tools/doc/addon-verify.js touch $@ ADDONS_BINDING_GYPS := \ - $(filter-out test/addons/doc-*/binding.gyp, \ + $(filter-out test/addons/??_*/binding.gyp, \ $(wildcard test/addons/*/binding.gyp)) # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale. @@ -520,7 +520,7 @@ CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc CPPLINT_EXCLUDE += src/queue.h CPPLINT_EXCLUDE += src/tree.h CPPLINT_EXCLUDE += src/v8abbr.h -CPPLINT_EXCLUDE += $(wildcard test/addons/doc-*/*.cc test/addons/doc-*/*.h) +CPPLINT_EXCLUDE += $(wildcard test/addons/??_*/*.cc test/addons/??_*/*.h) CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \ deps/debugger-agent/include/* \ diff --git a/tools/doc/addon-verify.js b/tools/doc/addon-verify.js index cc80a7bd32906f..68c46f06bc3472 100644 --- a/tools/doc/addon-verify.js +++ b/tools/doc/addon-verify.js @@ -1,31 +1,36 @@ -var fs = require('fs'); -var path = require('path'); -var marked = require('marked'); +'use strict'; -var doc = path.resolve(__dirname, '..', '..', 'doc', 'api', 'addons.markdown'); -var verifyDir = path.resolve(__dirname, '..', '..', 'test', 'addons'); +const fs = require('fs'); +const path = require('path'); +const marked = require('marked'); -var contents = fs.readFileSync(doc).toString(); +const doc = path.resolve(__dirname, '..', '..', 'doc', 'api', 'addons.markdown'); +const verifyDir = path.resolve(__dirname, '..', '..', 'test', 'addons'); -var tokens = marked.lexer(contents, {}); -var files = null; -var id = 0; +const contents = fs.readFileSync(doc).toString(); + +let tokens = marked.lexer(contents, {}); +let files = null; +let blockName; +let id = 0; // Just to make sure that all examples will be processed tokens.push({ type: 'heading' }); var oldDirs = fs.readdirSync(verifyDir); oldDirs = oldDirs.filter(function(dir) { - return /^doc-/.test(dir); + return /^\d{2}_/.test(dir); }).map(function(dir) { return path.resolve(verifyDir, dir); }); for (var i = 0; i < tokens.length; i++) { var token = tokens[i]; - if (token.type === 'heading') { + if (token.type === 'heading' && token.text) { + blockName = token.text if (files && Object.keys(files).length !== 0) { verifyFiles(files, + blockName, console.log.bind(null, 'wrote'), function(err) { if (err) throw err; }); } @@ -48,15 +53,16 @@ function once(fn) { }; } -function verifyFiles(files, onprogress, ondone) { - var dir = path.resolve(verifyDir, 'doc-' + id++); - +function verifyFiles(files, blockName, onprogress, ondone) { // must have a .cc and a .js to be a valid test if (!Object.keys(files).some((name) => /\.cc$/.test(name)) || !Object.keys(files).some((name) => /\.js$/.test(name))) { return; } + blockName = blockName.toLowerCase().replace(/\s/g, '_').replace(/[^a-z\d_]/g, '') + let dir = path.resolve(verifyDir, `${(++id < 10 ? '0' : '') + id}_${blockName}`); + files = Object.keys(files).map(function(name) { return { path: path.resolve(dir, name),