Skip to content
Browse files

tests: runner: create tmp dir in runner

Do what a65f08d did in luvit so you can run the runner directly with
luvit.
  • Loading branch information...
1 parent df582dd commit b54ea5b5421fd1a601521ed7f75b7bd669f034ee Brandon Philips committed Mar 21, 2012
Showing with 52 additions and 26 deletions.
  1. +45 −24 tests/runner.lua
  2. +7 −2 tests/test-pipe.lua
View
69 tests/runner.lua
@@ -3,6 +3,7 @@ local utils = require('utils')
local fs = require('fs')
local string = require('string')
local table = require('table')
+local path = require('path')
local results = {}
local ports = 10001
@@ -60,35 +61,55 @@ local function runTest(filename, callback)
end)
end
-fs.readdir('.', function(err, files)
- assert(err == nil)
- test_files = {}
+local function run(callback)
+ fs.readdir('.', function(err, files)
+ assert(err == nil)
+ test_files = {}
- for i, v in ipairs(files) do
- local _, _, ext = string.find(v, 'test-.*%.(.*)')
- if ext == 'lua' then
- table.insert(test_files, v)
+ for i, v in ipairs(files) do
+ local _, _, ext = string.find(v, 'test-.*%.(.*)')
+ if ext == 'lua' then
+ table.insert(test_files, v)
+ end
end
- end
- async.forEachSeries(test_files, runTest, function()
- local nerr = 0;
- local nran = 0;
+ async.forEachSeries(test_files, runTest, function()
+ local nerr = 0;
+ local nran = 0;
- for k, v in pairs(results) do
- nran = nran + 1
- if v.exit_status ~= 0 then
- nerr = nerr + 1
- process.stdout:write('\n\n')
- process.stdout:write(utils.color("Bred") .. "FAIL (" .. v.filename .. ')' .. utils.color() .. "\n")
- process.stdout:write(v.stdout_data)
- process.stdout:write(v.stderr_data)
+ for k, v in pairs(results) do
+ nran = nran + 1
+ if v.exit_status ~= 0 then
+ nerr = nerr + 1
+ process.stdout:write('\n\n')
+ process.stdout:write(utils.color("Bred") .. "FAIL (" .. v.filename .. ')' .. utils.color() .. "\n")
+ process.stdout:write(v.stdout_data)
+ process.stdout:write(v.stderr_data)
+ end
+ end
+ process.stdout:write('Done\n')
+ if nerr ~= 0 then
+ callback()
+ process.exit(1)
+ end
+ end)
+ end)
+end
+
+local tmp_dir = path.join(__dirname, 'tmp')
+local function remove_tmp(callback)
+ fs.readdir(tmp_dir, function(err, files)
+ if (files ~= nil) then
+ for i, v in ipairs(files) do
+ fs.unlinkSync(path.join(tmp_dir, v))
end
end
- process.stdout:write('Done\n')
- if nerr ~= 0 then
- process.exit(1)
- end
+ fs.rmdir(tmp_dir, callback)
end)
-end)
+end
+remove_tmp(function ()
+ fs.mkdir(tmp_dir, "0755", function()
+ run(remove_tmp)
+ end)
+end)
View
9 tests/test-pipe.lua
@@ -17,8 +17,13 @@ limitations under the License.
--]]
require("helper")
+local path = require('path')
+local fs = require('fs')
-local fp = require('fs').createReadStream('test-pipe.lua')
-local null = require('fs').createWriteStream('/dev/null')
+local tmp_file = path.join(__dirname, 'tmp', 'test_pipe')
+fs.writeFileSync(tmp_file, "")
+
+local fp = fs.createReadStream('test-pipe.lua')
+local null = fs.createWriteStream(tmp_file)
fp:pipe(null)
assert(true)

0 comments on commit b54ea5b

Please sign in to comment.
Something went wrong with that request. Please try again.