summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormpeterv <mpeterval@gmail.com>2016-04-18 15:22:36 +0300
committermpeterv <mpeterval@gmail.com>2016-04-18 15:28:51 +0300
commit685081ca75271014c35d22083f8cd255512e1a1f (patch)
tree1ce2498dd9d43b59091701383606803643aa4822
parent59663e20d1d59b15c5032a64155e89d54e5d490a (diff)
downloadluacov-685081ca75271014c35d22083f8cd255512e1a1f.tar.gz
Port CLI test for Windows
-rw-r--r--tests/cli.lua25
-rw-r--r--tests/nested/test.lua6
2 files changed, 18 insertions, 13 deletions
diff --git a/tests/cli.lua b/tests/cli.lua
index 4f7370d..4e31fb1 100644
--- a/tests/cli.lua
+++ b/tests/cli.lua
@@ -1,9 +1,10 @@
+local dir_sep = package.config:sub(1, 1)
local lua = arg[-1] or "lua"
-local slash = lua:find("/")
+local slash = lua:find(dir_sep)
-- Correct lua path so that it can be used from test directories.
if slash and slash ~= 1 then
- lua = "../../" .. lua
+ lua = ".." .. dir_sep .. ".." .. dir_sep .. lua
end
local ntests = 0
@@ -26,21 +27,23 @@ end
-- flags will be passed to luacov.
local function test(dir, expected_file, flags)
ntests = ntests + 1
- local test_dir = "tests/" .. dir
+ local test_dir = "tests" .. dir_sep .. dir
expected_file = expected_file or "expected.out"
flags = flags or ""
- os.remove(test_dir .. "/luacov.stats.out")
- os.remove(test_dir .. "/luacov.report.out")
+ os.remove(test_dir .. dir_sep .. "luacov.stats.out")
+ os.remove(test_dir .. dir_sep .. "luacov.report.out")
local init_lua = "package.path=[[?.lua;../../src/?.lua;]]..package.path; corowrap = coroutine.wrap"
+ init_lua = init_lua:gsub("/", dir_sep)
exec(("cd %q && %q -e %q -lluacov test.lua"):format(
test_dir, lua, init_lua))
- exec(("cd %q && %q -e %q ../../src/bin/luacov %s"):format(
- test_dir, lua, init_lua, flags))
+ local luacov_path = ("../../src/bin/luacov"):gsub("/", dir_sep)
+ exec(("cd %q && %q -e %q %s %s"):format(
+ test_dir, lua, init_lua, luacov_path, flags))
- expected_file = test_dir .. "/" .. expected_file
+ expected_file = test_dir .. dir_sep .. expected_file
local expected = read(expected_file)
- local actual_file = test_dir .. "/luacov.report.out"
+ local actual_file = test_dir .. dir_sep .. "luacov.report.out"
local actual = read(actual_file)
local ok
@@ -53,8 +56,8 @@ local function test(dir, expected_file, flags)
end
assert(ok, ("CLI test #%d failed (%s ~= %s)"):format(ntests, actual_file, expected_file))
- os.remove(test_dir .. "/luacov.stats.out")
- os.remove(test_dir .. "/luacov.report.out")
+ os.remove(test_dir .. dir_sep .. "luacov.stats.out")
+ os.remove(test_dir .. dir_sep .. "luacov.report.out")
end
test("simple")
diff --git a/tests/nested/test.lua b/tests/nested/test.lua
index d9d4e49..3155321 100644
--- a/tests/nested/test.lua
+++ b/tests/nested/test.lua
@@ -3,11 +3,12 @@ local luacov = require "luacov.runner"
testlib.f1()
+local dir_sep = package.config:sub(1, 1)
local cmd = arg[-5] or "lua"
-local slash = cmd:find("/")
+local slash = cmd:find(dir_sep)
if slash and slash ~= 1 then
- cmd = "../" .. cmd
+ cmd = ".." .. dir_sep .. cmd
end
cmd = cmd .. " -e 'package.path=[[../?.lua;../../../src/?.lua;]]'"
@@ -15,6 +16,7 @@ cmd = cmd .. " -e 'osexit = os.exit'"
cmd = cmd .. " -e 'require([[luacov.runner]]).load_config({statsfile = [[../luacov.stats.out]], savestepsize = 1})'"
cmd = cmd .. " -l luacov.tick"
cmd = cmd .. " -e 'dofile([[script.lua]])'"
+cmd = cmd:gsub("/", dir_sep)
local ok = os.execute("cd subdir && " .. cmd)
assert(ok == 0 or ok == true)