From 577e132f00676616a97c48a0553854a5f35c07c8 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Thu, 5 May 2016 01:03:25 +0200 Subject: [PATCH] test: fix test-debugger-pid The current format that prints the process PID before the actual message. Adapt the test so it also passes on Windows, that emits a different message from the rest of platforms. Move the test to parallel. PR-URL: https://github.com/nodejs/node/pull/6584 Reviewed-By: Ben Noordhuis Reviewed-By: Rich Trott --- test/debugger/test-debugger-pid.js | 32 ------------------ test/parallel/test-debugger-pid.js | 54 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 32 deletions(-) delete mode 100644 test/debugger/test-debugger-pid.js create mode 100644 test/parallel/test-debugger-pid.js diff --git a/test/debugger/test-debugger-pid.js b/test/debugger/test-debugger-pid.js deleted file mode 100644 index 6a977d7cfa72e8..00000000000000 --- a/test/debugger/test-debugger-pid.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict'; -require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; - -var buffer = ''; - -// connect to debug agent -var interfacer = spawn(process.execPath, ['debug', '-p', '655555']); - -console.error(process.execPath, 'debug', '-p', '655555'); -interfacer.stdout.setEncoding('utf-8'); -interfacer.stderr.setEncoding('utf-8'); -var onData = function(data) { - data = (buffer + data).split('\n'); - buffer = data.pop(); - data.forEach(function(line) { - interfacer.emit('line', line); - }); -}; -interfacer.stdout.on('data', onData); -interfacer.stderr.on('data', onData); - -interfacer.on('line', function(line) { - line = line.replace(/^(debug> *)+/, ''); - var expected = 'Target process: 655555 doesn\'t exist.'; - assert.ok(expected == line, 'Got unexpected line: ' + line); -}); - -interfacer.on('exit', function(code, signal) { - assert.ok(code == 1, 'Got unexpected code: ' + code); -}); diff --git a/test/parallel/test-debugger-pid.js b/test/parallel/test-debugger-pid.js new file mode 100644 index 00000000000000..b36978414eb0f3 --- /dev/null +++ b/test/parallel/test-debugger-pid.js @@ -0,0 +1,54 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const spawn = require('child_process').spawn; + +var buffer = ''; + +// connect to debug agent +var interfacer = spawn(process.execPath, ['debug', '-p', '655555']); + +console.error(process.execPath, 'debug', '-p', '655555'); +interfacer.stdout.setEncoding('utf-8'); +interfacer.stderr.setEncoding('utf-8'); +var onData = function(data) { + data = (buffer + data).split('\n'); + buffer = data.pop(); + data.forEach(function(line) { + interfacer.emit('line', line); + }); +}; +interfacer.stdout.on('data', onData); +interfacer.stderr.on('data', onData); + +var lineCount = 0; +interfacer.on('line', function(line) { + var expected; + const pid = interfacer.pid; + if (common.isWindows) { + switch (++lineCount) { + case 1: + line = line.replace(/^(debug> *)+/, ''); + var msg = 'There was an internal error in Node\'s debugger. ' + + 'Please report this bug.'; + expected = `(node:${pid}) ${msg}`; + break; + + case 2: + expected = 'The parameter is incorrect.'; + break; + + default: + return; + } + } else { + line = line.replace(/^(debug> *)+/, ''); + expected = `(node:${pid}) Target process: 655555 doesn\'t exist.`; + } + + assert.strictEqual(expected, line); +}); + +interfacer.on('exit', function(code, signal) { + assert.ok(code == 1, 'Got unexpected code: ' + code); +});