| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cf8a488 commit 9e9d499
213 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,17 +1,10 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../../common'); | ||
| 2 | + const common = require('../../common'); | ||
| 3 | 3 | var assert = require('assert'); | |
| 4 | 4 | var binding = require('./build/Release/binding'); | |
| 5 | - var called = false; | ||
| 6 | 5 | ||
| 7 | - process.on('exit', function() { | ||
| 8 | - assert(called); | ||
| 9 | - }); | ||
| 10 | - | ||
| 11 | - binding(5, function(err, val) { | ||
| 6 | + binding(5, common.mustCall(function(err, val) { | ||
| 12 | 7 | assert.equal(null, err); | |
| 13 | 8 | assert.equal(10, val); | |
| 14 | - process.nextTick(function() { | ||
| 15 | - called = true; | ||
| 16 | - }); | ||
| 17 | - }); | ||
| 9 | + process.nextTick(common.mustCall(function() {})); | ||
| 10 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,11 +4,10 @@ | |||
| 4 | 4 | * should trigger the error event after each attempt. | |
| 5 | 5 | */ | |
| 6 | 6 | ||
| 7 | - require('../common'); | ||
| 7 | + const common = require('../common'); | ||
| 8 | 8 | var assert = require('assert'); | |
| 9 | 9 | var http = require('http'); | |
| 10 | 10 | ||
| 11 | - var resDespiteError = false; | ||
| 12 | 11 | var hadError = 0; | |
| 13 | 12 | ||
| 14 | 13 | function httpreq(count) { | |
@@ -19,9 +18,7 @@ function httpreq(count) { | |||
| 19 | 18 | port: 80, | |
| 20 | 19 | path: '/', | |
| 21 | 20 | method: 'GET' | |
| 22 | - }, function(res) { | ||
| 23 | - resDespiteError = true; | ||
| 24 | - }); | ||
| 21 | + }, common.fail); | ||
| 25 | 22 | ||
| 26 | 23 | req.on('error', function(e) { | |
| 27 | 24 | console.log(e.message); | |
@@ -37,6 +34,5 @@ httpreq(0); | |||
| 37 | 34 | ||
| 38 | 35 | ||
| 39 | 36 | process.on('exit', function() { | |
| 40 | - assert.equal(false, resDespiteError); | ||
| 41 | 37 | assert.equal(2, hadError); | |
| 42 | 38 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | var common = require('../common'); | |
| 3 | - var assert = require('assert'); | ||
| 4 | 3 | ||
| 5 | 4 | if (!common.hasCrypto) { | |
| 6 | 5 | common.skip('missing crypto'); | |
@@ -9,21 +8,11 @@ if (!common.hasCrypto) { | |||
| 9 | 8 | var https = require('https'); | |
| 10 | 9 | ||
| 11 | 10 | var http = require('http'); | |
| 12 | - var gotHttpsResp = false; | ||
| 13 | - var gotHttpResp = false; | ||
| 14 | 11 | ||
| 15 | - process.on('exit', function() { | ||
| 16 | - assert(gotHttpsResp); | ||
| 17 | - assert(gotHttpResp); | ||
| 18 | - console.log('ok'); | ||
| 19 | - }); | ||
| 20 | - | ||
| 21 | - https.get('https://www.google.com/', function(res) { | ||
| 22 | - gotHttpsResp = true; | ||
| 12 | + https.get('https://www.google.com/', common.mustCall(function(res) { | ||
| 23 | 13 | res.resume(); | |
| 24 | - }); | ||
| 14 | + })); | ||
| 25 | 15 | ||
| 26 | - http.get('http://www.google.com/', function(res) { | ||
| 27 | - gotHttpResp = true; | ||
| 16 | + http.get('http://www.google.com/', common.mustCall(function(res) { | ||
| 28 | 17 | res.resume(); | |
| 29 | - }); | ||
| 18 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,16 +3,12 @@ | |||
| 3 | 3 | // https://groups.google.com/forum/#!topic/nodejs/UE0ZbfLt6t8 | |
| 4 | 4 | // https://groups.google.com/forum/#!topic/nodejs-dev/jR7-5UDqXkw | |
| 5 | 5 | ||
| 6 | - require('../common'); | ||
| 6 | + const common = require('../common'); | ||
| 7 | 7 | var net = require('net'); | |
| 8 | 8 | var assert = require('assert'); | |
| 9 | 9 | ||
| 10 | 10 | var start = new Date(); | |
| 11 | 11 | ||
| 12 | - var gotTimeout = false; | ||
| 13 | - | ||
| 14 | - var gotConnect = false; | ||
| 15 | - | ||
| 16 | 12 | var T = 100; | |
| 17 | 13 | ||
| 18 | 14 | // 192.0.2.1 is part of subnet assigned as "TEST-NET" in RFC 5737. | |
@@ -23,22 +19,11 @@ var socket = net.createConnection(9999, '192.0.2.1'); | |||
| 23 | 19 | ||
| 24 | 20 | socket.setTimeout(T); | |
| 25 | 21 | ||
| 26 | - socket.on('timeout', function() { | ||
| 22 | + socket.on('timeout', common.mustCall(function() { | ||
| 27 | 23 | console.error('timeout'); | |
| 28 | - gotTimeout = true; | ||
| 29 | 24 | var now = new Date(); | |
| 30 | 25 | assert.ok(now - start < T + 500); | |
| 31 | 26 | socket.destroy(); | |
| 32 | - }); | ||
| 33 | - | ||
| 34 | - socket.on('connect', function() { | ||
| 35 | - console.error('connect'); | ||
| 36 | - gotConnect = true; | ||
| 37 | - socket.destroy(); | ||
| 38 | - }); | ||
| 39 | - | ||
| 27 | + })); | ||
| 40 | 28 | ||
| 41 | - process.on('exit', function() { | ||
| 42 | - assert.ok(gotTimeout); | ||
| 43 | - assert.ok(!gotConnect); | ||
| 44 | - }); | ||
| 29 | + socket.on('connect', common.fail); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,25 +1,14 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 3 | - var assert = require('assert'); | ||
| 2 | + const common = require('../common'); | ||
| 4 | 3 | var net = require('net'); | |
| 5 | 4 | ||
| 6 | - var client, killed = false, ended = false; | ||
| 5 | + var client; | ||
| 7 | 6 | var TIMEOUT = 10 * 1000; | |
| 8 | 7 | ||
| 9 | 8 | client = net.createConnection(53, '8.8.8.8', function() { | |
| 10 | 9 | client.unref(); | |
| 11 | 10 | }); | |
| 12 | 11 | ||
| 13 | - client.on('close', function() { | ||
| 14 | - ended = true; | ||
| 15 | - }); | ||
| 16 | - | ||
| 17 | - setTimeout(function() { | ||
| 18 | - killed = true; | ||
| 19 | - client.end(); | ||
| 20 | - }, TIMEOUT).unref(); | ||
| 12 | + client.on('close', common.fail); | ||
| 21 | 13 | ||
| 22 | - process.on('exit', function() { | ||
| 23 | - assert.strictEqual(killed, false, 'A client should have connected'); | ||
| 24 | - assert.strictEqual(ended, false, 'A client should stay connected'); | ||
| 25 | - }); | ||
| 14 | + setTimeout(common.fail, TIMEOUT).unref(); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,10 +2,6 @@ | |||
| 2 | 2 | var common = require('../common'); | |
| 3 | 3 | var assert = require('assert'); | |
| 4 | 4 | ||
| 5 | - var pwd_called = false; | ||
| 6 | - var childClosed = false; | ||
| 7 | - var childExited = false; | ||
| 8 | - | ||
| 9 | 5 | function pwd(callback) { | |
| 10 | 6 | var output = ''; | |
| 11 | 7 | var child = common.spawnPwd(); | |
@@ -16,17 +12,14 @@ function pwd(callback) { | |||
| 16 | 12 | output += s; | |
| 17 | 13 | }); | |
| 18 | 14 | ||
| 19 | - child.on('exit', function(c) { | ||
| 15 | + child.on('exit', common.mustCall(function(c) { | ||
| 20 | 16 | console.log('exit: ' + c); | |
| 21 | 17 | assert.equal(0, c); | |
| 22 | - childExited = true; | ||
| 23 | - }); | ||
| 18 | + })); | ||
| 24 | 19 | ||
| 25 | - child.on('close', function() { | ||
| 20 | + child.on('close', common.mustCall(function() { | ||
| 26 | 21 | callback(output); | |
| 27 | - pwd_called = true; | ||
| 28 | - childClosed = true; | ||
| 29 | - }); | ||
| 22 | + })); | ||
| 30 | 23 | } | |
| 31 | 24 | ||
| 32 | 25 | ||
@@ -35,9 +28,3 @@ pwd(function(result) { | |||
| 35 | 28 | assert.equal(true, result.length > 1); | |
| 36 | 29 | assert.equal('\n', result[result.length - 1]); | |
| 37 | 30 | }); | |
| 38 | - | ||
| 39 | - process.on('exit', function() { | ||
| 40 | - assert.equal(true, pwd_called); | ||
| 41 | - assert.equal(true, childExited); | ||
| 42 | - assert.equal(true, childClosed); | ||
| 43 | - }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,21 +48,16 @@ if (process.argv[2] === 'child') { | |||
| 48 | 48 | var child = fork(process.argv[1], ['child']); | |
| 49 | 49 | ||
| 50 | 50 | var childFlag = false; | |
| 51 | - var childSelfTerminate = false; | ||
| 52 | - var parentEmit = false; | ||
| 53 | 51 | var parentFlag = false; | |
| 54 | 52 | ||
| 55 | 53 | // when calling .disconnect the event should emit | |
| 56 | 54 | // and the disconnected flag should be true. | |
| 57 | - child.on('disconnect', function() { | ||
| 58 | - parentEmit = true; | ||
| 55 | + child.on('disconnect', common.mustCall(function() { | ||
| 59 | 56 | parentFlag = child.connected; | |
| 60 | - }); | ||
| 57 | + })); | ||
| 61 | 58 | ||
| 62 | 59 | // the process should also self terminate without using signals | |
| 63 | - child.on('exit', function() { | ||
| 64 | - childSelfTerminate = true; | ||
| 65 | - }); | ||
| 60 | + child.on('exit', common.mustCall(function() {})); | ||
| 66 | 61 | ||
| 67 | 62 | // when child is listening | |
| 68 | 63 | child.on('message', function(obj) { | |
@@ -91,8 +86,5 @@ if (process.argv[2] === 'child') { | |||
| 91 | 86 | process.on('exit', function() { | |
| 92 | 87 | assert.equal(childFlag, false); | |
| 93 | 88 | assert.equal(parentFlag, false); | |
| 94 | - | ||
| 95 | - assert.ok(childSelfTerminate); | ||
| 96 | - assert.ok(parentEmit); | ||
| 97 | 89 | }); | |
| 98 | 90 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,33 +1,22 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | var assert = require('assert'); | |
| 4 | 4 | var exec = require('child_process').exec; | |
| 5 | 5 | var os = require('os'); | |
| 6 | - | ||
| 7 | - var success_count = 0; | ||
| 8 | - | ||
| 9 | 6 | var str = 'hello'; | |
| 10 | 7 | ||
| 11 | 8 | // default encoding | |
| 12 | - exec('echo ' + str, function(err, stdout, stderr) { | ||
| 9 | + exec('echo ' + str, common.mustCall(function(err, stdout, stderr) { | ||
| 13 | 10 | assert.ok('string', typeof stdout, 'Expected stdout to be a string'); | |
| 14 | 11 | assert.ok('string', typeof stderr, 'Expected stderr to be a string'); | |
| 15 | 12 | assert.equal(str + os.EOL, stdout); | |
| 16 | - | ||
| 17 | - success_count++; | ||
| 18 | - }); | ||
| 13 | + })); | ||
| 19 | 14 | ||
| 20 | 15 | // no encoding (Buffers expected) | |
| 21 | 16 | exec('echo ' + str, { | |
| 22 | 17 | encoding: null | |
| 23 | - }, function(err, stdout, stderr) { | ||
| 18 | + }, common.mustCall(function(err, stdout, stderr) { | ||
| 24 | 19 | assert.ok(stdout instanceof Buffer, 'Expected stdout to be a Buffer'); | |
| 25 | 20 | assert.ok(stderr instanceof Buffer, 'Expected stderr to be a Buffer'); | |
| 26 | 21 | assert.equal(str + os.EOL, stdout.toString()); | |
| 27 | - | ||
| 28 | - success_count++; | ||
| 29 | - }); | ||
| 30 | - | ||
| 31 | - process.on('exit', function() { | ||
| 32 | - assert.equal(2, success_count); | ||
| 33 | - }); | ||
| 22 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,9 +3,6 @@ const common = require('../common'); | |||
| 3 | 3 | var assert = require('assert'); | |
| 4 | 4 | var exec = require('child_process').exec; | |
| 5 | 5 | ||
| 6 | - var success_count = 0; | ||
| 7 | - var error_count = 0; | ||
| 8 | - | ||
| 9 | 6 | var pwdcommand, dir; | |
| 10 | 7 | ||
| 11 | 8 | if (common.isWindows) { | |
@@ -16,21 +13,7 @@ if (common.isWindows) { | |||
| 16 | 13 | dir = '/dev'; | |
| 17 | 14 | } | |
| 18 | 15 | ||
| 19 | - exec(pwdcommand, {cwd: dir}, function(err, stdout, stderr) { | ||
| 20 | - if (err) { | ||
| 21 | - error_count++; | ||
| 22 | - console.log('error!: ' + err.code); | ||
| 23 | - console.log('stdout: ' + JSON.stringify(stdout)); | ||
| 24 | - console.log('stderr: ' + JSON.stringify(stderr)); | ||
| 25 | - assert.equal(false, err.killed); | ||
| 26 | - } else { | ||
| 27 | - success_count++; | ||
| 28 | - console.log(stdout); | ||
| 29 | - assert.ok(stdout.indexOf(dir) == 0); | ||
| 30 | - } | ||
| 31 | - }); | ||
| 32 | - | ||
| 33 | - process.on('exit', function() { | ||
| 34 | - assert.equal(1, success_count); | ||
| 35 | - assert.equal(0, error_count); | ||
| 36 | - }); | ||
| 16 | + exec(pwdcommand, {cwd: dir}, common.mustCall(function(err, stdout, stderr) { | ||
| 17 | + assert.ifError(err); | ||
| 18 | + assert.ok(stdout.indexOf(dir) == 0); | ||
| 19 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,17 +4,10 @@ var assert = require('assert'); | |||
| 4 | 4 | var child_process = require('child_process'); | |
| 5 | 5 | ||
| 6 | 6 | function test(fun, code) { | |
| 7 | - var errors = 0; | ||
| 8 | - | ||
| 9 | - fun('does-not-exist', function(err) { | ||
| 7 | + fun('does-not-exist', common.mustCall(function(err) { | ||
| 10 | 8 | assert.equal(err.code, code); | |
| 11 | 9 | assert(/does\-not\-exist/.test(err.cmd)); | |
| 12 | - errors++; | ||
| 13 | - }); | ||
| 14 | - | ||
| 15 | - process.on('exit', function() { | ||
| 16 | - assert.equal(errors, 1); | ||
| 17 | - }); | ||
| 10 | + })); | ||
| 18 | 11 | } | |
| 19 | 12 | ||
| 20 | 13 | if (common.isWindows) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments