diff options
author | mpeterv <mpeterval@gmail.com> | 2016-04-17 14:50:04 +0300 |
---|---|---|
committer | mpeterv <mpeterval@gmail.com> | 2016-04-17 15:23:16 +0300 |
commit | 933c68092a8e9667dbd4bef9fdf4bb2d325ccb12 (patch) | |
tree | 65b3ac9adea88dd3ae90514b3eb7c59e0a7411e0 | |
parent | 73874505c05821494b79272e4e092ba86e20c39e (diff) | |
download | luacov-933c68092a8e9667dbd4bef9fdf4bb2d325ccb12.tar.gz |
Add a test for nested luacov execution
TODO: fix luacov.tick not working since 2012 or so when
`module` calls (that set package.loaded earlier than `require`) were
removed.
-rw-r--r-- | tests/cli.lua | 2 | ||||
-rw-r--r-- | tests/nested/.luacov | 5 | ||||
-rw-r--r-- | tests/nested/expected.out | 28 | ||||
-rw-r--r-- | tests/nested/subdir/script.lua | 5 | ||||
-rw-r--r-- | tests/nested/test.lua | 26 | ||||
-rw-r--r-- | tests/nested/testlib.lua | 16 |
6 files changed, 82 insertions, 0 deletions
diff --git a/tests/cli.lua b/tests/cli.lua index 93da5da..528aa02 100644 --- a/tests/cli.lua +++ b/tests/cli.lua @@ -66,4 +66,6 @@ test("coroutines") test("hook") +test("nested") + print(("%d CLI tests passed."):format(ntests)) diff --git a/tests/nested/.luacov b/tests/nested/.luacov new file mode 100644 index 0000000..7dbefb5 --- /dev/null +++ b/tests/nested/.luacov @@ -0,0 +1,5 @@ +return { + modules = { + testlib = "testlib.lua" + } +} diff --git a/tests/nested/expected.out b/tests/nested/expected.out new file mode 100644 index 0000000..28784b2 --- /dev/null +++ b/tests/nested/expected.out @@ -0,0 +1,28 @@ + +============================================================================== +testlib.lua +============================================================================== + 2 local a = 1 + 2 local b = 2 + + 2 local lib = {} + + 2 function lib.f1() + 2 local c = 3 + 2 return 4 + end + + 2 function lib.f2() + 3 local d = 5 + 3 return 6 + end + + 2 return lib + +============================================================================== +Summary +============================================================================== + +10 0 100.00% testlib.lua +------------------------ +10 0 100.00% diff --git a/tests/nested/subdir/script.lua b/tests/nested/subdir/script.lua new file mode 100644 index 0000000..ef278a2 --- /dev/null +++ b/tests/nested/subdir/script.lua @@ -0,0 +1,5 @@ +local testlib = require "testlib" +testlib.f1() +testlib.f2() +testlib.f2() +os.exit() diff --git a/tests/nested/test.lua b/tests/nested/test.lua new file mode 100644 index 0000000..67a5e72 --- /dev/null +++ b/tests/nested/test.lua @@ -0,0 +1,26 @@ +local testlib = require "testlib" +local luacov = require "luacov.runner" + +testlib.f1() + +luacov.pause() + +local cmd = arg[-5] or "lua" +local slash = cmd:find("/") + +if slash and slash ~= 1 then + cmd = "../" .. cmd +end + +cmd = cmd .. " -e 'package.path=[[../?.lua;../../../src/?.lua;]]'" +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]])'" + +local ok = os.execute("cd subdir && " .. cmd) +assert(ok == 0 or ok == true) + +luacov.resume() + +testlib.f2() diff --git a/tests/nested/testlib.lua b/tests/nested/testlib.lua new file mode 100644 index 0000000..2733f71 --- /dev/null +++ b/tests/nested/testlib.lua @@ -0,0 +1,16 @@ +local a = 1 +local b = 2 + +local lib = {} + +function lib.f1() + local c = 3 + return 4 +end + +function lib.f2() + local d = 5 + return 6 +end + +return lib |