From 12d97eeabf44c2dd2cf841db218aac449022143d Mon Sep 17 00:00:00 2001 From: William Boman Date: Mon, 21 Feb 2022 20:56:16 +0100 Subject: feat: add async module (#499) --- tests/core/process_spec.lua | 131 +++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 61 deletions(-) (limited to 'tests/core/process_spec.lua') diff --git a/tests/core/process_spec.lua b/tests/core/process_spec.lua index 17ff0822..2db42865 100644 --- a/tests/core/process_spec.lua +++ b/tests/core/process_spec.lua @@ -63,74 +63,83 @@ end) describe("process.spawn", function() -- Unix only - async.tests.it("should spawn command and feed output to sink", function() - local stdio = process.in_memory_sink() - local callback = spy.new() - process.spawn("env", { - args = {}, - env = { - "HELLO=world", - "MY_ENV=var", - }, - stdio_sink = stdio.sink, - }, callback) - - assert.wait_for(function() - assert.spy(callback).was_called(1) - assert.spy(callback).was_called_with(true) - assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n") + it( + "should spawn command and feed output to sink", + async_test(function() + local stdio = process.in_memory_sink() + local callback = spy.new() + process.spawn("env", { + args = {}, + env = { + "HELLO=world", + "MY_ENV=var", + }, + stdio_sink = stdio.sink, + }, callback) + + assert.wait_for(function() + assert.spy(callback).was_called(1) + assert.spy(callback).was_called_with(true) + assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n") + end) end) - end) + ) end) describe("process.chain", function() -- Unix only - async.tests.it("should chain commands", function() - local stdio = process.in_memory_sink() - local callback = spy.new() - - local c = process.chain { - env = { - "HELLO=world", - "MY_ENV=var", - }, - stdio_sink = stdio.sink, - } - - c.run("env", {}) - c.run("bash", { "-c", "echo Hello $HELLO" }) - c.spawn(callback) - - assert.wait_for(function() - assert.spy(callback).was_called(1) - assert.spy(callback).was_called_with(true) - assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\nHello world\n") + it( + "should chain commands", + async_test(function() + local stdio = process.in_memory_sink() + local callback = spy.new() + + local c = process.chain { + env = { + "HELLO=world", + "MY_ENV=var", + }, + stdio_sink = stdio.sink, + } + + c.run("env", {}) + c.run("bash", { "-c", "echo Hello $HELLO" }) + c.spawn(callback) + + assert.wait_for(function() + assert.spy(callback).was_called(1) + assert.spy(callback).was_called_with(true) + assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\nHello world\n") + end) end) - end) + ) -- Unix only - async.tests.it("should abort chain commands should one fail", function() - local stdio = process.in_memory_sink() - local callback = spy.new() - - local c = process.chain { - env = { - "HELLO=world", - "MY_ENV=var", - }, - stdio_sink = stdio.sink, - } - - c.run("env", {}) - c.run("bash", { "-c", ">&2 echo Uh oh; exit 1" }) - c.run("bash", { "-c", "echo Hello $HELLO" }) - c.spawn(callback) - - assert.wait_for(function() - assert.spy(callback).was_called(1) - assert.spy(callback).was_called_with(false) - assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n") - assert.equal(table.concat(stdio.buffers.stderr, ""), "Uh oh\n") + it( + "should abort chain commands should one fail", + async_test(function() + local stdio = process.in_memory_sink() + local callback = spy.new() + + local c = process.chain { + env = { + "HELLO=world", + "MY_ENV=var", + }, + stdio_sink = stdio.sink, + } + + c.run("env", {}) + c.run("bash", { "-c", ">&2 echo Uh oh; exit 1" }) + c.run("bash", { "-c", "echo Hello $HELLO" }) + c.spawn(callback) + + assert.wait_for(function() + assert.spy(callback).was_called(1) + assert.spy(callback).was_called_with(false) + assert.equal(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n") + assert.equal(table.concat(stdio.buffers.stderr, ""), "Uh oh\n") + end) end) - end) + ) end) -- cgit v1.2.3-70-g09d2