test: case insensitve path comparison on Windows
authorAlexis Campailla <alexis@janeasystems.com>
Thu, 19 Dec 2013 16:44:33 +0000 (08:44 -0800)
committerFedor Indutny <fedor.indutny@gmail.com>
Fri, 20 Dec 2013 15:23:34 +0000 (19:23 +0400)
Windows needs case insensitive comparison when it comes to
path strings.

test/simple/test-executable-path.js

index 8d82b74..57205af 100644 (file)
@@ -25,6 +25,7 @@ var path = require('path');
 var match = false;
 
 var isDebug = process.features.debug;
+var isWindows = process.platform === 'win32';
 
 var debugPaths = [path.normalize(path.join(__dirname, '..', '..',
                                            'out', 'Debug', 'node')),
@@ -39,13 +40,21 @@ console.error('debugPaths: ' + debugPaths);
 console.error('defaultPaths: ' + defaultPaths);
 console.error('process.execPath: ' + process.execPath);
 
+function pathStartsWith(a, b) {
+  if (isWindows)
+    return (a.toLowerCase().indexOf(b.toLowerCase()) == 0);
+  else
+    return (a.indexOf(b) == 0);
+}
+
+
 if (isDebug) {
   debugPaths.forEach(function(path) {
-    match = match || process.execPath.indexOf(path) == 0;
+    match = match || pathStartsWith(process.execPath, path);
   });
 } else {
   defaultPaths.forEach(function(path) {
-    match = match || process.execPath.indexOf(path) == 0;
+    match = match || pathStartsWith(process.execPath, path);
   });
 }