Skip to content

Commit cad513e

Browse files
authored
Merge pull request #61 from desdic/20251224cleanup
Cleanup and add more tests
2 parents c5eea90 + be37c20 commit cad513e

9 files changed

Lines changed: 112 additions & 16 deletions

File tree

lua/greyjoy/_extensions/docker_compose.lua

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ if not ok then
2525
return
2626
end
2727

28-
local uok, utils = pcall(require, "greyjoy.utils")
29-
if not uok then
30-
vim.notify(
31-
"This plugin requires greyjoy.nvim (https://github.com/desdic/greyjoy.nvim)",
32-
vim.log.levels.ERROR({ title = "Plugin error" })
33-
)
34-
return
35-
end
36-
3728
local health = vim.health
3829

3930
local DockerCompose = {}

lua/greyjoy/_extensions/generic.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ end
101101
--- {filepath} is replaced with current filepath
102102
--- {rootdir} is the path for the root directory
103103
---
104-
--- Having multiple conditions like filetype and filename will do an `and` operation so both requirements has to be met before it triggers.
104+
--- Having multiple conditions like filetype and filename will do an `and` operation
105+
--- so both requirements has to be met before it triggers.
105106
--- Examples:
106107
--- commands = {
107108
--- ["run {filename}"] = {

lua/greyjoy/callback.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ greycall.extensions = function(
3939
or pluginname == plugin
4040
or greyjoy.__in_group(pluginname, plugin)
4141
then
42-
local output = {}
4342
if plugin_type == "global" then
44-
output = plugin_obj.parse(fileobj)
43+
local output = plugin_obj.parse(fileobj)
4544
callback(output, callbackoptions)
4645
else
4746
if rootdir then
@@ -51,7 +50,7 @@ greycall.extensions = function(
5150
filename = file,
5251
filepath = rootdir,
5352
}
54-
output = plugin_obj.parse(fileinfo)
53+
local output = plugin_obj.parse(fileinfo)
5554
callback(output, callbackoptions)
5655
end
5756
end

lua/greyjoy/init.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ greyjoy.setup = function(options)
198198
greyjoy.run_group_map = {}
199199
if greyjoy.config.run_groups then
200200
for group_name, group_plugins in pairs(greyjoy.config.run_groups) do
201-
greyjoy.run_group_map[group_name] = greyjoy.run_group_map[group_name]
202-
or {}
201+
greyjoy.run_group_map[group_name] = {}
203202

204203
for index in ipairs(group_plugins) do
205204
greyjoy.run_group_map[group_name][group_plugins[index]] = true

lua/greyjoy/terminals.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
-- luacheck: ignore 122
12
local M = {}
23

34
M.term = function(command, config)

lua/greyjoy/utils.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ M.new_file_obj = function(patterns, bufname, filetype)
6767
filepath = vim.uv.cwd()
6868
end
6969

70-
local rootdir = vim.fs.dirname(vim.fs.find(patterns, { upward = true })[1])
70+
local rootdir_search = vim.fs.find(patterns, { upward = true })
71+
local rootdir = nil
72+
if rootdir_search and #rootdir_search > 0 then
73+
rootdir = vim.fs.dirname(rootdir_search[1])
74+
end
7175
rootdir = M.if_nil(rootdir, filepath)
7276

7377
return {

lua/tests/automated/cargo_spec.lua

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
local eq = assert.are.same
2+
3+
describe("cargo extension", function()
4+
it("reads config", function()
5+
local cargo = require("greyjoy._extensions.cargo")
6+
7+
eq(cargo.exports, cargo.exports or false)
8+
9+
local fileinfo = {
10+
filename = "Cargo.toml",
11+
filepath = "/home/example",
12+
}
13+
14+
local config = {}
15+
16+
cargo.setup(config)
17+
local res = cargo.exports.parse(fileinfo)
18+
19+
-- Verify that parse returns a table
20+
eq(type(res), "table")
21+
end)
22+
23+
it("validates fileinfo type", function()
24+
local cargo = require("greyjoy._extensions.cargo")
25+
26+
local config = {}
27+
cargo.setup(config)
28+
29+
-- Test with invalid input
30+
local res = cargo.exports.parse("not a table")
31+
eq(type(res), "table")
32+
eq(#res, 0)
33+
end)
34+
end)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
local eq = assert.are.same
2+
local conditions = require("greyjoy.conditions")
3+
4+
describe("conditions module", function()
5+
it("provides file_exists function", function()
6+
eq(type(conditions.file_exists), "function")
7+
end)
8+
9+
it("provides directory_exists function", function()
10+
eq(type(conditions.directory_exists), "function")
11+
end)
12+
13+
it("file_exists returns boolean", function()
14+
local fileobj = {
15+
rootdir = "/tmp",
16+
}
17+
local result = conditions.file_exists("nonexistent_file_xyz.txt", fileobj)
18+
eq(type(result), "boolean")
19+
eq(result, false)
20+
end)
21+
22+
it("directory_exists returns boolean", function()
23+
local fileobj = {
24+
rootdir = "/tmp",
25+
}
26+
local result = conditions.directory_exists("nonexistent_dir_xyz", fileobj)
27+
eq(type(result), "boolean")
28+
eq(result, false)
29+
end)
30+
end)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
local eq = assert.are.same
2+
3+
describe("docker_compose extension", function()
4+
it("reads config", function()
5+
local docker_compose = require("greyjoy._extensions.docker_compose")
6+
7+
eq(docker_compose.exports, docker_compose.exports or false)
8+
9+
local fileinfo = {
10+
filename = "docker-compose.yml",
11+
filepath = "/home/example",
12+
}
13+
14+
local config = {
15+
cmd = "/usr/bin/docker-compose",
16+
shell = "/bin/bash",
17+
}
18+
19+
docker_compose.setup(config)
20+
local res = docker_compose.exports.parse(fileinfo)
21+
22+
-- Verify that parse returns a table
23+
eq(type(res), "table")
24+
end)
25+
26+
it("validates fileinfo type", function()
27+
local docker_compose = require("greyjoy._extensions.docker_compose")
28+
29+
local config = {}
30+
docker_compose.setup(config)
31+
32+
-- Test with invalid input
33+
local res = docker_compose.exports.parse("not a table")
34+
eq(type(res), "table")
35+
eq(#res, 0)
36+
end)
37+
end)

0 commit comments

Comments
 (0)