Skip to content
Browse files

add initial pass to a test runner

  • Loading branch information...
1 parent 6dfb948 commit a93a500c2af1a8447dc49a7b8804381a6d9f12b0 @rphillips rphillips committed with pquerna
Showing with 110 additions and 3 deletions.
  1. +5 −0 luvit.gyp
  2. +7 −3 tests/modules/helper.lua
  3. +76 −0 tests/runner.lua
  4. +22 −0 tests/test.gyp
View
5 luvit.gyp
@@ -87,5 +87,10 @@
}
],
},
+ {
+ 'target_name': 'test',
+ 'type': 'none',
+ 'dependencies': [ 'tests/test.gyp:*' ],
+ },
],
}
View
10 tests/modules/helper.lua
@@ -19,7 +19,6 @@ limitations under the License.
local Debug = require('debug')
local Utils = require('utils')
local source = Debug.getinfo(3, "S").source:sub(2)
-print_stderr("Running " .. Utils.color("Bblue") .. source .. Utils.color() .. "... ")
local table_concat = require('table').concat
local expectations = {}
@@ -49,10 +48,11 @@ process:on('exit', function (code, signal)
end
if #errors > 0 then
print_stderr(Utils.color("Bred") .. "FAIL" .. Utils.color() .. "\n")
-
error("\n" .. source .. ":on_exit:" .. table_concat(errors, ""))
+ exit_process(1)
end
print_stderr(Utils.color("Bgreen") .. "PASS" .. Utils.color() .. "\n")
+ exit_process(0)
end)
@@ -68,6 +68,10 @@ _G.deep_equal = function(expected, actual)
end
return true
else
- return equal(expected, actual)
+ local rv = equal(expected, actual)
+ if rv == false then
+ exit_process(1)
+ end
end
end
+
View
76 tests/runner.lua
@@ -0,0 +1,76 @@
+local Process = require('process')
+local Utils = require('utils')
+local Fs = require('fs')
+local string = require('string')
+local table = require('table')
+
+local results = {}
+
+local async = {}
+async.forEachSeries = function(arr, iterator, callback)
+ if #arr == 0 then
+ return callback()
+ end
+ local completed = 0
+ local iterate
+ iterate = function()
+ iterator(arr[completed + 1], function(err)
+ if err then
+ callback(err)
+ callback = function() end
+ else
+ completed = completed + 1
+ if completed == #arr then
+ callback()
+ else
+ iterate()
+ end
+ end
+ end)
+ end
+ iterate()
+end
+
+local function run_test(filename, callback)
+ results[filename] = {}
+ results[filename].stdout_data = ''
+ results[filename].stderr_data = ''
+ results[filename].filename = filename
+ local child = Process.spawn(process.argv[0], {filename}, {})
+ child:on('exit', function (exit_status, term_signal)
+ results[filename].exit_status = exit_status
+ callback()
+ end)
+ child.stdout:on("data", function (chunk)
+ results[filename].stdout_data = results[filename].stdout_data .. chunk
+ end)
+ child.stderr:on("data", function (chunk)
+ results[filename].stderr_data = results[filename].stderr_data .. chunk
+ end)
+end
+
+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)
+ end
+ end
+
+ async.forEachSeries(test_files, run_test, function()
+ for k, v in pairs(results) do
+ if v.exit_status ~= 0 then
+ process.stdout:write(Utils.color("Bred") .. "FAIL (" .. v.filename .. ')' .. Utils.color() .. "\n")
+ process.stdout:write(v.stdout_data)
+ process.stdout:write(v.stderr_data)
+ else
+ process.stdout:write(Utils.color("Bgreen") .. 'PASS (' .. v.filename .. ')\n')
+ end
+ end
+ p('Tests completed')
+ end)
+end)
+
View
22 tests/test.gyp
@@ -0,0 +1,22 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'test',
+ 'type': 'none',
+ 'actions': [
+ {
+ 'action_name': 'test_runner',
+ 'inputs': [
+ '<(PRODUCT_DIR)/luvit',
+ 'runner.lua',
+ ],
+ 'outputs': [ '<(PRODUCT_DIR)/test-results.stamp' ],
+ 'action': [
+ '<(PRODUCT_DIR)/luvit',
+ 'runner.lua',
+ ],
+ }
+ ],
+ },
+ ]
+}

0 comments on commit a93a500

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