| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0ba74db commit 3b0e800
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,11 +147,13 @@ exports.deprecate = internalUtil.deprecate; | |||
| 147 | 147 | var debugs = {}; | |
| 148 | 148 | var debugEnviron; | |
| 149 | 149 | exports.debuglog = function(set) { | |
| 150 | - if (debugEnviron === undefined) | ||
| 151 | - debugEnviron = process.env.NODE_DEBUG || ''; | ||
| 150 | + if (debugEnviron === undefined) { | ||
| 151 | + debugEnviron = new Set( | ||
| 152 | + (process.env.NODE_DEBUG || '').split(',').map((s) => s.toUpperCase())); | ||
| 153 | + } | ||
| 152 | 154 | set = set.toUpperCase(); | |
| 153 | 155 | if (!debugs[set]) { | |
| 154 | - if (new RegExp(`\\b${set}\\b`, 'i').test(debugEnviron)) { | ||
| 156 | + if (debugEnviron.has(set)) { | ||
| 155 | 157 | var pid = process.pid; | |
| 156 | 158 | debugs[set] = function() { | |
| 157 | 159 | var msg = exports.format.apply(exports, arguments); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,34 +23,42 @@ | |||
| 23 | 23 | const common = require('../common'); | |
| 24 | 24 | const assert = require('assert'); | |
| 25 | 25 | ||
| 26 | - if (process.argv[2] === 'child') | ||
| 27 | - child(); | ||
| 26 | + const [, , modeArgv, sectionArgv] = process.argv; | ||
| 27 | + | ||
| 28 | + if (modeArgv === 'child') | ||
| 29 | + child(sectionArgv); | ||
| 28 | 30 | else | |
| 29 | 31 | parent(); | |
| 30 | 32 | ||
| 31 | 33 | function parent() { | |
| 32 | - test('foo,tud,bar', true); | ||
| 33 | - test('foo,tud', true); | ||
| 34 | - test('tud,bar', true); | ||
| 35 | - test('tud', true); | ||
| 36 | - test('foo,bar', false); | ||
| 37 | - test('', false); | ||
| 34 | + test('foo,tud,bar', true, 'tud'); | ||
| 35 | + test('foo,tud', true, 'tud'); | ||
| 36 | + test('tud,bar', true, 'tud'); | ||
| 37 | + test('tud', true, 'tud'); | ||
| 38 | + test('foo,bar', false, 'tud'); | ||
| 39 | + test('', false, 'tud'); | ||
| 40 | + | ||
| 41 | + test('###', true, '###'); | ||
| 42 | + test('hi:)', true, 'hi:)'); | ||
| 43 | + test('f$oo', true, 'f$oo'); | ||
| 44 | + test('f$oo', false, 'f.oo'); | ||
| 45 | + test('no-bar-at-all', false, 'bar'); | ||
| 38 | 46 | } | |
| 39 | 47 | ||
| 40 | - function test(environ, shouldWrite) { | ||
| 48 | + function test(environ, shouldWrite, section) { | ||
| 41 | 49 | let expectErr = ''; | |
| 42 | - if (shouldWrite) { | ||
| 43 | - expectErr = 'TUD %PID%: this { is: \'a\' } /debugging/\n' + | ||
| 44 | - 'TUD %PID%: number=1234 string=asdf obj={"foo":"bar"}\n'; | ||
| 45 | - } | ||
| 46 | 50 | const expectOut = 'ok\n'; | |
| 47 | 51 | ||
| 48 | 52 | const spawn = require('child_process').spawn; | |
| 49 | - const child = spawn(process.execPath, [__filename, 'child'], { | ||
| 53 | + const child = spawn(process.execPath, [__filename, 'child', section], { | ||
| 50 | 54 | env: Object.assign(process.env, { NODE_DEBUG: environ }) | |
| 51 | 55 | }); | |
| 52 | 56 | ||
| 53 | - expectErr = expectErr.split('%PID%').join(child.pid); | ||
| 57 | + if (shouldWrite) { | ||
| 58 | + expectErr = | ||
| 59 | + `${section.toUpperCase()} ${child.pid}: this { is: 'a' } /debugging/\n${ | ||
| 60 | + section.toUpperCase()} ${child.pid}: num=1 str=a obj={"foo":"bar"}\n`; | ||
| 61 | + } | ||
| 54 | 62 | ||
| 55 | 63 | let err = ''; | |
| 56 | 64 | child.stderr.setEncoding('utf8'); | |
@@ -72,10 +80,10 @@ function test(environ, shouldWrite) { | |||
| 72 | 80 | } | |
| 73 | 81 | ||
| 74 | 82 | ||
| 75 | - function child() { | ||
| 83 | + function child(section) { | ||
| 76 | 84 | const util = require('util'); | |
| 77 | - const debug = util.debuglog('tud'); | ||
| 85 | + const debug = util.debuglog(section); | ||
| 78 | 86 | debug('this', { is: 'a' }, /debugging/); | |
| 79 | - debug('number=%d string=%s obj=%j', 1234, 'asdf', { foo: 'bar' }); | ||
| 87 | + debug('num=%d str=%s obj=%j', 1, 'a', { foo: 'bar' }); | ||
| 80 | 88 | console.log('ok'); | |
| 81 | 89 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments