repl,util: insert carriage returns in output by JungMinu · Pull Request #8028 · nodejs/node · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions lib/repl.js
10 changes: 5 additions & 5 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,9 @@ function reduceToSingleString(output, base, braces, breakLength) {
// If the opening "brace" is too large, like in the case of "Set {",
// we need to force the first item to be on the next line or the
// items will not line up correctly.
(base === '' && braces[0].length === 1 ? '' : base + '\n ') +
(base === '' && braces[0].length === 1 ? '' : base + '\r\n ') +
' ' +
output.join(',\n ') +
output.join(',\r\n ') +
' ' +
braces[1];
}
Expand Down Expand Up @@ -1001,19 +1001,19 @@ exports.print = internalUtil.deprecate(function() {

exports.puts = internalUtil.deprecate(function() {
for (var i = 0, len = arguments.length; i < len; ++i) {
process.stdout.write(arguments[i] + '\n');
process.stdout.write(arguments[i] + '\r\n');
}
}, 'util.puts is deprecated. Use console.log instead.');


exports.debug = internalUtil.deprecate(function(x) {
process.stderr.write('DEBUG: ' + x + '\n');
process.stderr.write('DEBUG: ' + x + '\r\n');
}, 'util.debug is deprecated. Use console.error instead.');


exports.error = internalUtil.deprecate(function(x) {
for (var i = 0, len = arguments.length; i < len; ++i) {
process.stderr.write(arguments[i] + '\n');
process.stderr.write(arguments[i] + '\r\n');
}
}, 'util.error is deprecated. Use console.error instead.');

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const interactive = childProcess.exec(nodeBinary + ' '
+ '-i',
common.mustCall(function(err, stdout, stderr) {
assert.ifError(err);
assert.strictEqual(stdout, `> 'test'\n> `);
assert.strictEqual(stdout, `> 'test'\r\n> `);
}));

interactive.stdin.write('a\n');
Expand Down
9 changes: 5 additions & 4 deletions test/parallel/test-repl-.save.load.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ putIn.run(testFile);
putIn.run(['.save ' + saveFileName]);

// the file should have what I wrote
assert.equal(fs.readFileSync(saveFileName, 'utf8'), testFile.join('\n') + '\n');
assert.equal(fs.readFileSync(saveFileName, 'utf8'), testFile.join('\r\n')
+ '\r\n');

// make sure that the REPL data is "correct"
// so when I load it back I know I'm good
Expand All @@ -54,7 +55,7 @@ var loadFile = join(common.tmpDir, 'file.does.not.exist');
// should not break
putIn.write = function(data) {
// make sure I get a failed to load message and not some crazy error
assert.equal(data, 'Failed to load:' + loadFile + '\n');
assert.equal(data, 'Failed to load:' + loadFile + '\r\n');
// eat me to avoid work
putIn.write = function() {};
};
Expand All @@ -63,7 +64,7 @@ putIn.run(['.load ' + loadFile]);
// throw error on loading directory
loadFile = common.tmpDir;
putIn.write = function(data) {
assert.equal(data, 'Failed to load:' + loadFile + ' is not a valid file\n');
assert.equal(data, 'Failed to load:' + loadFile + ' is not a valid file\r\n');
putIn.write = function() {};
};
putIn.run(['.load ' + loadFile]);
Expand All @@ -78,7 +79,7 @@ const invalidFileName = join(common.tmpDir, '\0\0\0\0\0');
// should not break
putIn.write = function(data) {
// make sure I get a failed to save message and not some other error
assert.equal(data, 'Failed to save:' + invalidFileName + '\n');
assert.equal(data, 'Failed to save:' + invalidFileName + '\r\n');
// reset to no-op
putIn.write = function() {};
};
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-repl-autolibs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function test1() {
if (data.length) {

// inspect output matches repl output
assert.equal(data, util.inspect(require('fs'), null, 2, false) + '\n');
assert.equal(data, util.inspect(require('fs'), null, 2, false) + '\r\n');
// globally added lib matches required lib
assert.equal(global.fs, require('fs'));
test2();
Expand All @@ -36,7 +36,7 @@ function test2() {
gotWrite = true;
if (data.length) {
// repl response error message
assert.equal(data, '{}\n');
assert.equal(data, '{}\r\n');
// original value wasn't overwritten
assert.equal(val, global.url);
}
Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-repl-definecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ r.defineCommand('say2', function() {
this.displayPrompt();
});

inputStream.write('.help\n');
assert(/\nsay1\thelp for say1\n/.test(output), 'help for say1 not present');
assert(/\nsay2\t\n/.test(output), 'help for say2 not present');
inputStream.write('.say1 node developer\n');
inputStream.write('.help\r\n');
assert(/\r\nsay1\thelp for say1\r\n/.test(output), 'help for say1 not present');
assert(/\r\nsay2\t\r\n/.test(output), 'help for say2 not present');
inputStream.write('.say1 node developer\r\n');
assert(/> hello node developer/.test(output), 'say1 outputted incorrectly');
inputStream.write('.say2 node developer\n');
inputStream.write('.say2 node developer\r\n');
assert(/> hello from say2/.test(output), 'say2 outputted incorrectly');
22 changes: 11 additions & 11 deletions test/parallel/test-repl-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,45 @@ function testSloppyMode() {

cli.input.emit('data', `
x = 3
`.trim() + '\n');
assert.equal(cli.output.accumulator.join(''), '> 3\n> ');
`.trim() + '\r\n');
assert.equal(cli.output.accumulator.join(''), '> 3\r\n> ');
cli.output.accumulator.length = 0;

cli.input.emit('data', `
let y = 3
`.trim() + '\n');
assert.equal(cli.output.accumulator.join(''), 'undefined\n> ');
`.trim() + '\r\n');
assert.equal(cli.output.accumulator.join(''), 'undefined\r\n> ');
}

function testStrictMode() {
var cli = initRepl(repl.REPL_MODE_STRICT);

cli.input.emit('data', `
x = 3
`.trim() + '\n');
`.trim() + '\r\n');
assert.ok(/ReferenceError: x is not defined/.test(
cli.output.accumulator.join('')));
cli.output.accumulator.length = 0;

cli.input.emit('data', `
let y = 3
`.trim() + '\n');
assert.equal(cli.output.accumulator.join(''), 'undefined\n> ');
`.trim() + '\r\n');
assert.equal(cli.output.accumulator.join(''), 'undefined\r\n> ');
}

function testAutoMode() {
var cli = initRepl(repl.REPL_MODE_MAGIC);

cli.input.emit('data', `
x = 3
`.trim() + '\n');
assert.equal(cli.output.accumulator.join(''), '> 3\n> ');
`.trim() + '\r\n');
assert.equal(cli.output.accumulator.join(''), '> 3\r\n> ');
cli.output.accumulator.length = 0;

cli.input.emit('data', `
let y = 3
`.trim() + '\n');
assert.equal(cli.output.accumulator.join(''), 'undefined\n> ');
`.trim() + '\r\n');
assert.equal(cli.output.accumulator.join(''), 'undefined\r\n> ');
}

function initRepl(mode) {
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-repl-persistent-history.js
Loading