aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/process_spec.lua
blob: 38ea94de8ac7f1a94565d8d795d451a359145e2e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
local match = require "luassert.match"
local process = require "mason-core.process"
local spy = require "luassert.spy"

describe("process.spawn", function()
    -- Unix only
    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, 0, match.is_number())
                assert.equals(table.concat(stdio.buffers.stdout, ""), "HELLO=world\nMY_ENV=var\n")
            end)
        end)
    )
end)