From: Ryan Dahl Date: Tue, 13 Sep 2011 01:10:42 +0000 (-0700) Subject: Fix test-module-load-list X-Git-Tag: v0.5.7~36 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0928f0f290c50b72c4f51988b2bd65fd373f24d7;p=platform%2Fupstream%2Fnodejs.git Fix test-module-load-list 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". --- diff --git a/src/node.js b/src/node.js index 1ebf3e7..97d6165 100644 --- a/src/node.js +++ b/src/node.js @@ -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; @@ -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; } diff --git a/test/simple/test-module-load-list.js b/test/simple/test-module-load-list.js index 1c3cc07..ba430fa 100644 --- a/test/simple/test-module-load-list.js +++ b/test/simple/test-module-load-list.js @@ -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]); } } @@ -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 @@ -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();