aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-03-05 22:22:54 +0100
committerGitHub <noreply@github.com>2022-03-05 22:22:54 +0100
commit20e5dc0d10bb4d92d6f0c80a6057924ca2ce1e51 (patch)
tree6d004b451872a30015e090dda4dabb888a18ac19 /tests
parentremove npm install --production from ansiblels (#518) (diff)
downloadmason-20e5dc0d10bb4d92d6f0c80a6057924ca2ce1e51.tar
mason-20e5dc0d10bb4d92d6f0c80a6057924ca2ce1e51.tar.gz
mason-20e5dc0d10bb4d92d6f0c80a6057924ca2ce1e51.tar.bz2
mason-20e5dc0d10bb4d92d6f0c80a6057924ca2ce1e51.tar.lz
mason-20e5dc0d10bb4d92d6f0c80a6057924ca2ce1e51.tar.xz
mason-20e5dc0d10bb4d92d6f0c80a6057924ca2ce1e51.tar.zst
mason-20e5dc0d10bb4d92d6f0c80a6057924ca2ce1e51.zip
async: raise errors instead of returning pcall-style (#521)
Diffstat (limited to 'tests')
-rw-r--r--tests/core/async_spec.lua46
-rw-r--r--tests/core/process_spec.lua2
2 files changed, 41 insertions, 7 deletions
diff --git a/tests/core/async_spec.lua b/tests/core/async_spec.lua
index 7d965e9b..88af14af 100644
--- a/tests/core/async_spec.lua
+++ b/tests/core/async_spec.lua
@@ -24,18 +24,30 @@ describe("async", function()
"should wrap callback-style async functions",
async_test(function()
local stdio = process.in_memory_sink()
- local ok, success = a.promisify(process.spawn)("env", {
+ local success, exit_code = a.promisify(process.spawn)("env", {
args = {},
env = { "FOO=BAR", "BAR=BAZ" },
stdio_sink = stdio.sink,
})
- assert.is_true(ok)
assert.is_true(success)
+ assert.equals(0, exit_code)
assert.equals("FOO=BAR\nBAR=BAZ\n", table.concat(stdio.buffers.stdout, ""))
end)
)
it(
+ "should return all values",
+ async_test(function()
+ local val1, val2, val3 = a.wait(function(resolve)
+ resolve(1, 2, 3)
+ end)
+ assert.equals(1, val1)
+ assert.equals(2, val2)
+ assert.equals(3, val3)
+ end)
+ )
+
+ it(
"should cancel coroutine",
async_test(function()
local james_bond = spy.new()
@@ -50,13 +62,35 @@ describe("async", function()
)
it(
- "should reject if async function raises error",
+ "should raise error if async function raises error",
async_test(function()
- local ok, err = a.promisify(function()
+ local err = assert.has.errors(a.promisify(function()
error "something went wrong"
- end)()
- assert.is_false(ok)
+ end))
assert.is_true(match.has_match "something went wrong$"(err))
end)
)
+
+ it(
+ "should raise error if async function rejects",
+ async_test(function()
+ local err = assert.has.errors(function()
+ a.wait(function(_, reject)
+ reject "This is an error"
+ end)
+ end)
+ assert.equals("This is an error", err)
+ end)
+ )
+
+ it(
+ "should pass nil arguments to promisified functions",
+ async_test(function()
+ local fn = spy.new(function(_, _, _, _, _, _, _, cb)
+ cb()
+ end)
+ a.promisify(fn)(nil, 2, nil, 4, nil, nil, 7)
+ assert.spy(fn).was_called_with(nil, 2, nil, 4, nil, nil, 7, match.is_function())
+ end)
+ )
end)
diff --git a/tests/core/process_spec.lua b/tests/core/process_spec.lua
index 2db42865..3c76b462 100644
--- a/tests/core/process_spec.lua
+++ b/tests/core/process_spec.lua
@@ -79,7 +79,7 @@ describe("process.spawn", function()
assert.wait_for(function()
assert.spy(callback).was_called(1)
- assert.spy(callback).was_called_with(true)
+ assert.spy(callback).was_called_with(true, 0)
assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n")
end)
end)