Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Better temporary directory handling for tests.
Browse files Browse the repository at this point in the history
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
isaacs authored and ry committed Sep 10, 2010
1 parent c86f3c5 commit c099e27
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions test/common.js
Expand Up @@ -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');
Expand Down
12 changes: 4 additions & 8 deletions 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');
Expand All @@ -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');
Expand All @@ -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);
});

3 changes: 1 addition & 2 deletions test/simple/test-mkdir-rmdir.js
Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion test/simple/testcfg.py
Expand Up @@ -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

Expand All @@ -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())

Expand Down
11 changes: 10 additions & 1 deletion tools/test.py
Expand Up @@ -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):
Expand Down

0 comments on commit c099e27

Please sign in to comment.