diff options
| author | William Boman <william@redwill.se> | 2025-02-16 17:07:22 +0100 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2025-02-19 12:15:49 +0100 |
| commit | 5063ba98dc220a754caf68e510fb192755b1bdf0 (patch) | |
| tree | 174abf2bd4339e3ea1db3652610469f3f09e24b2 /tests | |
| parent | feat(context): add ctx:fetch() (diff) | |
| download | mason-5063ba98dc220a754caf68e510fb192755b1bdf0.tar mason-5063ba98dc220a754caf68e510fb192755b1bdf0.tar.gz mason-5063ba98dc220a754caf68e510fb192755b1bdf0.tar.bz2 mason-5063ba98dc220a754caf68e510fb192755b1bdf0.tar.lz mason-5063ba98dc220a754caf68e510fb192755b1bdf0.tar.xz mason-5063ba98dc220a754caf68e510fb192755b1bdf0.tar.zst mason-5063ba98dc220a754caf68e510fb192755b1bdf0.zip | |
refactor: turn StdioSink into a proper class
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason-core/async/async_spec.lua | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/InstallRunner_spec.lua | 8 | ||||
| -rw-r--r-- | tests/mason-core/installer/managers/cargo_spec.lua | 5 | ||||
| -rw-r--r-- | tests/mason-core/installer/managers/composer_spec.lua | 5 | ||||
| -rw-r--r-- | tests/mason-core/installer/managers/gem_spec.lua | 5 | ||||
| -rw-r--r-- | tests/mason-core/installer/managers/golang_spec.lua | 5 | ||||
| -rw-r--r-- | tests/mason-core/installer/managers/luarocks_spec.lua | 5 | ||||
| -rw-r--r-- | tests/mason-core/installer/managers/npm_spec.lua | 4 | ||||
| -rw-r--r-- | tests/mason-core/installer/managers/nuget_spec.lua | 5 | ||||
| -rw-r--r-- | tests/mason-core/installer/managers/opam_spec.lua | 5 | ||||
| -rw-r--r-- | tests/mason-core/installer/managers/pypi_spec.lua | 13 | ||||
| -rw-r--r-- | tests/mason-core/process_spec.lua | 4 | ||||
| -rw-r--r-- | tests/mason-core/spawn_spec.lua | 22 |
13 files changed, 58 insertions, 32 deletions
diff --git a/tests/mason-core/async/async_spec.lua b/tests/mason-core/async/async_spec.lua index 79f74462..49a92563 100644 --- a/tests/mason-core/async/async_spec.lua +++ b/tests/mason-core/async/async_spec.lua @@ -42,11 +42,11 @@ describe("async", function() it("should wrap callback-style async functions via promisify", function() local async_spawn = _.compose(_.table_pack, a.promisify(process.spawn)) - local stdio = process.in_memory_sink() + local stdio = process.BufferedSink:new() local success, exit_code = unpack(a.run_blocking(async_spawn, "env", { args = {}, env = { "FOO=BAR", "BAR=BAZ" }, - stdio_sink = stdio.sink, + stdio_sink = stdio, })) assert.is_true(success) assert.equals(0, exit_code) diff --git a/tests/mason-core/installer/InstallRunner_spec.lua b/tests/mason-core/installer/InstallRunner_spec.lua index 696f7b34..0ff7a40f 100644 --- a/tests/mason-core/installer/InstallRunner_spec.lua +++ b/tests/mason-core/installer/InstallRunner_spec.lua @@ -212,8 +212,8 @@ describe("InstallRunner ::", function() local runner = InstallRunner:new(handle, Semaphore:new(1)) stub(dummy.spec.source, "install", function(ctx) - ctx.stdio_sink.stdout "Hello " - ctx.stdio_sink.stderr "world!" + ctx.stdio_sink:stdout "Hello " + ctx.stdio_sink:stderr "world!" end) local callback = test_helpers.sync_runner_execute(runner, { debug = true }) @@ -229,7 +229,7 @@ describe("InstallRunner ::", function() local runner = InstallRunner:new(handle, Semaphore:new(1)) stub(dummy.spec.source, "install", function(ctx) - ctx.stdio_sink.stderr "Something will go terribly wrong.\n" + ctx.stdio_sink:stderr "Something will go terribly wrong.\n" error("This went terribly wrong.", 0) end) @@ -246,7 +246,7 @@ describe("InstallRunner ::", function() local runner = InstallRunner:new(handle, Semaphore:new(1)) stub(dummy.spec.source, "install", function(ctx) - ctx.stdio_sink.stderr "Something will go terribly wrong.\n" + ctx.stdio_sink:stderr "Something will go terribly wrong.\n" error("This went terribly wrong.", 0) end) diff --git a/tests/mason-core/installer/managers/cargo_spec.lua b/tests/mason-core/installer/managers/cargo_spec.lua index bc5c5f21..66f89ca2 100644 --- a/tests/mason-core/installer/managers/cargo_spec.lua +++ b/tests/mason-core/installer/managers/cargo_spec.lua @@ -1,4 +1,5 @@ local cargo = require "mason-core.installer.managers.cargo" +local match = require "luassert.match" local spy = require "luassert.spy" local test_helpers = require "mason-test.helpers" @@ -30,7 +31,9 @@ describe("cargo manager", function() cargo.install("my-crate", "1.0.0") end) - assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing crate my-crate@1.0.0…\n" + assert + .spy(ctx.stdio_sink.stdout) + .was_called_with(match.is_ref(ctx.stdio_sink), "Installing crate my-crate@1.0.0…\n") end) it("should install locked", function() diff --git a/tests/mason-core/installer/managers/composer_spec.lua b/tests/mason-core/installer/managers/composer_spec.lua index f3887c68..8559e353 100644 --- a/tests/mason-core/installer/managers/composer_spec.lua +++ b/tests/mason-core/installer/managers/composer_spec.lua @@ -1,4 +1,5 @@ local composer = require "mason-core.installer.managers.composer" +local match = require "luassert.match" local spy = require "luassert.spy" local test_helpers = require "mason-test.helpers" @@ -29,6 +30,8 @@ describe("composer manager", function() composer.install("my-package", "1.0.0") end) - assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing composer package my-package@1.0.0…\n" + assert + .spy(ctx.stdio_sink.stdout) + .was_called_with(match.is_ref(ctx.stdio_sink), "Installing composer package my-package@1.0.0…\n") end) end) diff --git a/tests/mason-core/installer/managers/gem_spec.lua b/tests/mason-core/installer/managers/gem_spec.lua index 3a72521a..0345d799 100644 --- a/tests/mason-core/installer/managers/gem_spec.lua +++ b/tests/mason-core/installer/managers/gem_spec.lua @@ -1,4 +1,5 @@ local gem = require "mason-core.installer.managers.gem" +local match = require "luassert.match" local spy = require "luassert.spy" local test_helper = require "mason-test.helpers" @@ -34,7 +35,9 @@ describe("gem manager", function() gem.install("my-gem", "1.0.0") end) - assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing gem my-gem@1.0.0…\n" + assert + .spy(ctx.stdio_sink.stdout) + .was_called_with(match.is_ref(ctx.stdio_sink), "Installing gem my-gem@1.0.0…\n") end) it("should install extra packages", function() diff --git a/tests/mason-core/installer/managers/golang_spec.lua b/tests/mason-core/installer/managers/golang_spec.lua index e1a99cbd..146fea02 100644 --- a/tests/mason-core/installer/managers/golang_spec.lua +++ b/tests/mason-core/installer/managers/golang_spec.lua @@ -1,4 +1,5 @@ local golang = require "mason-core.installer.managers.golang" +local match = require "luassert.match" local spy = require "luassert.spy" local test_helpers = require "mason-test.helpers" @@ -29,7 +30,9 @@ describe("golang manager", function() golang.install("my-golang", "1.0.0") end) - assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing go package my-golang@1.0.0…\n" + assert + .spy(ctx.stdio_sink.stdout) + .was_called_with(match.is_ref(ctx.stdio_sink), "Installing go package my-golang@1.0.0…\n") end) it("should install extra packages", function() diff --git a/tests/mason-core/installer/managers/luarocks_spec.lua b/tests/mason-core/installer/managers/luarocks_spec.lua index 406c5c51..31dd3dc0 100644 --- a/tests/mason-core/installer/managers/luarocks_spec.lua +++ b/tests/mason-core/installer/managers/luarocks_spec.lua @@ -1,4 +1,5 @@ local luarocks = require "mason-core.installer.managers.luarocks" +local match = require "luassert.match" local spy = require "luassert.spy" local stub = require "luassert.stub" local test_helpers = require "mason-test.helpers" @@ -80,6 +81,8 @@ describe("luarocks manager", function() luarocks.install("my-rock", "1.0.0") end) - assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing luarocks package my-rock@1.0.0…\n" + assert + .spy(ctx.stdio_sink.stdout) + .was_called_with(match.is_ref(ctx.stdio_sink), "Installing luarocks package my-rock@1.0.0…\n") end) end) diff --git a/tests/mason-core/installer/managers/npm_spec.lua b/tests/mason-core/installer/managers/npm_spec.lua index b2fabc80..e3a2bc76 100644 --- a/tests/mason-core/installer/managers/npm_spec.lua +++ b/tests/mason-core/installer/managers/npm_spec.lua @@ -98,6 +98,8 @@ describe("npm manager", function() npm.install("my-package", "1.0.0") end) - assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing npm package my-package@1.0.0…\n" + assert + .spy(ctx.stdio_sink.stdout) + .was_called_with(match.is_ref(ctx.stdio_sink), "Installing npm package my-package@1.0.0…\n") end) end) diff --git a/tests/mason-core/installer/managers/nuget_spec.lua b/tests/mason-core/installer/managers/nuget_spec.lua index fdfbdc82..2f16a652 100644 --- a/tests/mason-core/installer/managers/nuget_spec.lua +++ b/tests/mason-core/installer/managers/nuget_spec.lua @@ -1,3 +1,4 @@ +local match = require "luassert.match" local nuget = require "mason-core.installer.managers.nuget" local spy = require "luassert.spy" local test_helpers = require "mason-test.helpers" @@ -28,6 +29,8 @@ describe("nuget manager", function() nuget.install("nuget-package", "1.0.0") end) - assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing nuget package nuget-package@1.0.0…\n" + assert + .spy(ctx.stdio_sink.stdout) + .was_called_with(match.is_ref(ctx.stdio_sink), "Installing nuget package nuget-package@1.0.0…\n") end) end) diff --git a/tests/mason-core/installer/managers/opam_spec.lua b/tests/mason-core/installer/managers/opam_spec.lua index 51f116e8..9ff53b98 100644 --- a/tests/mason-core/installer/managers/opam_spec.lua +++ b/tests/mason-core/installer/managers/opam_spec.lua @@ -1,3 +1,4 @@ +local match = require "luassert.match" local opam = require "mason-core.installer.managers.opam" local spy = require "luassert.spy" local test_helpers = require "mason-test.helpers" @@ -28,6 +29,8 @@ describe("opam manager", function() opam.install("opam-package", "1.0.0") end) - assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing opam package opam-package@1.0.0…\n" + assert + .spy(ctx.stdio_sink.stdout) + .was_called_with(match.is_ref(ctx.stdio_sink), "Installing opam package opam-package@1.0.0…\n") end) end) diff --git a/tests/mason-core/installer/managers/pypi_spec.lua b/tests/mason-core/installer/managers/pypi_spec.lua index ea3da250..7ae28563 100644 --- a/tests/mason-core/installer/managers/pypi_spec.lua +++ b/tests/mason-core/installer/managers/pypi_spec.lua @@ -143,7 +143,7 @@ describe("pypi manager", function() ) assert .spy(ctx.stdio_sink.stderr) - .was_called_with "Run with :MasonInstall --force to bypass this version validation.\n" + .was_called_with(match.is_ref(ctx.stdio_sink), "Run with :MasonInstall --force to bypass this version validation.\n") end) it( @@ -179,9 +179,10 @@ describe("pypi manager", function() "--system-site-packages", "venv", } - assert - .spy(ctx.stdio_sink.stderr) - .was_called_with "Warning: The resolved python3 version 3.5.0 is not compatible with the required Python versions: >=3.8.\n" + assert.spy(ctx.stdio_sink.stderr).was_called_with( + match.is_ref(ctx.stdio_sink), + "Warning: The resolved python3 version 3.5.0 is not compatible with the required Python versions: >=3.8.\n" + ) end ) @@ -249,7 +250,9 @@ describe("pypi manager", function() pypi.install("pypi-package", "1.0.0") end) - assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing pip package pypi-package@1.0.0…\n" + assert + .spy(ctx.stdio_sink.stdout) + .was_called_with(match.is_ref(ctx.stdio_sink), "Installing pip package pypi-package@1.0.0…\n") end) it("should install extra specifier", function() diff --git a/tests/mason-core/process_spec.lua b/tests/mason-core/process_spec.lua index 06330cdd..480b047b 100644 --- a/tests/mason-core/process_spec.lua +++ b/tests/mason-core/process_spec.lua @@ -5,7 +5,7 @@ local spy = require "luassert.spy" describe("process.spawn", function() -- Unix only it("should spawn command and feed output to sink", function() - local stdio = process.in_memory_sink() + local stdio = process.BufferedSink:new() local callback = spy.new() process.spawn("env", { args = {}, @@ -13,7 +13,7 @@ describe("process.spawn", function() "HELLO=world", "MY_ENV=var", }, - stdio_sink = stdio.sink, + stdio_sink = stdio, }, callback) assert.wait(function() diff --git a/tests/mason-core/spawn_spec.lua b/tests/mason-core/spawn_spec.lua index a1432294..9fc91200 100644 --- a/tests/mason-core/spawn_spec.lua +++ b/tests/mason-core/spawn_spec.lua @@ -26,16 +26,19 @@ describe("async spawn", function() end) it("should use provided stdio_sink", function() - local stdio = process.in_memory_sink() + local stdout = spy.new() + local stdio = process.StdioSink:new { + stdout = stdout, + } local result = a.run_blocking(spawn.env, { env_raw = { "FOO=bar" }, - stdio_sink = stdio.sink, + stdio_sink = stdio, }) assert.is_true(result:is_success()) - assert.equals(nil, result:get_or_nil().stdout) - assert.equals(nil, result:get_or_nil().stderr) - assert.equals("FOO=bar\n", table.concat(stdio.buffers.stdout, "")) - assert.equals("", table.concat(stdio.buffers.stderr, "")) + assert.equals(nil, result:get_or_nil()) + -- Not 100 %guaranteed it's only called once because output is always buffered, but it's extremely likely + assert.spy(stdout).was_called(1) + assert.spy(stdout).was_called_with "FOO=bar\n" end) it("should pass command arguments", function() @@ -68,10 +71,7 @@ describe("async spawn", function() assert.spy(process.spawn).was_called_with( "bash", match.tbl_containing { - stdio_sink = match.tbl_containing { - stdout = match.is_function(), - stderr = match.is_function(), - }, + stdio_sink = match.instanceof(process.BufferedSink), env = match.list_containing "VAR=world", args = match.tbl_containing { "-c", @@ -134,7 +134,7 @@ describe("async spawn", function() it("should format failure message", function() stub(process, "spawn", function(cmd, opts, callback) - opts.stdio_sink.stderr(("This is an error message for %s!"):format(cmd)) + opts.stdio_sink:stderr(("This is an error message for %s!"):format(cmd)) callback(false, 127) end) |
