Comparing version
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var fs = require('./'); | ||
@@ -2,0 +4,0 @@ |
@@ -20,2 +20,4 @@ // Permission is hereby granted, free of charge, to any person obtaining a | ||
"use strict"; | ||
var binding = require('./build/Release/fs-ext'); | ||
@@ -95,3 +97,3 @@ var fs = require('fs'); | ||
} | ||
if(!arg) arg = 0; | ||
if (!arg) arg = 0; | ||
return binding.fcntl(fd, cmd, arg, callback); | ||
@@ -152,12 +154,13 @@ }; | ||
// populate with fs functions from there | ||
for (var key in fs) { | ||
exports[key] = fs[key]; | ||
var key; | ||
for (key in fs) { | ||
exports[key] = fs[key]; | ||
} | ||
// put constants into constants module (don't like doing this but...) | ||
for (var key in binding) { | ||
if (/^[A-Z_]+$/.test(key) && !constants.hasOwnProperty(key)) { | ||
constants[key] = binding[key]; | ||
} | ||
for (key in binding) { | ||
if (/^[A-Z_]+$/.test(key) && !constants.hasOwnProperty(key)) { | ||
constants[key] = binding[key]; | ||
} | ||
} | ||
@@ -6,3 +6,3 @@ { | ||
"keywords": ["fs", "filesystem", "flock", "seek"], | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"homepage": "https://github.com/baudehlo/node-fs-ext/", | ||
@@ -27,3 +27,9 @@ "repository": { | ||
"install": "node-gyp configure build", | ||
"test": "./run_tests" } | ||
"test": "./run_tests", | ||
"lint": "node ./node_modules/eslint/bin/eslint \"*.js\" \"tests/**/*.js\"", | ||
"cover": "NODE_ENV=cov ./node_modules/.bin/istanbul cover _mocha" | ||
}, | ||
"devDependencies": { | ||
"eslint" : "^2.13.0" | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
@@ -9,18 +10,16 @@ // Test these APIs as published in extension module 'fs-ext' | ||
var assert = require('assert'), | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
var tests_ok = 0, | ||
tests_run = 0; | ||
tests_run = 0; | ||
var debug_me = true; | ||
debug_me = false; | ||
var debug_me = false; | ||
var tmp_dir = "/tmp", | ||
file_path = path.join(tmp_dir, 'what.when.fcntl.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.fcntl.test'); | ||
file_path = path.join(tmp_dir, 'what.when.fcntl.test'); | ||
var file_fd, | ||
err; | ||
err; | ||
@@ -35,3 +34,4 @@ | ||
fs.closeSync(file_fd); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not be open, that's okay. | ||
@@ -52,3 +52,4 @@ } | ||
fs.unlinkSync(file_path); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not exist, that's okay. | ||
@@ -64,6 +65,7 @@ } | ||
if ( err && err.code !== expected_errno ) { | ||
fault_msg = api_name + '(): expected error ' + expected_errno + ', got another error'; | ||
} else if ( !err ) { | ||
fault_msg = api_name + '(): expected error ' + expected_errno + ', got another error'; | ||
} | ||
else if ( !err ) { | ||
fault_msg = api_name + '(): expected error ' + expected_errno + ', got another error'; | ||
} | ||
@@ -73,3 +75,4 @@ if ( ! fault_msg ) { | ||
if (debug_me) console.log(' FAILED OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -90,3 +93,4 @@ console.log(' ARGS: ', util.inspect(arguments)); | ||
if (debug_me) console.log(' OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -105,4 +109,5 @@ console.log(' ARGS: ', util.inspect(arguments)); | ||
if ( typeof fs.fcntl !== 'function' ) { | ||
console.log('fs.fcntl API is missing'); | ||
} else { | ||
console.log('fs.fcntl API is missing'); | ||
} | ||
else { | ||
tests_ok++; | ||
@@ -114,3 +119,4 @@ } | ||
console.log('fs.fcntlSync API is missing'); | ||
} else { | ||
} | ||
else { | ||
tests_ok++; | ||
@@ -121,3 +127,3 @@ } | ||
// If any pre-checks and setup fail, quit before tests | ||
if ( tests_run !== tests_ok ) { | ||
if ( tests_run !== tests_ok ) { | ||
process.exit(1); | ||
@@ -134,3 +140,4 @@ } | ||
tests_ok++; | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
console.log(' Unable to create test data file %j', file_path); | ||
@@ -141,3 +148,3 @@ console.log(' Error was: %j', e); | ||
if ( tests_run !== tests_ok ) { | ||
if ( tests_run !== tests_ok ) { | ||
process.exit(1); | ||
@@ -147,3 +154,3 @@ } | ||
// Test that constants are published - - - - - - - - | ||
// Test that constants are published - - - - - - - - | ||
@@ -162,4 +169,5 @@ var fs_binding = require('../build/Release/fs-ext'); | ||
tests_ok++; | ||
} else { | ||
console.log('FAILURE: %s is not defined correctly', name); | ||
} | ||
else { | ||
console.log('FAILURE: %s is not defined correctly', name); | ||
console.log(' %s %j %j', name, fs_binding[name], typeof fs_binding[name]); | ||
@@ -177,3 +185,4 @@ } | ||
err = fs.fcntlSync(undefined, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -185,5 +194,6 @@ } | ||
tests_ok++; | ||
} else { | ||
if (debug_me) console.log(' expected error from undefined fd argument'); | ||
} | ||
else if (debug_me) { | ||
console.log(' expected error from undefined fd argument'); | ||
} | ||
@@ -196,3 +206,4 @@ | ||
err = fs.fcntlSync('foo', 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -204,8 +215,9 @@ } | ||
tests_ok++; | ||
} else { | ||
if (debug_me) console.log(' expected error from non-numeric fd argument'); | ||
} | ||
else if (debug_me) { | ||
console.log(' expected error from non-numeric fd argument'); | ||
} | ||
// fd value is negative | ||
// fd value is negative | ||
@@ -215,3 +227,4 @@ tests_run++; | ||
err = fs.fcntlSync(-9, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -222,3 +235,3 @@ } | ||
// fd value is 'impossible' | ||
// fd value is 'impossible' | ||
@@ -228,3 +241,4 @@ tests_run++; | ||
err = fs.fcntlSync(98765, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -241,16 +255,18 @@ } | ||
err = fs.fcntlSync(file_fd, 'foo'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
} | ||
// "message": "Unknown fcntl flag: foo" | ||
// "message": "Unknown fcntl flag: foo" | ||
if (err) { | ||
if (debug_me) console.log(' err %j', err); | ||
tests_ok++; | ||
} else { | ||
if (debug_me) console.log(' expected error from non-numeric fd argument'); | ||
} | ||
else if (debug_me) { | ||
console.log(' expected error from non-numeric fd argument'); | ||
} | ||
// Test valid calls: fcntlSync - - - - - - - - - - | ||
// Test valid calls: fcntlSync - - - - - - - - - - | ||
@@ -261,3 +277,4 @@ tests_run++; | ||
fs.fcntlSync(file_fd, 'getfd'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -287,3 +304,4 @@ } | ||
} | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -293,3 +311,3 @@ } | ||
// Test valid calls: fcntl - - - - - - - - - - - | ||
// Test valid calls: fcntl - - - - - - - - - - - | ||
@@ -329,3 +347,3 @@ // SEEK_SET to 0 | ||
// Test invalid calls: fcntl - - - - - - - - - | ||
// Test invalid calls: fcntl - - - - - - - - - | ||
@@ -340,3 +358,4 @@ // offset value is negative | ||
err = undefined; | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -348,5 +367,6 @@ } | ||
tests_ok++; | ||
} else { | ||
if (debug_me) console.log(' unexpected success from fcntl() with bad argument'); | ||
} | ||
else if (debug_me) { | ||
console.log(' unexpected success from fcntl() with bad argument'); | ||
} | ||
}); | ||
@@ -353,0 +373,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
// Stress test these APIs as published in extension module 'fs-ext' | ||
@@ -7,4 +7,4 @@ // Specifically, try to exercise any memory leaks by simple repetition. | ||
// | ||
// Asynchronous flock(2). No arguments other than a possible error are | ||
// passed to the callback. Flags can be 'sh', 'ex', 'shnb', 'exnb', 'un' | ||
// Asynchronous flock(2). No arguments other than a possible error are | ||
// passed to the callback. Flags can be 'sh', 'ex', 'shnb', 'exnb', 'un' | ||
// and correspond to the various LOCK_SH, LOCK_EX, LOCK_SH|LOCK_NB, etc. | ||
@@ -26,18 +26,17 @@ // | ||
var assert = require('assert'), | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
var tests_ok = 0, | ||
tests_run = 0; | ||
tests_run = 0; | ||
var debug_me = true; | ||
debug_me = false; | ||
var debug_me = false; | ||
var tmp_dir = "/tmp", | ||
file_path = path.join(tmp_dir, 'what.when.flock.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.flock.test'); | ||
file_path = path.join(tmp_dir, 'what.when.flock.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.flock.test'); | ||
var file_fd, | ||
err; | ||
err; | ||
@@ -57,3 +56,4 @@ | ||
fs.closeSync(file_fd); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not be open, that's okay. | ||
@@ -74,3 +74,4 @@ } | ||
fs.unlinkSync(file_path); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not exist, that's okay. | ||
@@ -82,5 +83,5 @@ } | ||
var usage = process.memoryUsage(); | ||
console.log(' memory: heapUsed %d rss %d', | ||
console.log(' memory: heapUsed %d rss %d', | ||
usage.heapUsed, usage.rss); | ||
console.log(' heapTotal %d vsize %d', | ||
console.log(' heapTotal %d vsize %d', | ||
usage.heapTotal, usage.vsize); | ||
@@ -95,6 +96,7 @@ } | ||
if ( err && err.code !== expected_errno ) { | ||
fault_msg = api_name + '(): expected error ' + expected_errno + ', got another error'; | ||
} else if ( !err ) { | ||
fault_msg = api_name + '(): expected error ' + expected_errno + ', got another error'; | ||
} | ||
else if ( !err ) { | ||
fault_msg = api_name + '(): expected error ' + expected_errno + ', got another error'; | ||
} | ||
@@ -104,3 +106,4 @@ if ( ! fault_msg ) { | ||
if (debug_me) console.log(' FAILED OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -121,3 +124,4 @@ console.log(' ARGS: ', util.inspect(arguments)); | ||
if (debug_me) console.log(' OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -132,3 +136,3 @@ console.log(' ARGS: ', util.inspect(arguments)); | ||
// We assume that test-fs-flock.js has run successfully before this | ||
// We assume that test-fs-flock.js has run successfully before this | ||
// test and so we omit several duplicate tests. | ||
@@ -144,3 +148,4 @@ | ||
tests_ok++; | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
console.log(' Unable to create test data file %j', file_path); | ||
@@ -151,3 +156,3 @@ console.log(' Error was: %j', e); | ||
if ( tests_run !== tests_ok ) { | ||
if ( tests_run !== tests_ok ) { | ||
process.exit(1); | ||
@@ -160,4 +165,4 @@ } | ||
var how_many_times, | ||
how_many_secs, | ||
how_many_done; | ||
how_many_secs, | ||
how_many_done; | ||
@@ -171,4 +176,4 @@ | ||
// Repeat a successful flockSync() call | ||
if( 1 ) { | ||
// Repeat a successful flockSync() call | ||
if ( 1 ) { | ||
how_many_times = 10000000; | ||
@@ -178,3 +183,3 @@ //how_many_times = 1000000; | ||
for( var i=0 ; i<how_many_times ; i++ ) { | ||
for ( var i=0 ; i<how_many_times ; i++ ) { | ||
tests_run++; | ||
@@ -191,4 +196,4 @@ err = fs.flockSync(file_fd, 'un'); | ||
// Repeat a successful flock() call | ||
if( 1 ) { | ||
// Repeat a successful flock() call | ||
if ( 1 ) { | ||
how_many_times = 1000000; | ||
@@ -216,5 +221,6 @@ //how_many_times = 100000; | ||
}); | ||
} else { | ||
} | ||
else { | ||
test_failing_flock(); | ||
} | ||
} | ||
@@ -244,3 +250,2 @@ function test_failing_flock() { | ||
}); | ||
} else { | ||
} | ||
@@ -247,0 +252,0 @@ |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
@@ -6,4 +7,4 @@ // Test these APIs as published in extension module 'fs-ext' | ||
// | ||
// Asynchronous flock(2). No arguments other than a possible error are | ||
// passed to the callback. Flags can be 'sh', 'ex', 'shnb', 'exnb', 'un' | ||
// Asynchronous flock(2). No arguments other than a possible error are | ||
// passed to the callback. Flags can be 'sh', 'ex', 'shnb', 'exnb', 'un' | ||
// and correspond to the various LOCK_SH, LOCK_EX, LOCK_SH|LOCK_NB, etc. | ||
@@ -27,18 +28,17 @@ // | ||
var assert = require('assert'), | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
var tests_ok = 0, | ||
tests_run = 0; | ||
tests_run = 0; | ||
var debug_me = true; | ||
debug_me = false; | ||
var debug_me = false; | ||
var tmp_dir = "/tmp", | ||
file_path = path.join(tmp_dir, 'what.when.flock.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.flock.test'); | ||
file_path = path.join(tmp_dir, 'what.when.flock.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.flock.test'); | ||
var file_fd, | ||
err; | ||
err; | ||
@@ -53,3 +53,4 @@ | ||
fs.closeSync(file_fd); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not be open, that's okay. | ||
@@ -70,3 +71,4 @@ } | ||
fs.unlinkSync(file_path); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not exist, that's okay. | ||
@@ -82,6 +84,7 @@ } | ||
if ( err && err.code !== expected_errno ) { | ||
fault_msg = api_name + '(): expected error ' + expected_errno + ', got another error'; | ||
} else if ( !err ) { | ||
fault_msg = api_name + '(): expected error ' + expected_errno + ', got another error'; | ||
} | ||
else if ( !err ) { | ||
fault_msg = api_name + '(): expected error ' + expected_errno + ', got another error'; | ||
} | ||
@@ -91,3 +94,4 @@ if ( ! fault_msg ) { | ||
if (debug_me) console.log(' FAILED OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -108,3 +112,4 @@ console.log(' ARGS: ', util.inspect(arguments)); | ||
if (debug_me) console.log(' OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -123,4 +128,5 @@ console.log(' ARGS: ', util.inspect(arguments)); | ||
if ( typeof fs.flock !== 'function' ) { | ||
console.log('fs.flock API is missing'); | ||
} else { | ||
console.log('fs.flock API is missing'); | ||
} | ||
else { | ||
tests_ok++; | ||
@@ -132,3 +138,4 @@ } | ||
console.log('fs.flockSync API is missing'); | ||
} else { | ||
} | ||
else { | ||
tests_ok++; | ||
@@ -139,3 +146,3 @@ } | ||
// If any pre-checks and setup fail, quit before tests | ||
if ( tests_run !== tests_ok ) { | ||
if ( tests_run !== tests_ok ) { | ||
process.exit(1); | ||
@@ -152,3 +159,4 @@ } | ||
tests_ok++; | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
console.log(' Unable to create test data file %j', file_path); | ||
@@ -159,3 +167,3 @@ console.log(' Error was: %j', e); | ||
if ( tests_run !== tests_ok ) { | ||
if ( tests_run !== tests_ok ) { | ||
process.exit(1); | ||
@@ -165,3 +173,3 @@ } | ||
// Test that constants are published - - - - - - - - | ||
// Test that constants are published - - - - - - - - | ||
@@ -180,4 +188,5 @@ var fs_binding = require('../build/Release/fs-ext'); | ||
tests_ok++; | ||
} else { | ||
console.log('FAILURE: %s is not defined correctly', name); | ||
} | ||
else { | ||
console.log('FAILURE: %s is not defined correctly', name); | ||
console.log(' %s %j %j', name, fs_binding[name], typeof fs_binding[name]); | ||
@@ -190,3 +199,3 @@ } | ||
// fd value is undefined | ||
// fd value is undefined | ||
@@ -196,3 +205,4 @@ tests_run++; | ||
err = fs.flockSync(undefined, 'un'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -204,8 +214,9 @@ } | ||
tests_ok++; | ||
} else { | ||
if (debug_me) console.log(' expected error from undefined fd argument'); | ||
} | ||
else if (debug_me) { | ||
console.log(' expected error from undefined fd argument'); | ||
} | ||
// fd value is non-number | ||
// fd value is non-number | ||
@@ -215,3 +226,4 @@ tests_run++; | ||
err = fs.flockSync('foo', 'un'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -223,8 +235,9 @@ } | ||
tests_ok++; | ||
} else { | ||
if (debug_me) console.log(' expected error from non-numeric fd argument'); | ||
} | ||
else if (debug_me) { | ||
console.log(' expected error from non-numeric fd argument'); | ||
} | ||
// fd value is negative | ||
// fd value is negative | ||
@@ -234,3 +247,4 @@ tests_run++; | ||
err = fs.flockSync(-9, 'un'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -241,3 +255,3 @@ } | ||
// fd value is 'impossible' | ||
// fd value is 'impossible' | ||
@@ -247,3 +261,4 @@ tests_run++; | ||
err = fs.flockSync(98765, 'un'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -261,16 +276,18 @@ } | ||
err = fs.flockSync(file_fd, 'foo'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
} | ||
// "message": "Unknown flock flag: foo" | ||
// "message": "Unknown flock flag: foo" | ||
if (err) { | ||
if (debug_me) console.log(' err %j', err); | ||
tests_ok++; | ||
} else { | ||
if (debug_me) console.log(' expected error from non-numeric fd argument'); | ||
} | ||
else if (debug_me) { | ||
console.log(' expected error from non-numeric fd argument'); | ||
} | ||
// Test valid calls: flockSync - - - - - - - - - - | ||
// Test valid calls: flockSync - - - - - - - - - - | ||
@@ -284,3 +301,4 @@ // Flags can be 'sh', 'ex', 'shnb', 'exnb', 'un'. | ||
err = fs.flockSync(file_fd, 'un'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -296,3 +314,4 @@ } | ||
err = fs.flockSync(file_fd, 'sh'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -305,3 +324,4 @@ } | ||
err = fs.flockSync(file_fd, 'un'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -317,3 +337,4 @@ } | ||
err = fs.flockSync(file_fd, 'ex'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -326,3 +347,4 @@ } | ||
err = fs.flockSync(file_fd, 'un'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -338,3 +360,4 @@ } | ||
err = fs.flockSync(file_fd, 'shnb'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -347,3 +370,4 @@ } | ||
err = fs.flockSync(file_fd, 'un'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -359,3 +383,4 @@ } | ||
err = fs.flockSync(file_fd, 'exnb'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -368,3 +393,4 @@ } | ||
err = fs.flockSync(file_fd, 'un'); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -381,3 +407,3 @@ } | ||
// Test valid calls: flock - - - - - - - - - - - | ||
// Test valid calls: flock - - - - - - - - - - - | ||
@@ -387,3 +413,3 @@ // SEEK_SET to 0 | ||
tests_run++; | ||
tests_run++; | ||
tests_run++; | ||
fs.flock(file_fd, 'sh', function(err, extra) { | ||
@@ -395,4 +421,5 @@ expect_ok('flock', file_fd, err); | ||
if ( extra === undefined ) { | ||
tests_ok++; | ||
} else { | ||
tests_ok++; | ||
} | ||
else { | ||
console.log(' async flock() callback received more than one argument'); | ||
@@ -409,3 +436,3 @@ } | ||
// Test invalid calls: flock - - - - - - - - - | ||
// Test invalid calls: flock - - - - - - - - - | ||
@@ -420,12 +447,14 @@ // offset value is negative | ||
err = undefined; | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
} | ||
// "message": "Unknown flock flag: foo" | ||
// "message": "Unknown flock flag: foo" | ||
if (err) { | ||
if (debug_me) console.log(' err %j', err); | ||
tests_ok++; | ||
} else { | ||
if (debug_me) console.log(' unexpected success from flock() with bad argument'); | ||
} | ||
else if (debug_me) { | ||
console.log(' unexpected success from flock() with bad argument'); | ||
} | ||
}); | ||
@@ -437,4 +466,4 @@ }); | ||
//------------------------------------------------------------------------------ | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - | ||
// | ||
@@ -441,0 +470,0 @@ // Errors we have seen: |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
@@ -7,9 +8,9 @@ // Stress test these APIs as published in extension module 'fs-ext' | ||
// | ||
// Asynchronous lseek(2). | ||
// Asynchronous lseek(2). | ||
// | ||
// callback will be given two arguments (err, currFilePos). | ||
// | ||
// whence can be 0 (SEEK_SET) to set the new position in bytes to offset, | ||
// 1 (SEEK_CUR) to set the new position to the current position plus offset | ||
// bytes (can be negative), or 2 (SEEK_END) to set to the end of the file | ||
// | ||
// whence can be 0 (SEEK_SET) to set the new position in bytes to offset, | ||
// 1 (SEEK_CUR) to set the new position to the current position plus offset | ||
// bytes (can be negative), or 2 (SEEK_END) to set to the end of the file | ||
// plus offset bytes (usually negative or zero to seek to the end of the file). | ||
@@ -29,19 +30,19 @@ // | ||
var assert = require('assert'), | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
var tests_ok = 0, | ||
tests_run = 0; | ||
tests_run = 0; | ||
var debug_me = true; | ||
debug_me = false; | ||
debug_me = false; | ||
var tmp_dir = "/tmp", | ||
file_path = path.join(tmp_dir, 'what.when.seek.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.seek.test'); | ||
file_path = path.join(tmp_dir, 'what.when.seek.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.seek.test'); | ||
var file_fd, | ||
result, | ||
err; | ||
result, | ||
err; | ||
@@ -61,3 +62,4 @@ | ||
fs.closeSync(file_fd); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not be open, that's okay. | ||
@@ -78,3 +80,4 @@ } | ||
fs.unlinkSync(file_path); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not exist, that's okay. | ||
@@ -86,5 +89,5 @@ } | ||
var usage = process.memoryUsage(); | ||
console.log(' memory: heapUsed %d rss %d', | ||
console.log(' memory: heapUsed %d rss %d', | ||
usage.heapUsed, usage.rss); | ||
console.log(' heapTotal %d vsize %d', | ||
console.log(' heapTotal %d vsize %d', | ||
usage.heapTotal, usage.vsize); | ||
@@ -100,10 +103,10 @@ } | ||
fault_msg = api_name + '(): returned error ' + err.message; | ||
} else { | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned error ' + err; | ||
} | ||
} else { | ||
if ( value_seen !== value_expected ) { | ||
fault_msg = api_name + '(): wrong value ' + value_seen + | ||
} | ||
else if ( value_seen !== value_expected ) { | ||
fault_msg = api_name + '(): wrong value ' + value_seen + | ||
' (expecting ' + value_expected + ')'; | ||
} | ||
} | ||
@@ -114,3 +117,4 @@ | ||
if (debug_me) console.log(' OK: %s() returned ', api_name, value_seen); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -131,13 +135,16 @@ console.log(' ARGS: ', util.inspect(arguments)); | ||
if ( err.code !== expected_errno ) { | ||
fault_msg = api_name + '(): returned wrong errno \'' + err.message + | ||
fault_msg = api_name + '(): returned wrong errno \'' + err.message + | ||
'\' (expecting ' + expected_errno + ')'; | ||
} | ||
} else { | ||
} | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned wrong error \'' + err + '\''; | ||
} | ||
} else { | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned wrong error \'' + err + '\''; | ||
} | ||
} else { | ||
fault_msg = api_name + '(): expected errno \'' + expected_errno + | ||
} | ||
else { | ||
fault_msg = api_name + '(): expected errno \'' + expected_errno + | ||
'\', but got result ' + value_seen; | ||
@@ -149,3 +156,4 @@ } | ||
if (debug_me) console.log(' FAILED OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -160,3 +168,3 @@ if (debug_me) console.log(' ARGS: ', util.inspect(arguments)); | ||
// We assume that test-fs-seek.js has run successfully before this | ||
// We assume that test-fs-seek.js has run successfully before this | ||
// test and so we omit several duplicate tests. | ||
@@ -172,3 +180,4 @@ | ||
tests_ok++; | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
console.log(' Unable to create test data file %j', file_path); | ||
@@ -179,3 +188,3 @@ console.log(' Error was: %j', e); | ||
if ( tests_run !== tests_ok ) { | ||
if ( tests_run !== tests_ok ) { | ||
process.exit(1); | ||
@@ -188,4 +197,4 @@ } | ||
var how_many_times, | ||
how_many_secs, | ||
how_many_done; | ||
how_many_secs, | ||
how_many_done; | ||
@@ -206,3 +215,3 @@ | ||
if (how_many_secs > 0 ) { | ||
setTimeout(ho_hum,1000); | ||
setTimeout(ho_hum, 1000); | ||
return; | ||
@@ -213,3 +222,3 @@ } | ||
console.log(' Time is %s', new Date()); | ||
}, | ||
}, | ||
1000 ); | ||
@@ -219,8 +228,8 @@ } | ||
// Repeat a successful seekSync() call | ||
if( 1 ) { | ||
// Repeat a successful seekSync() call | ||
if ( 1 ) { | ||
how_many_times = 10000000; | ||
//how_many_times = 4; | ||
for( var i=0 ; i<how_many_times ; i++ ) { | ||
for ( var i=0 ; i<how_many_times ; i++ ) { | ||
tests_run++; | ||
@@ -238,4 +247,4 @@ result = err = undefined; | ||
// Repeat a successful seek() call | ||
if( 1 ) { | ||
// Repeat a successful seek() call | ||
if ( 1 ) { | ||
how_many_times = 1000000; | ||
@@ -262,5 +271,6 @@ //how_many_times = 4; | ||
}); | ||
} else { | ||
} | ||
else { | ||
test_failing_seek(); | ||
} | ||
} | ||
@@ -289,3 +299,2 @@ function test_failing_seek() { | ||
}); | ||
} else { | ||
} | ||
@@ -298,4 +307,4 @@ | ||
//------------------------------------------------------------------------------ | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - | ||
@@ -302,0 +311,0 @@ // ### fs.seek(fd, offset, whence, [callback]) |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
@@ -6,9 +7,9 @@ // Test these APIs as published in extension module 'fs-ext' | ||
// | ||
// Asynchronous lseek(2). | ||
// Asynchronous lseek(2). | ||
// | ||
// callback will be given two arguments (err, currFilePos). | ||
// | ||
// whence can be 0 (SEEK_SET) to set the new position in bytes to offset, | ||
// 1 (SEEK_CUR) to set the new position to the current position plus offset | ||
// bytes (can be negative), or 2 (SEEK_END) to set to the end of the file | ||
// | ||
// whence can be 0 (SEEK_SET) to set the new position in bytes to offset, | ||
// 1 (SEEK_CUR) to set the new position to the current position plus offset | ||
// bytes (can be negative), or 2 (SEEK_END) to set to the end of the file | ||
// plus offset bytes (usually negative or zero to seek to the end of the file). | ||
@@ -27,6 +28,6 @@ // | ||
//XXX Combine seek() calls with calls to write() and read() to verify that | ||
//XXX Combine seek() calls with calls to write() and read() to verify that | ||
// the file position is being correctly reset. | ||
//XXX Test specific values for 'whence' constants? | ||
//XXX Test specific values for 'whence' constants? | ||
@@ -36,5 +37,5 @@ | ||
// 0, 1, and 2, for the equivalent 'meanings' SEEK_SET/_CUR/_END, | ||
// then you are implying that even if other library implementations | ||
// use different system values you will be translating from 0/1/2 to | ||
// the system values. | ||
// then you are implying that even if other library implementations | ||
// use different system values you will be translating from 0/1/2 to | ||
// the system values. | ||
// So... shouldn't define module constants SEEK_SET/_CUR/_END using the | ||
@@ -50,20 +51,20 @@ // system values, but rather as own constants, and translate to system | ||
var assert = require('assert'), | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
var tests_ok = 0, | ||
tests_run = 0; | ||
tests_run = 0; | ||
var debug_me = true; | ||
debug_me = false; | ||
debug_me = false; | ||
var tmp_dir = "/tmp", | ||
file_path = path.join(tmp_dir, 'what.when.seek.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.seek.test'); | ||
file_path = path.join(tmp_dir, 'what.when.seek.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.seek.test'); | ||
var file_fd, | ||
result, | ||
err, | ||
offset_big; | ||
result, | ||
err, | ||
offset_big; | ||
@@ -79,3 +80,4 @@ | ||
fs.closeSync(file_fd); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not be open, that's okay. | ||
@@ -102,3 +104,4 @@ } | ||
fs.unlinkSync(file_path); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not exist, that's okay. | ||
@@ -115,10 +118,10 @@ } | ||
fault_msg = api_name + '(): returned error ' + err.message; | ||
} else { | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned error ' + err; | ||
} | ||
} else { | ||
if ( value_seen !== value_expected ) { | ||
fault_msg = api_name + '(): wrong value \'' + value_seen + | ||
} | ||
else if ( value_seen !== value_expected ) { | ||
fault_msg = api_name + '(): wrong value \'' + value_seen + | ||
'\' (expecting ' + value_expected + ')'; | ||
} | ||
} | ||
@@ -129,3 +132,4 @@ | ||
if (debug_me) console.log(' OK: %s() returned ', api_name, value_seen); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -146,15 +150,18 @@ console.log(' ARGS: ', util.inspect(arguments)); | ||
if ( err.code !== expected_errno ) { | ||
fault_msg = api_name + '(): returned wrong errno \'' + err.message + | ||
fault_msg = api_name + '(): returned wrong errno \'' + err.message + | ||
'\' (expecting ' + expected_errno + ')'; | ||
} | ||
} else { | ||
} | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned wrong error \'' + err + '\''; | ||
console.log(' (We see non-errno error %j', err); | ||
} | ||
} else { | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned wrong error \'' + err + '\''; | ||
console.log(' (We see non-Error error %j', err); | ||
} | ||
} else { | ||
fault_msg = api_name + '(): expected errno \'' + expected_errno + | ||
} | ||
else { | ||
fault_msg = api_name + '(): expected errno \'' + expected_errno + | ||
'\', but got result ' + value_seen; | ||
@@ -166,3 +173,4 @@ } | ||
if (debug_me) console.log(' FAILED OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -182,5 +190,6 @@ if (debug_me) console.log(' ARGS: ', util.inspect(arguments)); | ||
if ( err.code !== undefined ) { | ||
fault_msg = api_name + '(): returned wrong error \'' + err.message + | ||
fault_msg = api_name + '(): returned wrong error \'' + err.message + | ||
'\' (expecting ' + expected_error + ')'; | ||
} else if ( err.message !== undefined ) { | ||
} | ||
else if ( err.message !== undefined ) { | ||
if ( err.message !== expected_error ) { | ||
@@ -190,12 +199,15 @@ fault_msg = api_name + '(): returned wrong error \'' + err + '\''; | ||
} | ||
} else { | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned wrong error \'' + err + '\''; | ||
console.log(' (We see non-errno error %j', err); | ||
} | ||
} else { | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned wrong error \'' + err + '\''; | ||
console.log(' (We see non-Error error %j', err); | ||
} | ||
} else { | ||
fault_msg = api_name + '(): expected errno \'' + expected_errno + | ||
} | ||
else { | ||
fault_msg = api_name + '(): expected errno \'' + expected_error + | ||
'\', but got result ' + value_seen; | ||
@@ -207,3 +219,4 @@ } | ||
if (debug_me) console.log(' FAILED OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -223,4 +236,5 @@ if (debug_me) console.log(' ARGS: ', util.inspect(arguments)); | ||
if ( typeof fs.seek !== 'function' ) { | ||
console.log('fs.seek API is missing'); | ||
} else { | ||
console.log('fs.seek API is missing'); | ||
} | ||
else { | ||
tests_ok++; | ||
@@ -232,3 +246,4 @@ } | ||
console.log('fs.seekSync API is missing'); | ||
} else { | ||
} | ||
else { | ||
tests_ok++; | ||
@@ -239,3 +254,3 @@ } | ||
// If any pre-checks and setup fail, quit before tests | ||
if ( tests_run !== tests_ok ) { | ||
if ( tests_run !== tests_ok ) { | ||
process.exit(1); | ||
@@ -252,3 +267,4 @@ } | ||
tests_ok++; | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
console.log(' Unable to create test data file %j', file_path); | ||
@@ -259,3 +275,3 @@ console.log(' Error was: %j', e); | ||
if ( tests_run !== tests_ok ) { | ||
if ( tests_run !== tests_ok ) { | ||
process.exit(1); | ||
@@ -265,3 +281,3 @@ } | ||
// Test that constants are published - - - - - - - - | ||
// Test that constants are published - - - - - - - - | ||
@@ -280,4 +296,5 @@ var fs_binding = require('../build/Release/fs-ext'); | ||
tests_ok++; | ||
} else { | ||
console.log('FAILURE: %s is not defined correctly', name); | ||
} | ||
else { | ||
console.log('FAILURE: %s is not defined correctly', name); | ||
console.log(' %s %j %j', name, fs_binding[name], typeof fs_binding[name]); | ||
@@ -291,3 +308,3 @@ } | ||
// fd value is undefined | ||
// fd value is undefined | ||
@@ -298,3 +315,4 @@ tests_run++; | ||
result = fs.seekSync(undefined, 0, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -305,3 +323,3 @@ } | ||
// fd value is non-number | ||
// fd value is non-number | ||
@@ -312,3 +330,4 @@ tests_run++; | ||
result = fs.seekSync('foo', 0, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -319,3 +338,3 @@ } | ||
// fd value is negative | ||
// fd value is negative | ||
@@ -326,3 +345,4 @@ tests_run++; | ||
result = fs.seekSync(-9, 0, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -333,3 +353,3 @@ } | ||
// fd value is 'impossible' | ||
// fd value is 'impossible' | ||
@@ -340,3 +360,4 @@ tests_run++; | ||
result = fs.seekSync(98765, 0, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -353,3 +374,4 @@ } | ||
result = fs.seekSync(file_fd, 0, 98765); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -364,3 +386,4 @@ } | ||
result = fs.seekSync(file_fd, 0, -99); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -377,3 +400,4 @@ } | ||
result = fs.seekSync(file_fd, -98765, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -390,3 +414,4 @@ } | ||
result = fs.seekSync(file_fd, 4.0001, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -397,3 +422,3 @@ } | ||
// offset value is "too big" (beyond end of file) | ||
// offset value is "too big" (beyond end of file) | ||
// This unexpectedly 'works' ... | ||
@@ -405,3 +430,4 @@ | ||
result = fs.seekSync(file_fd, 98765, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -412,3 +438,3 @@ } | ||
// offset value is "very big" (from below to beyond 32 bits) | ||
// offset value is "very big" (from below to beyond 32 bits) | ||
@@ -420,3 +446,4 @@ tests_run++; | ||
result = fs.seekSync(file_fd, offset_big, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -432,3 +459,4 @@ } | ||
result = fs.seekSync(file_fd, offset_big, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -444,3 +472,4 @@ } | ||
result = fs.seekSync(file_fd, offset_big, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -457,3 +486,4 @@ } | ||
result = fs.seekSync(file_fd, offset_big, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -480,3 +510,3 @@ } | ||
// Test valid calls: seekSync - - - - - - - - - - | ||
// Test valid calls: seekSync - - - - - - - - - - | ||
@@ -489,3 +519,4 @@ // SEEK_SET to 0 | ||
result = fs.seekSync(file_fd, 0, 0); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -502,3 +533,4 @@ } | ||
result = fs.seekSync(file_fd, 0, 1); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -515,3 +547,4 @@ } | ||
result = fs.seekSync(file_fd, 0, 2); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -528,3 +561,4 @@ } | ||
result = fs.seekSync(file_fd, 0, fs_binding.SEEK_SET); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -541,3 +575,4 @@ } | ||
result = fs.seekSync(file_fd, 0, fs_binding.SEEK_CUR); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -554,3 +589,4 @@ } | ||
result = fs.seekSync(file_fd, 0, fs_binding.SEEK_END); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -563,3 +599,3 @@ } | ||
// Test valid calls: seek - - - - - - - - - - - | ||
// Test valid calls: seek - - - - - - - - - - - | ||
@@ -580,3 +616,3 @@ // SEEK_SET to 0 | ||
// Test invalid calls: seek - - - - - - - - - | ||
// Test invalid calls: seek - - - - - - - - - | ||
@@ -601,4 +637,4 @@ // offset value is negative | ||
//------------------------------------------------------------------------------ | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
//- - - - - - - - - - - - - - - - - - - - - - - - - - | ||
// | ||
@@ -605,0 +641,0 @@ // Errors we have seen: |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var fs = require(__dirname+'/../fs-ext.js'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
@@ -23,5 +24,5 @@ // Stress test these APIs as published in extension module 'fs-ext' | ||
var assert = require('assert'), | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
@@ -32,14 +33,14 @@ var tests_ok = 0; | ||
var debug_me = true; | ||
debug_me = false; | ||
debug_me = false; | ||
var tmp_dir = "/tmp", | ||
file_path = path.join(tmp_dir, 'what.when.utime.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.utime.test'); | ||
file_path = path.join(tmp_dir, 'what.when.utime.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.utime.test'); | ||
var result, | ||
err; | ||
err; | ||
var atime_old, mtime_old, | ||
atime_req, mtime_req, | ||
atime_seen, mtime_seen; | ||
atime_req, mtime_req, | ||
atime_seen, mtime_seen; | ||
@@ -76,3 +77,4 @@ | ||
fs.unlinkSync(file_path); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not exist, that's okay. | ||
@@ -90,5 +92,5 @@ } | ||
var usage = process.memoryUsage(); | ||
console.log(' memory: heapUsed %d rss %d', | ||
console.log(' memory: heapUsed %d rss %d', | ||
usage.heapUsed, usage.rss); | ||
console.log(' heapTotal %d vsize %d', | ||
console.log(' heapTotal %d vsize %d', | ||
usage.heapTotal, usage.vsize); | ||
@@ -104,10 +106,10 @@ } | ||
fault_msg = api_name + '(): returned error ' + err.message; | ||
} else { | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned error ' + err; | ||
} | ||
} else { | ||
if ( value_seen !== value_expected ) { | ||
fault_msg = api_name + '(): wrong value ' + value_seen + | ||
} | ||
else if ( value_seen !== value_expected ) { | ||
fault_msg = api_name + '(): wrong value ' + value_seen + | ||
' (expecting ' + value_expected + ')'; | ||
} | ||
} | ||
@@ -118,3 +120,4 @@ | ||
if (debug_me) console.log(' OK: %s() returned ', api_name, value_seen); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -135,13 +138,16 @@ console.log(' ARGS: ', util.inspect(arguments)); | ||
if ( err.code !== expected_errno ) { | ||
fault_msg = api_name + '(): returned wrong errno \'' + err.message + | ||
fault_msg = api_name + '(): returned wrong errno \'' + err.message + | ||
'\' (expecting ' + expected_errno + ')'; | ||
} | ||
} else { | ||
} | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned wrong error \'' + err + '\''; | ||
} | ||
} else { | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned wrong error \'' + err + '\''; | ||
} | ||
} else { | ||
fault_msg = api_name + '(): expected errno \'' + expected_errno + | ||
} | ||
else { | ||
fault_msg = api_name + '(): expected errno \'' + expected_errno + | ||
'\', but got result ' + value_seen; | ||
@@ -153,3 +159,4 @@ } | ||
if (debug_me) console.log(' FAILED OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -163,3 +170,3 @@ if (debug_me) console.log(' ARGS: ', util.inspect(arguments)); | ||
// We assume that test-fs-utime.js has run successfully before this | ||
// We assume that test-fs-utime.js has run successfully before this | ||
// test and so we omit several duplicate tests. | ||
@@ -176,3 +183,4 @@ | ||
tests_ok++; | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
console.log(' Unable to create test data file %j', file_path); | ||
@@ -183,3 +191,3 @@ console.log(' Error was: %j', e); | ||
if ( tests_run !== tests_ok ) { | ||
if ( tests_run !== tests_ok ) { | ||
process.exit(1); | ||
@@ -192,4 +200,4 @@ } | ||
var how_many_times, | ||
how_many_secs, | ||
how_many_done; | ||
how_many_secs, | ||
how_many_done; | ||
@@ -204,8 +212,8 @@ | ||
// Repeat a successful utimeSync() call | ||
if( 1 ) { | ||
// Repeat a successful utimeSync() call | ||
if ( 1 ) { | ||
how_many_times = 1000000; | ||
//how_many_times = 4; | ||
for( var i=0 ; i<how_many_times ; i++ ) { | ||
for ( var i=0 ; i<how_many_times ; i++ ) { | ||
tests_run++; | ||
@@ -223,8 +231,8 @@ result = err = undefined; | ||
// Repeat an failing utimeSync() call | ||
if( 1 ) { | ||
// Repeat an failing utimeSync() call | ||
if ( 1 ) { | ||
how_many_times = 1000000; | ||
//how_many_times = 4; | ||
for( var i=0 ; i<how_many_times ; i++ ) { | ||
for ( var j=0 ; j<how_many_times ; j++ ) { | ||
tests_run++; | ||
@@ -234,3 +242,4 @@ result = err = undefined; | ||
result = fs.utimeSync(file_path_not, atime_req, mtime_req); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -249,3 +258,3 @@ } | ||
// Repeat a successful utime() call | ||
// Repeat a successful utime() call | ||
if (1) { | ||
@@ -273,5 +282,6 @@ how_many_times = 1000000; | ||
}); | ||
} else { | ||
} | ||
else { | ||
test_failing_utime(); | ||
} | ||
} | ||
@@ -278,0 +288,0 @@ |
@@ -0,7 +1,8 @@ | ||
"use strict"; | ||
// Test these APIs as published in extension module 'fs-ext' | ||
// | ||
// fs.utime(path, | ||
// fs.utime(path, | ||
// | ||
// fs.utimeSync(path, | ||
// fs.utimeSync(path, | ||
// | ||
@@ -25,5 +26,5 @@ // Synchronous utime(2). Throws an exception on error. | ||
var assert = require('assert'), | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
path = require('path'), | ||
util = require('util'), | ||
fs = require('../fs-ext'); | ||
@@ -34,11 +35,11 @@ var tests_ok = 0; | ||
var debug_me = true; | ||
debug_me = false; | ||
debug_me = false; | ||
var tmp_dir = "/tmp", | ||
file_path = path.join(tmp_dir, 'what.when.utime.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.utime.test'); | ||
file_path = path.join(tmp_dir, 'what.when.utime.test'), | ||
file_path_not = path.join(tmp_dir, 'what.not.utime.test'); | ||
var file_fd, | ||
result, | ||
err; | ||
result, | ||
err; | ||
@@ -70,3 +71,4 @@ | ||
fs.unlinkSync(file_path); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not exist, that's okay. | ||
@@ -77,3 +79,4 @@ } | ||
fs.unlinkSync(file_path_not); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
// might not exist, that's okay. | ||
@@ -97,12 +100,17 @@ } | ||
fault_msg = api_name + '(): returned error ' + err.message; | ||
} else { | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned error ' + err; | ||
} | ||
} else if ( atime_seen == atime_old ) { | ||
} | ||
else if ( atime_seen == atime_old ) { | ||
fault_msg = api_name + '(): atime was unchanged'; | ||
} else if ( mtime_seen == mtime_old ) { | ||
} | ||
else if ( mtime_seen == mtime_old ) { | ||
fault_msg = api_name + '(): mtime was unchanged'; | ||
} else if ( atime_seen !== atime_req ) { | ||
} | ||
else if ( atime_seen !== atime_req ) { | ||
fault_msg = api_name + '(): atime not correct result'; | ||
} else if ( mtime_seen !== mtime_req ) { | ||
} | ||
else if ( mtime_seen !== mtime_req ) { | ||
fault_msg = api_name + '(): mtime not correct result'; | ||
@@ -114,3 +122,4 @@ } | ||
if (debug_me) console.log(' OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
//XXX Create array from arguments adding xtime_req, xtime_seen to end? | ||
@@ -132,13 +141,16 @@ console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
if ( err.code !== expected_errno ) { | ||
fault_msg = api_name + '(): returned wrong errno \'' + err.message + | ||
fault_msg = api_name + '(): returned wrong errno \'' + err.message + | ||
'\' (expecting ' + expected_errno + ')'; | ||
} | ||
} else { | ||
} | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned wrong error \'' + err + '\''; | ||
} | ||
} else { | ||
} | ||
else { | ||
fault_msg = api_name + '(): returned wrong error \'' + err + '\''; | ||
} | ||
} else { | ||
fault_msg = api_name + '(): expected errno \'' + expected_errno + | ||
} | ||
else { | ||
fault_msg = api_name + '(): expected errno \'' + expected_errno + | ||
'\', but got result ' + value_seen; | ||
@@ -150,3 +162,4 @@ } | ||
if (debug_me) console.log(' FAILED OK: ' + api_name ); | ||
} else { | ||
} | ||
else { | ||
console.log('FAILURE: ' + arguments.callee.name + ': ' + fault_msg); | ||
@@ -167,4 +180,5 @@ //if (debug_me) console.log(' ARGS: ', util.inspect(arguments)); | ||
if ( typeof fs.utime !== 'function' ) { | ||
console.log('fs.utime API is missing'); | ||
} else { | ||
console.log('fs.utime API is missing'); | ||
} | ||
else { | ||
tests_ok++; | ||
@@ -176,3 +190,4 @@ } | ||
console.log('fs.utimeSync API is missing'); | ||
} else { | ||
} | ||
else { | ||
tests_ok++; | ||
@@ -182,3 +197,3 @@ } | ||
// If any pre-checks and setup fail, quit before tests | ||
if ( tests_run !== tests_ok ) { | ||
if ( tests_run !== tests_ok ) { | ||
process.exit(2); | ||
@@ -194,6 +209,7 @@ } | ||
try { | ||
var file_fd = fs.openSync(file_path, 'w'); | ||
file_fd = fs.openSync(file_path, 'w'); | ||
fs.closeSync(file_fd); | ||
tests_ok++; | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
console.log(' Unable to create test data file %j', file_path); | ||
@@ -205,4 +221,4 @@ console.log(' Error was: %j', e); | ||
var atime_old, mtime_old, | ||
atime_req, mtime_req, | ||
atime_seen, mtime_seen; | ||
atime_req, mtime_req, | ||
atime_seen, mtime_seen; | ||
@@ -239,2 +255,3 @@ function debug_show_times() { | ||
function check_results(test_path) { | ||
var api_name; // Declared because it's used below but this seems to be stale code | ||
get_times_seen(test_path); | ||
@@ -269,3 +286,3 @@ console.log(' atime/mtime old %d %d', atime_old, mtime_old ); | ||
// Use wrong filename to get 'ENOENT' error | ||
// Use wrong filename to get 'ENOENT' error | ||
@@ -277,3 +294,4 @@ setup_test_values( 0, 0 ); | ||
result = fs.utimeSync(file_path_not, atime_req, mtime_req); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -293,3 +311,4 @@ } | ||
result = fs.utimeSync(file_path); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -309,3 +328,4 @@ } | ||
result = fs.utimeSync(file_path, atime_req, mtime_req); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -326,3 +346,4 @@ } | ||
result = fs.utimeSync(file_path, atime_req, mtime_req); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -341,3 +362,4 @@ } | ||
result = fs.utimeSync(file_path, atime_req, mtime_req); | ||
} catch (e) { | ||
} | ||
catch (e) { | ||
err = e; | ||
@@ -361,4 +383,4 @@ } | ||
// Set to 'now' | ||
setup_test_values( date2unixtime(new Date()), | ||
// Set to 'now' | ||
setup_test_values( date2unixtime(new Date()), | ||
date2unixtime(new Date())); | ||
@@ -371,3 +393,3 @@ tests_run++; | ||
// Use wrong filename to get 'ENOENT' error | ||
// Use wrong filename to get 'ENOENT' error | ||
setup_test_values( date2unixtime(new Date('1999-01-01 01:01:00 UTC')), | ||
@@ -374,0 +396,0 @@ date2unixtime(new Date('1999-01-01 01:01:01 UTC'))); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
94638
2.51%21
16.67%2224
6.51%1
Infinity%