Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better temporary directory handling for tests.

Add a setUp and tearDown function to the test case class, and use it to
create and remove the test/tmp directory for each test.

TODO: amend other tests.
  • Loading branch information...
commit c099e274d2e428e93227ce11ae0f81cddc1204f4 1 parent c86f3c5
@isaacs isaacs authored ry committed
View
1  test/common.js
@@ -3,6 +3,7 @@ var path = require("path");
exports.testDir = path.dirname(__filename);
exports.fixturesDir = path.join(exports.testDir, "fixtures");
exports.libDir = path.join(exports.testDir, "../lib");
+exports.tmpDir = path.join(exports.testDir, "tmp");
exports.PORT = 12346;
exports.assert = require('assert');
View
12 test/simple/test-fs-symlink.js
@@ -1,13 +1,12 @@
common = require("../common");
-assert = common.assert
+var assert = common.assert;
var path = require('path');
var fs = require('fs');
var completed = 0;
// test creating and reading symbolic link
-var linkData = "../../cycles/root.js";
-var linkPath = path.join(common.fixturesDir, "nested-index", 'one', 'symlink1.js');
-try {fs.unlinkSync(linkPath);}catch(e){}
+var linkData = path.join(common.fixturesDir, "/cycles/root.js");
+var linkPath = path.join(common.tmpDir, 'symlink1.js');
fs.symlink(linkData, linkPath, function(err){
if (err) throw err;
console.log('symlink done');
@@ -21,8 +20,7 @@ fs.symlink(linkData, linkPath, function(err){
// test creating and reading hard link
var srcPath = path.join(common.fixturesDir, "cycles", 'root.js');
-var dstPath = path.join(common.fixturesDir, "nested-index", 'one', 'link1.js');
-try {fs.unlinkSync(dstPath);}catch(e){}
+var dstPath = path.join(common.tmpDir, 'link1.js');
fs.link(srcPath, dstPath, function(err){
if (err) throw err;
console.log('hard link done');
@@ -33,8 +31,6 @@ fs.link(srcPath, dstPath, function(err){
});
process.addListener("exit", function () {
- try {fs.unlinkSync(linkPath);}catch(e){}
- try {fs.unlinkSync(dstPath);}catch(e){}
assert.equal(completed, 2);
});
View
3  test/simple/test-mkdir-rmdir.js
@@ -4,8 +4,7 @@ var path = require('path');
var fs = require('fs');
var dirname = path.dirname(__filename);
-var fixtures = path.join(dirname, "../fixtures");
-var d = path.join(fixtures, "dir");
+var d = path.join(common.tmpDir, "dir");
var mkdir_error = false;
var rmdir_error = false;
View
17 test/simple/testcfg.py
@@ -27,6 +27,9 @@
import test
import os
+import shutil
+from shutil import rmtree
+from os import mkdir
from os.path import join, dirname, exists
import re
@@ -42,7 +45,19 @@ def __init__(self, path, file, mode, context, config):
self.file = file
self.config = config
self.mode = mode
-
+
+ def tearDown(self):
+ try:
+ rmtree(join(dirname(self.config.root), 'tmp'))
+ except:
+ pass
+
+ def setUp(self):
+ try:
+ mkdir(join(dirname(self.config.root), 'tmp'))
+ except:
+ pass
+
def GetLabel(self):
return "%s %s" % (self.mode, self.GetName())
View
11 tools/test.py
@@ -359,7 +359,16 @@ def RunCommand(self, command):
return TestOutput(self, full_command, output)
def Run(self):
- return self.RunCommand(self.GetCommand())
+ self.setUp()
+ result = self.RunCommand(self.GetCommand())
+ self.tearDown()
+ return result
+
+ def setUp(self):
+ return
+
+ def tearDown(self):
+ return
class TestOutput(object):
Please sign in to comment.
Something went wrong with that request. Please try again.