Skip to content

Commit

Permalink
Added unit test for util.getNonBlockingReadSize() (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
poire-z committed Sep 17, 2017
1 parent 8f7d39b commit dd2013f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ read_globals = {

exclude_files = {
"build/*",
"spec/*",
"thirdparty/*",
}

files["spec/unit/*"].std = "+busted"

-- TODO: clean up and enforce max line width (631)
ignore = {
"631",
Expand Down
22 changes: 21 additions & 1 deletion spec/unit/util_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe("util module", function()

describe("util.purgeDir", function()
it("should error out on non-exists directory", function()
ok, err = util.purgeDir('/tmp/123/abc/567/foobar')
local ok, err = util.purgeDir('/tmp/123/abc/567/foobar')
assert.is_nil(ok)
assert.is_not_nil(err)
end)
Expand All @@ -160,4 +160,24 @@ describe("util module", function()
assert.is_not_nil(err)
end)
end)

describe("util.getNonBlockingReadSize", function()
it("should read pipe when data is available", function()
if not util.isAndroid() then
local std_out = io.popen("sleep 3; echo 'done'", "r")
assert.are.equal(util.getNonBlockingReadSize(std_out), 0)
util.sleep(1)
assert.are.equal(util.getNonBlockingReadSize(std_out), 0)
util.sleep(1)
assert.are.equal(util.getNonBlockingReadSize(std_out), 0)
util.sleep(2)
assert.are.equal(util.getNonBlockingReadSize(std_out), 5)
local startsec = util.gettime()
local data = std_out:read("*all")
local donesec = util.gettime()
assert.are.equal(data, "done\n")
assert.is_true(donesec - startsec <= 1)
end
end)
end)
end)

0 comments on commit dd2013f

Please sign in to comment.