Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Fix test-module-load-list
Browse files Browse the repository at this point in the history
and lazy load modules for process.stdout

This probably breaks test-module-load-list on windows, but it hopefully is
an easy fix to replace "_posix" bindings with "_win32".
  • Loading branch information
ry committed Sep 13, 2011
1 parent 0aad61e commit 0928f0f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 36 deletions.
22 changes: 13 additions & 9 deletions src/node.js
Expand Up @@ -219,27 +219,31 @@
if (stdout) return stdout;

var binding = process.binding('stdio'),
// FIXME Remove conditional when net is supported again on windows.
net = (process.platform !== "win32")
? NativeModule.require('net')
: undefined,
fs = NativeModule.require('fs'),
tty = NativeModule.require('tty'),
fd = binding.stdoutFD;

// Note stdout._type is used for test-module-load-list.js

if (binding.isatty(fd)) {
binding.unref();
var tty = NativeModule.require('tty');
stdout = new tty.WriteStream(fd);
stdout._type = "tty";
} else if (binding.isStdoutBlocking()) {
var fs = NativeModule.require('fs');
stdout = new fs.WriteStream(null, {fd: fd});
stdout._type = "fs";
} else {
binding.unref();

var net = NativeModule.require('net');
stdout = new net.Stream(fd);

// FIXME Should probably have an option in net.Stream to create a
// stream from an existing fd which is writable only. But for now
// we'll just add this hack and set the `readable` member to false.
// Test: ./node test/fixtures/echo.js < /etc/passwd
stdout.readable = false;
stdout._type = "pipe";
}

return stdout;
Expand All @@ -255,16 +259,16 @@
if (stdin) return stdin;

var binding = process.binding('stdio'),
net = NativeModule.require('net'),
fs = NativeModule.require('fs'),
tty = NativeModule.require('tty'),
fd = binding.openStdin();

if (binding.isatty(fd)) {
var tty = NativeModule.require('tty');
stdin = new tty.ReadStream(fd);
} else if (binding.isStdinBlocking()) {
var fs = NativeModule.require('fs');
stdin = new fs.ReadStream(null, {fd: fd});
} else {
var net = NativeModule.require('net');
stdin = new net.Stream(fd);
stdin.readable = true;
}
Expand Down
77 changes: 50 additions & 27 deletions test/simple/test-module-load-list.js
Expand Up @@ -28,9 +28,8 @@ function assertEqual(x, y) {
}

function checkExpected() {
assertEqual(expected.length, process.moduleLoadList.length);

for (var i = 0; i < expected.length; i++) {
var toCompare = Math.max(expected.length, process.moduleLoadList.length);
for (var i = 0; i < toCompare; i++) {
assertEqual(expected[i], process.moduleLoadList[i]);
}
}
Expand All @@ -56,8 +55,8 @@ checkExpected();


// Now do the test again after we console.log something.
console.log("load console.log");
console.error("load console.error");
console.log("load console.log. process.stdout._type is " +
process.stdout._type);

if (!process.features.uv) {
// legacy
Expand All @@ -75,31 +74,55 @@ if (!process.features.uv) {
'NativeModule readline'
]);
} else {
if (process.platform == 'win32') {
// win32
expected = expected.concat([
'NativeModule console',
'NativeModule tty',
'NativeModule tty_win32',
'NativeModule readline'
]);
} else {
// unix libuv backend.
expected = expected.concat([
'NativeModule console',
'NativeModule net_uv',
'NativeModule timers_uv',
'Binding timer_wrap',
'NativeModule _linklist',
'NativeModule tty',
'NativeModule tty_posix',
'Binding pipe_wrap',
'NativeModule readline'
]);
switch (process.stdout._type) {
case 'fs':
expected = expected.concat([
'NativeModule console',
'NativeModule readline',
'NativeModule tty',
'NativeModule tty_posix',
'NativeModule net_uv',
'NativeModule timers_uv',
'Binding timer_wrap',
'NativeModule _linklist',
]);
break;

case 'tty':
expected = expected.concat([
'NativeModule console',
'NativeModule tty',
'NativeModule tty_posix',
'NativeModule net_uv',
'NativeModule timers_uv',
'Binding timer_wrap',
'NativeModule _linklist',
'Binding pipe_wrap',
'NativeModule readline'
]);
break;

case 'pipe':
expected = expected.concat([
'NativeModule console',
'NativeModule net_uv',
'NativeModule timers_uv',
'Binding timer_wrap',
'NativeModule _linklist',
'Binding pipe_wrap',
'NativeModule readline',
'NativeModule tty',
'NativeModule tty_posix',
]);
break;

default:
assert.ok(0, "prcoess.stdout._type is bad");
}
}

console.error(process.moduleLoadList)
console.error("process.moduleLoadList", process.moduleLoadList)
console.error("expected", expected)

checkExpected();

0 comments on commit 0928f0f

Please sign in to comment.