|
| 1 | +local stub_notification |
| 2 | +local stub_runner |
| 3 | + |
| 4 | +local function clear_modules() |
| 5 | + package.loaded["cmake-tools.utils"] = nil |
| 6 | + package.loaded["cmake-tools.notification"] = nil |
| 7 | + package.loaded["cmake-tools.runners"] = nil |
| 8 | + package.loaded["cmake-tools.executors"] = nil |
| 9 | +end |
| 10 | + |
| 11 | +describe("utils.run", function() |
| 12 | + before_each(function() |
| 13 | + clear_modules() |
| 14 | + |
| 15 | + stub_notification = { |
| 16 | + enabled = true, |
| 17 | + stop_calls = 0, |
| 18 | + start_calls = 0, |
| 19 | + notify_calls = {}, |
| 20 | + notify = function(self, msg, level, opts) |
| 21 | + table.insert(self.notify_calls, { msg = msg, level = level, opts = opts }) |
| 22 | + end, |
| 23 | + startSpinner = function(self) |
| 24 | + self.start_calls = self.start_calls + 1 |
| 25 | + end, |
| 26 | + stopSpinner = function(self) |
| 27 | + self.stop_calls = self.stop_calls + 1 |
| 28 | + end, |
| 29 | + } |
| 30 | + |
| 31 | + package.loaded["cmake-tools.notification"] = { |
| 32 | + new = function(_) |
| 33 | + return stub_notification |
| 34 | + end, |
| 35 | + } |
| 36 | + |
| 37 | + stub_runner = { |
| 38 | + run = function(_, _, _, _, _, _, on_exit, on_output) |
| 39 | + on_output("[ 50%] Running test", nil) |
| 40 | + on_exit(0) |
| 41 | + end, |
| 42 | + } |
| 43 | + |
| 44 | + package.loaded["cmake-tools.runners"] = { |
| 45 | + fake = stub_runner, |
| 46 | + } |
| 47 | + |
| 48 | + package.loaded["cmake-tools.executors"] = { |
| 49 | + fake = {}, |
| 50 | + } |
| 51 | + end) |
| 52 | + |
| 53 | + after_each(function() |
| 54 | + clear_modules() |
| 55 | + end) |
| 56 | + |
| 57 | + it("stops spinner when run completes", function() |
| 58 | + local utils = require("cmake-tools.utils") |
| 59 | + |
| 60 | + utils.run("ctest", "", {}, {}, vim.loop.cwd(), { name = "fake", opts = {} }, nil) |
| 61 | + |
| 62 | + assert.equals(1, stub_notification.start_calls) |
| 63 | + assert.equals(1, stub_notification.stop_calls) |
| 64 | + end) |
| 65 | +end) |
0 commit comments