Fix test-module-load-list
authorRyan Dahl <ry@tinyclouds.org>
Tue, 13 Sep 2011 01:10:42 +0000 (18:10 -0700)
committerRyan Dahl <ry@tinyclouds.org>
Tue, 13 Sep 2011 01:12:48 +0000 (18:12 -0700)
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".

src/node.js
test/simple/test-module-load-list.js

index 1ebf3e7..97d6165 100644 (file)
       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;
       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;
       }
index 1c3cc07..ba430fa 100644 (file)
@@ -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();