From: Feross Aboukhadijeh Date: Tue, 30 Jun 2015 22:44:11 +0000 (-0700) Subject: exclude node test test-buffer-fakes.js X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=25fde09c4c2df25e3fd1bd9cadb9d28c969da348;p=buffer.git exclude node test test-buffer-fakes.js These checks only apply in node, where they're calling into C++ and need to ensure the prototype can't be faked to prevent crashes. --- diff --git a/bin/download-node-tests.js b/bin/download-node-tests.js index b871724..883ab98 100755 --- a/bin/download-node-tests.js +++ b/bin/download-node-tests.js @@ -1,10 +1,11 @@ #!/usr/bin/env node -var hyperquest = require('hyperquest') var concat = require('concat-stream') -var split = require('split') -var thru = require('through2') var fs = require('fs') +var hyperquest = require('hyperquest') +var cp = require('child_process') +var split = require('split') +var through = require('through2') var url = 'https://api.github.com/repos/nodejs/io.js/contents' var dirs = [ @@ -12,6 +13,9 @@ var dirs = [ '/test/pummel' ] +cp.execSync('rm -r node/*.js', { cwd: __dirname + '/../test' }) +cp.execSync('rm -r node-es6/*.js', { cwd: __dirname + '/../test' }) + var httpOpts = { headers: { 'User-Agent': null @@ -35,10 +39,14 @@ function downloadBufferTests (dir, files) { if (!/test-buffer.*/.test(file.name)) return var path - if (file.name !== 'test-buffer-iterator.js') { - path = __dirname + '/../test/node/' + file.name - } else { + if (file.name === 'test-buffer-iterator.js') { path = __dirname + '/../test/node-es6/' + file.name + } else if (file.name === 'test-buffer-fakes.js') { + // These teses only apply to node, where they're calling into C++ and need to + // ensure the prototype can't be faked, or else there will be a segfault. + return + } else { + path = __dirname + '/../test/node/' + file.name } hyperquest(file.download_url, httpOpts) @@ -51,7 +59,7 @@ function downloadBufferTests (dir, files) { function testfixer (filename) { var firstline = true - return thru(function (line, enc, cb) { + return through(function (line, enc, cb) { line = line.toString() if (firstline) { @@ -69,9 +77,6 @@ function testfixer (filename) { // require browser buffer line = line.replace(/(.*)require\('buffer'\)(.*)/, '$1require(\'../../\')$2') - // de-const Buffer (in case it's required explicitly with a const by a node test) - line = line.replace(/const Buffer/, 'var Buffer') - // smalloc is only used for kMaxLength line = line.replace(/require\('smalloc'\)/, '{ kMaxLength: 0x3FFFFFFF }') diff --git a/test/node/README.txt b/test/node/README.txt index adf7087..a0fd927 100644 --- a/test/node/README.txt +++ b/test/node/README.txt @@ -1 +1 @@ -io.js/node.js core buffer tests +node core buffer tests diff --git a/test/node/test-buffer-fakes.js b/test/node/test-buffer-fakes.js deleted file mode 100644 index 848026c..0000000 --- a/test/node/test-buffer-fakes.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; -var Buffer = require('../../').Buffer; -if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false; - -var common = {}; -const assert = require('assert'); -var Buffer = require('../../').Buffer; -const Bp = Buffer.prototype; - -function FakeBuffer() { } -FakeBuffer.__proto__ = Buffer; -FakeBuffer.prototype.__proto__ = Buffer.prototype; - -const fb = new FakeBuffer(); - -assert.throws(function() { - new Buffer(fb); -}, TypeError); - -assert.throws(function() { - +Buffer.prototype; -}, TypeError); - -assert.throws(function() { - Buffer.compare(fb, new Buffer(0)); -}, TypeError); - -assert.throws(function() { - fb.write('foo'); -}, TypeError); - -assert.throws(function() { - Buffer.concat([fb, fb]); -}, TypeError); - -assert.throws(function() { - fb.toString(); -}, TypeError); - -assert.throws(function() { - fb.equals(new Buffer(0)); -}, TypeError); - -assert.throws(function() { - fb.indexOf(5); -}, TypeError); - -assert.throws(function() { - fb.readFloatLE(0); -}, TypeError); - -assert.throws(function() { - fb.writeFloatLE(0); -}, TypeError); - -assert.throws(function() { - fb.fill(0); -}, TypeError); -