[Pkg-javascript-commits] [node-cross-spawn] 01/07: Imported Upstream version 2.0.1

Ross Gammon ross-guest at moszumanska.debian.org
Sun Dec 13 18:11:49 UTC 2015


This is an automated email from the git hooks/post-receive script.

ross-guest pushed a commit to branch master
in repository node-cross-spawn.

commit 718ee739e5852b9bd0595e6426f15681de5f82d2
Author: Ross Gammon <rossgammon at mail.dk>
Date:   Fri Dec 11 16:23:32 2015 +0100

    Imported Upstream version 2.0.1
---
 .travis.yml                 |  4 ++
 appveyor.yml                |  6 ++-
 package.json                |  9 +++--
 test/fixtures/shebang_noenv |  3 ++
 test/test.js                | 99 ++++++++++++++++++++++++++++++++++++++++++---
 test/util/buffered.js       | 21 ++++++----
 6 files changed, 126 insertions(+), 16 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 4feb925..0c27f07 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,3 +2,7 @@ language: node_js
 node_js:
   - '0.10'
   - '0.12'
+  - 'iojs-1'
+  - 'iojs-2'
+  - 'iojs-3'
+  - '4'
diff --git a/appveyor.yml b/appveyor.yml
index 22c6f43..f02a6ba 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -13,10 +13,14 @@ environment:
   matrix:
     - nodejs_version: 0.10
     - nodejs_version: 0.12
+    - nodejs_version: 1
+    - nodejs_version: 2
+    - nodejs_version: 3
+    - nodejs_version: 4
 
 # get the latest stable version of Node 0.STABLE.latest
 install:
-  - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version)
+  - ps: Install-Product node $env:nodejs_version
   - npm install
 
 build: off
diff --git a/package.json b/package.json
index b1f2eaa..8e16297 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "cross-spawn",
-  "version": "2.0.0",
+  "version": "2.0.1",
   "description": "Cross platform child_process#spawn and child_process#spawnSync",
   "main": "index.js",
   "scripts": {
@@ -32,11 +32,14 @@
   "license": "MIT",
   "dependencies": {
     "cross-spawn-async": "^2.0.0",
-    "spawn-sync": "^1.0.13"
+    "spawn-sync": "1.0.13"
   },
   "devDependencies": {
     "expect.js": "^0.3.0",
     "glob": "^5.0.12",
-    "mocha": "^2.2.5"
+    "mkdirp": "^0.5.1",
+    "mocha": "^2.2.5",
+    "rimraf": "^2.4.4",
+    "which": "^1.2.0"
   }
 }
diff --git a/test/fixtures/shebang_noenv b/test/fixtures/shebang_noenv
new file mode 100755
index 0000000..f119f91
--- /dev/null
+++ b/test/fixtures/shebang_noenv
@@ -0,0 +1,3 @@
+#!/usr/local/bin/node
+
+process.stdout.write('shebang works!');
\ No newline at end of file
diff --git a/test/test.js b/test/test.js
index 819f894..19570df 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,32 +1,84 @@
 'use strict';
 
+var fs       = require('fs');
 var path     = require('path');
 var expect   = require('expect.js');
+var rimraf   = require('rimraf');
+var mkdirp   = require('mkdirp');
+var which    = require('which');
 var buffered = require('./util/buffered');
 var spawn    = require('../');
 
 var isWin    = process.platform === 'win32';
 
+// Fix AppVeyor tests because Git bin folder is in PATH and it has a "echo" program there
+if (isWin) {
+    process.env.PATH = process.env.PATH
+    .split(path.delimiter)
+    .filter(function (entry) {
+        return !/\\git\\bin$/i.test(path.normalize(entry));
+    })
+    .join(path.delimiter);
+}
+
 describe('cross-spawn', function () {
     var methods = ['spawn', 'sync'];
 
     methods.forEach(function (method) {
         describe(method, function() {
-            it('should support shebang in executables', function (next) {
-                buffered(method, __dirname + '/fixtures/shebang', function (err, data, code) {
-                    var envPath;
+            var originalPath = process.env.PATH;
+
+            before(function () {
+                mkdirp.sync(__dirname + '/tmp');
+            });
 
+            after(function (next) {
+                // Need to wrap this in a set timeout otherwise it won't work on WINDOWS properly
+                setTimeout(function () {
+                    rimraf(__dirname + '/tmp', next);
+                }, 100);
+            });
+
+            afterEach(function () {
+                process.env.PATH = originalPath;
+            });
+
+            it('should support shebang in executables with /usr/bin/env', function (next) {
+                buffered(method, __dirname + '/fixtures/shebang', function (err, data, code) {
                     expect(err).to.not.be.ok();
                     expect(code).to.be(0);
                     expect(data).to.equal('shebang works!');
 
                     // Test if the actual shebang file is resolved against the PATH
-                    envPath = process.env.PATH;
                     process.env.PATH = path.normalize(__dirname + '/fixtures/') + path.delimiter + process.env.PATH;
 
                     buffered(method, 'shebang', function (err, data, code) {
-                        process.env.PATH = envPath;
+                        expect(err).to.not.be.ok();
+                        expect(code).to.be(0);
+                        expect(data).to.equal('shebang works!');
+
+                        next();
+                    });
+                });
+            });
+
+            it('should support shebang in executables without /usr/bin/env', function (next) {
+                var nodejs = which.sync('node');
+                var file = __dirname + '/fixtures/shebang_noenv';
+
+                fs.writeFileSync(file, '#!' + nodejs + '\n\nprocess.stdout.write(\'shebang works!\');', {
+                    mode: parseInt('0777', 8)
+                });
+
+                buffered(method, file, function (err, data, code) {
+                    expect(err).to.not.be.ok();
+                    expect(code).to.be(0);
+                    expect(data).to.equal('shebang works!');
+
+                    // Test if the actual shebang file is resolved against the PATH
+                    process.env.PATH = path.normalize(__dirname + '/fixtures/') + path.delimiter + process.env.PATH;
 
+                    buffered(method, 'shebang_noenv', function (err, data, code) {
                         expect(err).to.not.be.ok();
                         expect(code).to.be(0);
                         expect(data).to.equal('shebang works!');
@@ -36,6 +88,43 @@ describe('cross-spawn', function () {
                 });
             });
 
+            it('should support shebang in executables with relative path', function (next) {
+                var executable = './' + path.relative(process.cwd(), __dirname + '/fixtures/shebang');
+
+                fs.writeFileSync(__dirname + '/tmp/shebang', '#!/usr/bin/env node\n\nprocess.stdout.write(\'yeah\');', { mode: parseInt('0777', 8) });
+                process.env.PATH = path.normalize(__dirname + '/tmp/') + path.delimiter + process.env.PATH;
+
+                buffered(method, executable, function (err, data, code) {
+                    expect(err).to.not.be.ok();
+                    expect(code).to.be(0);
+                    expect(data).to.equal('shebang works!');
+
+                    next();
+                });
+            });
+
+            it('should support shebang in executables with extensions', function (next) {
+                fs.writeFileSync(__dirname + '/tmp/shebang.js', '#!/usr/bin/env node\n\nprocess.stdout.write(\'shebang with extension\');', { mode: parseInt('0777', 8) });
+                process.env.PATH = path.normalize(__dirname + '/tmp/') + path.delimiter + process.env.PATH;
+
+                buffered(method, __dirname + '/tmp/shebang.js', function (err, data, code) {
+                    expect(err).to.not.be.ok();
+                    expect(code).to.be(0);
+                    expect(data).to.equal('shebang with extension');
+
+                    // Test if the actual shebang file is resolved against the PATH
+                    process.env.PATH = path.normalize(__dirname + '/fixtures/') + path.delimiter + process.env.PATH;
+
+                    buffered(method, 'shebang.js', function (err, data, code) {
+                        expect(err).to.not.be.ok();
+                        expect(code).to.be(0);
+                        expect(data).to.equal('shebang with extension');
+
+                        next();
+                    });
+                });
+            });
+
             it('should expand using PATHEXT properly', function (next) {
                 buffered(method, __dirname + '/fixtures/foo', function (err, data, code) {
                     expect(err).to.not.be.ok();
diff --git a/test/util/buffered.js b/test/util/buffered.js
index 37cd15e..f2a45d3 100644
--- a/test/util/buffered.js
+++ b/test/util/buffered.js
@@ -4,7 +4,8 @@ var spawn = require('../../index');
 
 function buffered(method, command, args, options, callback) {
     var cp;
-    var data;
+    var stdout;
+    var stderr;
     var results;
 
     if (typeof options === 'function') {
@@ -23,17 +24,23 @@ function buffered(method, command, args, options, callback) {
     }
     else {
         cp = spawn(command, args, options);
-        data = null;
+        stdout = stderr = null;
 
-        cp.stdout && cp.stdout.on('data', function(buffer) {
-            data = data || '';
-            data += buffer.toString();
+        cp.stdout && cp.stdout.on('data', function (buffer) {
+            stdout = stdout || '';
+            stdout += buffer.toString();
+        });
+
+        cp.stderr && cp.stderr.on('data', function (buffer) {
+            stderr = stderr || '';
+            stderr += buffer.toString();
         });
 
         cp.on('error', callback);
 
-        cp.on('close', function(code) {
-            callback(null, data, code);
+        cp.on('close', function (code) {
+            code !== 0 && stderr && console.warn(stderr);
+            callback(null, stdout, code);
         });
     }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-cross-spawn.git



More information about the Pkg-javascript-commits mailing list