From 44dde5f24cf53ca1b01b5a4307dc861d53a53f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Mon, 8 Mar 2010 19:02:19 +0100 Subject: [PATCH] Remove fs/path globals from test suite It is way too easy to not notice bugs due to those modules being exported as globals while running the test suite. See: http://github.com/ry/node/issues#issue/75 --- test/common.js | 4 +--- test/simple/test-chdir.js | 8 +++----- test/simple/test-eio-race2.js | 1 + test/simple/test-eio-race4.js | 2 +- test/simple/test-file-read-noexist.js | 2 ++ test/simple/test-file-read-stream.js | 2 ++ test/simple/test-file-write-stream.js | 2 ++ test/simple/test-fs-chmod.js | 3 ++- test/simple/test-fs-realpath.js | 3 ++- test/simple/test-fs-stat.js | 2 +- test/simple/test-fs-symlink.js | 3 ++- test/simple/test-fs-write.js | 3 ++- test/simple/test-ini.js | 3 ++- test/simple/test-mkdir-rmdir.js | 2 ++ test/simple/test-module-loading.js | 1 + test/simple/test-readdir.js | 2 ++ test/simple/test-stdio.js | 1 + test/simple/test-stdout-flush.js | 1 + test/simple/test-sync-fileread.js | 2 ++ 19 files changed, 32 insertions(+), 15 deletions(-) diff --git a/test/common.js b/test/common.js index 6f7a4e1c77..035fe7a00b 100644 --- a/test/common.js +++ b/test/common.js @@ -11,6 +11,4 @@ var assert = require('assert'); var sys = require("sys"); process.mixin(exports, sys); -exports.assert = require('assert'); -exports.fs = require("fs"); -exports.path = path; +exports.assert = require('assert'); \ No newline at end of file diff --git a/test/simple/test-chdir.js b/test/simple/test-chdir.js index 1fd58ddaf6..12ade044b6 100644 --- a/test/simple/test-chdir.js +++ b/test/simple/test-chdir.js @@ -1,9 +1,7 @@ process.mixin(require("../common")); -var dirname = path.dirname(__filename); +assert.equal(true, process.cwd() !== __dirname); -assert.equal(true, process.cwd() !== dirname); +process.chdir(__dirname); -process.chdir(dirname); - -assert.equal(true, process.cwd() === dirname); +assert.equal(true, process.cwd() === __dirname); diff --git a/test/simple/test-eio-race2.js b/test/simple/test-eio-race2.js index 11f989a61a..c96aa8c473 100644 --- a/test/simple/test-eio-race2.js +++ b/test/simple/test-eio-race2.js @@ -1,4 +1,5 @@ process.mixin(require("../common")); +var path = require('path'); var testTxt = path.join(fixturesDir, "x.txt"); var fs = require('fs'); diff --git a/test/simple/test-eio-race4.js b/test/simple/test-eio-race4.js index 1792798284..f5fb65a8ee 100644 --- a/test/simple/test-eio-race4.js +++ b/test/simple/test-eio-race4.js @@ -1,5 +1,5 @@ process.mixin(require("../common")); - +var fs = require('fs'); var N = 100; var j = 0; diff --git a/test/simple/test-file-read-noexist.js b/test/simple/test-file-read-noexist.js index a68c4662c6..ae162f2a97 100644 --- a/test/simple/test-file-read-noexist.js +++ b/test/simple/test-file-read-noexist.js @@ -1,4 +1,6 @@ process.mixin(require("../common")); +var path = require('path'); +var fs = require('fs'); var got_error = false; var filename = path.join(fixturesDir, "does_not_exist.txt"); diff --git a/test/simple/test-file-read-stream.js b/test/simple/test-file-read-stream.js index 445957f6dc..ab41487090 100644 --- a/test/simple/test-file-read-stream.js +++ b/test/simple/test-file-read-stream.js @@ -1,6 +1,8 @@ process.mixin(require('../common')); var + path = require('path'), + fs = require('fs'), fn = path.join(fixturesDir, 'multipart.js'), file = fs.createReadStream(fn), diff --git a/test/simple/test-file-write-stream.js b/test/simple/test-file-write-stream.js index bb74db58a2..60f693a222 100644 --- a/test/simple/test-file-write-stream.js +++ b/test/simple/test-file-write-stream.js @@ -1,6 +1,8 @@ process.mixin(require('../common')); var + path = require('path'), + fs = require('fs'), fn = path.join(fixturesDir, "write.txt"), file = fs.createWriteStream(fn), diff --git a/test/simple/test-fs-chmod.js b/test/simple/test-fs-chmod.js index c4a7829b15..7b6cd52b92 100644 --- a/test/simple/test-fs-chmod.js +++ b/test/simple/test-fs-chmod.js @@ -1,5 +1,6 @@ process.mixin(require("../common")); - +var path = require('path'); +var fs = require('fs'); var got_error = false; var success_count = 0; diff --git a/test/simple/test-fs-realpath.js b/test/simple/test-fs-realpath.js index d6c1c3fc89..7efb0b4509 100644 --- a/test/simple/test-fs-realpath.js +++ b/test/simple/test-fs-realpath.js @@ -1,5 +1,6 @@ process.mixin(require("../common")); - +var fs = require('fs'); +var path = require('path'); var async_completed = 0, async_expected = 0, unlink = []; function asynctest(testBlock, args, callback, assertBlock) { diff --git a/test/simple/test-fs-stat.js b/test/simple/test-fs-stat.js index 088ad696a9..3f85032cef 100644 --- a/test/simple/test-fs-stat.js +++ b/test/simple/test-fs-stat.js @@ -1,5 +1,5 @@ process.mixin(require("../common")); - +var fs = require('fs'); var got_error = false; var success_count = 0; diff --git a/test/simple/test-fs-symlink.js b/test/simple/test-fs-symlink.js index ac9a3ab803..79eedb90e4 100644 --- a/test/simple/test-fs-symlink.js +++ b/test/simple/test-fs-symlink.js @@ -1,5 +1,6 @@ process.mixin(require("../common")); - +var path = require('path'); +var fs = require('fs'); var completed = 0; // test creating and reading symbolic link diff --git a/test/simple/test-fs-write.js b/test/simple/test-fs-write.js index d2bd1d581e..4670570ab3 100644 --- a/test/simple/test-fs-write.js +++ b/test/simple/test-fs-write.js @@ -1,5 +1,6 @@ process.mixin(require("../common")); - +var path = require('path'); +var fs = require('fs'); var fn = path.join(fixturesDir, "write.txt"); var expected = "hello"; var found; diff --git a/test/simple/test-ini.js b/test/simple/test-ini.js index 820bb34a3f..c9d0f8897f 100644 --- a/test/simple/test-ini.js +++ b/test/simple/test-ini.js @@ -1,5 +1,6 @@ process.mixin(require("../common")); -require("fs"); +var path = require('path'); +var fs = require("fs"); parse = require("ini").parse; debug("load fixtures/fixture.ini"); diff --git a/test/simple/test-mkdir-rmdir.js b/test/simple/test-mkdir-rmdir.js index b19d6ac295..24e8835991 100644 --- a/test/simple/test-mkdir-rmdir.js +++ b/test/simple/test-mkdir-rmdir.js @@ -1,4 +1,6 @@ process.mixin(require("../common")); +var path = require('path'); +var fs = require('fs'); var dirname = path.dirname(__filename); var fixtures = path.join(dirname, "../fixtures"); diff --git a/test/simple/test-module-loading.js b/test/simple/test-module-loading.js index 0c453b6d72..1d796d0324 100644 --- a/test/simple/test-module-loading.js +++ b/test/simple/test-module-loading.js @@ -1,4 +1,5 @@ process.mixin(require("../common")); +var path = require('path'); debug("load test-module-loading.js"); diff --git a/test/simple/test-readdir.js b/test/simple/test-readdir.js index c65b06d5f0..67d1151c11 100644 --- a/test/simple/test-readdir.js +++ b/test/simple/test-readdir.js @@ -1,4 +1,6 @@ process.mixin(require("../common")); +var path = require('path'); +var fs = require('fs'); var got_error = false, readdirDir = path.join(fixturesDir, "readdir") diff --git a/test/simple/test-stdio.js b/test/simple/test-stdio.js index e30378c868..c88774a9a2 100644 --- a/test/simple/test-stdio.js +++ b/test/simple/test-stdio.js @@ -1,4 +1,5 @@ process.mixin(require("../common")); +var path = require('path'); var sub = path.join(fixturesDir, 'echo.js'); diff --git a/test/simple/test-stdout-flush.js b/test/simple/test-stdout-flush.js index 38f61d9084..fe0273fc62 100644 --- a/test/simple/test-stdout-flush.js +++ b/test/simple/test-stdout-flush.js @@ -1,4 +1,5 @@ process.mixin(require("../common")); +var path = require('path'); var sub = path.join(fixturesDir, 'print-chars.js'); diff --git a/test/simple/test-sync-fileread.js b/test/simple/test-sync-fileread.js index adbe2e84a6..318d0621bd 100644 --- a/test/simple/test-sync-fileread.js +++ b/test/simple/test-sync-fileread.js @@ -1,4 +1,6 @@ process.mixin(require('../common')); +var path = require('path'); +var fs = require('fs'); var fixture = path.join(__dirname, "../fixtures/x.txt");