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.
This commit is contained in:
parent
7628905a9b
commit
85fb47c11c
@ -3,6 +3,7 @@ var path = require("path");
|
|||||||
exports.testDir = path.dirname(__filename);
|
exports.testDir = path.dirname(__filename);
|
||||||
exports.fixturesDir = path.join(exports.testDir, "fixtures");
|
exports.fixturesDir = path.join(exports.testDir, "fixtures");
|
||||||
exports.libDir = path.join(exports.testDir, "../lib");
|
exports.libDir = path.join(exports.testDir, "../lib");
|
||||||
|
exports.tmpDir = path.join(exports.testDir, "tmp");
|
||||||
exports.PORT = 12346;
|
exports.PORT = 12346;
|
||||||
|
|
||||||
exports.assert = require('assert');
|
exports.assert = require('assert');
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
common = require("../common");
|
common = require("../common");
|
||||||
assert = common.assert
|
var assert = common.assert;
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var completed = 0;
|
var completed = 0;
|
||||||
|
|
||||||
// test creating and reading symbolic link
|
// test creating and reading symbolic link
|
||||||
var linkData = "../../cycles/root.js";
|
var linkData = path.join(common.fixturesDir, "/cycles/root.js");
|
||||||
var linkPath = path.join(common.fixturesDir, "nested-index", 'one', 'symlink1.js');
|
var linkPath = path.join(common.tmpDir, 'symlink1.js');
|
||||||
try {fs.unlinkSync(linkPath);}catch(e){}
|
|
||||||
fs.symlink(linkData, linkPath, function(err){
|
fs.symlink(linkData, linkPath, function(err){
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log('symlink done');
|
console.log('symlink done');
|
||||||
@ -21,8 +20,7 @@ fs.symlink(linkData, linkPath, function(err){
|
|||||||
|
|
||||||
// test creating and reading hard link
|
// test creating and reading hard link
|
||||||
var srcPath = path.join(common.fixturesDir, "cycles", 'root.js');
|
var srcPath = path.join(common.fixturesDir, "cycles", 'root.js');
|
||||||
var dstPath = path.join(common.fixturesDir, "nested-index", 'one', 'link1.js');
|
var dstPath = path.join(common.tmpDir, 'link1.js');
|
||||||
try {fs.unlinkSync(dstPath);}catch(e){}
|
|
||||||
fs.link(srcPath, dstPath, function(err){
|
fs.link(srcPath, dstPath, function(err){
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log('hard link done');
|
console.log('hard link done');
|
||||||
@ -33,8 +31,6 @@ fs.link(srcPath, dstPath, function(err){
|
|||||||
});
|
});
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
try {fs.unlinkSync(linkPath);}catch(e){}
|
|
||||||
try {fs.unlinkSync(dstPath);}catch(e){}
|
|
||||||
assert.equal(completed, 2);
|
assert.equal(completed, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,8 +4,7 @@ var path = require('path');
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var dirname = path.dirname(__filename);
|
var dirname = path.dirname(__filename);
|
||||||
var fixtures = path.join(dirname, "../fixtures");
|
var d = path.join(common.tmpDir, "dir");
|
||||||
var d = path.join(fixtures, "dir");
|
|
||||||
|
|
||||||
var mkdir_error = false;
|
var mkdir_error = false;
|
||||||
var rmdir_error = false;
|
var rmdir_error = false;
|
||||||
|
@ -27,6 +27,9 @@
|
|||||||
|
|
||||||
import test
|
import test
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
from shutil import rmtree
|
||||||
|
from os import mkdir
|
||||||
from os.path import join, dirname, exists
|
from os.path import join, dirname, exists
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@ -42,7 +45,19 @@ class SimpleTestCase(test.TestCase):
|
|||||||
self.file = file
|
self.file = file
|
||||||
self.config = config
|
self.config = config
|
||||||
self.mode = mode
|
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):
|
def GetLabel(self):
|
||||||
return "%s %s" % (self.mode, self.GetName())
|
return "%s %s" % (self.mode, self.GetName())
|
||||||
|
|
||||||
|
@ -359,7 +359,16 @@ class TestCase(object):
|
|||||||
return TestOutput(self, full_command, output)
|
return TestOutput(self, full_command, output)
|
||||||
|
|
||||||
def Run(self):
|
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):
|
class TestOutput(object):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user