Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions lua/greyjoy/_extensions/docker_compose.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ if not ok then
return
end

local uok, utils = pcall(require, "greyjoy.utils")
if not uok then
vim.notify(
"This plugin requires greyjoy.nvim (https://github.com/desdic/greyjoy.nvim)",
vim.log.levels.ERROR({ title = "Plugin error" })
)
return
end

local health = vim.health

local DockerCompose = {}
Expand Down
3 changes: 2 additions & 1 deletion lua/greyjoy/_extensions/generic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ end
--- {filepath} is replaced with current filepath
--- {rootdir} is the path for the root directory
---
--- Having multiple conditions like filetype and filename will do an `and` operation so both requirements has to be met before it triggers.
--- Having multiple conditions like filetype and filename will do an `and` operation
--- so both requirements has to be met before it triggers.
--- Examples:
--- commands = {
--- ["run {filename}"] = {
Expand Down
5 changes: 2 additions & 3 deletions lua/greyjoy/callback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ greycall.extensions = function(
or pluginname == plugin
or greyjoy.__in_group(pluginname, plugin)
then
local output = {}
if plugin_type == "global" then
output = plugin_obj.parse(fileobj)
local output = plugin_obj.parse(fileobj)
callback(output, callbackoptions)
else
if rootdir then
Expand All @@ -51,7 +50,7 @@ greycall.extensions = function(
filename = file,
filepath = rootdir,
}
output = plugin_obj.parse(fileinfo)
local output = plugin_obj.parse(fileinfo)
callback(output, callbackoptions)
end
end
Expand Down
3 changes: 1 addition & 2 deletions lua/greyjoy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ greyjoy.setup = function(options)
greyjoy.run_group_map = {}
if greyjoy.config.run_groups then
for group_name, group_plugins in pairs(greyjoy.config.run_groups) do
greyjoy.run_group_map[group_name] = greyjoy.run_group_map[group_name]
or {}
greyjoy.run_group_map[group_name] = {}

for index in ipairs(group_plugins) do
greyjoy.run_group_map[group_name][group_plugins[index]] = true
Expand Down
1 change: 1 addition & 0 deletions lua/greyjoy/terminals.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- luacheck: ignore 122
local M = {}

M.term = function(command, config)
Expand Down
6 changes: 5 additions & 1 deletion lua/greyjoy/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ M.new_file_obj = function(patterns, bufname, filetype)
filepath = vim.uv.cwd()
end

local rootdir = vim.fs.dirname(vim.fs.find(patterns, { upward = true })[1])
local rootdir_search = vim.fs.find(patterns, { upward = true })
local rootdir = nil
if rootdir_search and #rootdir_search > 0 then
rootdir = vim.fs.dirname(rootdir_search[1])
end
rootdir = M.if_nil(rootdir, filepath)

return {
Expand Down
34 changes: 34 additions & 0 deletions lua/tests/automated/cargo_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local eq = assert.are.same

describe("cargo extension", function()
it("reads config", function()
local cargo = require("greyjoy._extensions.cargo")

eq(cargo.exports, cargo.exports or false)

local fileinfo = {
filename = "Cargo.toml",
filepath = "/home/example",
}

local config = {}

cargo.setup(config)
local res = cargo.exports.parse(fileinfo)

-- Verify that parse returns a table
eq(type(res), "table")
end)

it("validates fileinfo type", function()
local cargo = require("greyjoy._extensions.cargo")

local config = {}
cargo.setup(config)

-- Test with invalid input
local res = cargo.exports.parse("not a table")
eq(type(res), "table")
eq(#res, 0)
end)
end)
30 changes: 30 additions & 0 deletions lua/tests/automated/conditions_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
local eq = assert.are.same
local conditions = require("greyjoy.conditions")

describe("conditions module", function()
it("provides file_exists function", function()
eq(type(conditions.file_exists), "function")
end)

it("provides directory_exists function", function()
eq(type(conditions.directory_exists), "function")
end)

it("file_exists returns boolean", function()
local fileobj = {
rootdir = "/tmp",
}
local result = conditions.file_exists("nonexistent_file_xyz.txt", fileobj)
eq(type(result), "boolean")
eq(result, false)
end)

it("directory_exists returns boolean", function()
local fileobj = {
rootdir = "/tmp",
}
local result = conditions.directory_exists("nonexistent_dir_xyz", fileobj)
eq(type(result), "boolean")
eq(result, false)
end)
end)
37 changes: 37 additions & 0 deletions lua/tests/automated/docker_compose_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local eq = assert.are.same

describe("docker_compose extension", function()
it("reads config", function()
local docker_compose = require("greyjoy._extensions.docker_compose")

eq(docker_compose.exports, docker_compose.exports or false)

local fileinfo = {
filename = "docker-compose.yml",
filepath = "/home/example",
}

local config = {
cmd = "/usr/bin/docker-compose",
shell = "/bin/bash",
}

docker_compose.setup(config)
local res = docker_compose.exports.parse(fileinfo)

-- Verify that parse returns a table
eq(type(res), "table")
end)

it("validates fileinfo type", function()
local docker_compose = require("greyjoy._extensions.docker_compose")

local config = {}
docker_compose.setup(config)

-- Test with invalid input
local res = docker_compose.exports.parse("not a table")
eq(type(res), "table")
eq(#res, 0)
end)
end)