// Copyright Joyent, Inc. and other Node contributors.1//2// Permission is hereby granted, free of charge, to any person obtaining a3// copy of this software and associated documentation files (the4// "Software"), to deal in the Software without restriction, including5// without limitation the rights to use, copy, modify, merge, publish,6// distribute, sublicense, and/or sell copies of the Software, and to permit7// persons to whom the Software is furnished to do so, subject to the8// following conditions:9//10// The above copyright notice and this permission notice shall be included11// in all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS14// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF15// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN16// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,17// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19// USE OR OTHER DEALINGS IN THE SOFTWARE.202122var assert = require('assert');23var util = require('../../');2425assert.ok(process.stdout.writable);26assert.ok(process.stderr.writable);2728var stdout_write = global.process.stdout.write;29var strings = [];30global.process.stdout.write = function(string) {31strings.push(string);32};33console._stderr = process.stdout;3435var tests = [36{input: 'foo', output: 'foo'},37{input: undefined, output: 'undefined'},38{input: null, output: 'null'},39{input: false, output: 'false'},40{input: 42, output: '42'},41{input: function(){}, output: '[Function]'},42{input: parseInt('not a number', 10), output: 'NaN'},43{input: {answer: 42}, output: '{ answer: 42 }'},44{input: [1,2,3], output: '[ 1, 2, 3 ]'}45];4647// test util.log()48tests.forEach(function(test) {49util.log(test.input);50var result = strings.shift().trim(),51re = (/[0-9]{1,2} [A-Z][a-z]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} - (.+)$/),52match = re.exec(result);53assert.ok(match);54assert.equal(match[1], test.output);55});5657global.process.stdout.write = stdout_write;585960