Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
klen committed Dec 30, 2021
1 parent 30c88b2 commit c4d816e
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 34 deletions.
1 change: 1 addition & 0 deletions .vimrc.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require("nvim-test.runners.busted"):setup {
command = "vusted",
args = " --helper=spec/lua/conftest.lua",
}
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ nvim-treesitter:
LUA_PATH := $(LUA_PATH):$(CURDIR)
test t: nvim-treesitter
@echo $(CURDIR)
vusted --shuffle --lpath="./?.lua;./?/?.lua;./?/init.lua"
vusted \
--shuffle --lpath="./?.lua;./?/?.lua;./?/init.lua" \
--helper=$(CURDIR)/spec/lua/conftest.lua
.PHONY: test t
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Test Runner for neovim

[![tests](https://github.com/klen/nvim-test/actions/workflows/tests.yml/badge.svg)](https://github.com/klen/nvim-test/actions/workflows/tests.yml)

## Features

| Language | Test Runners |
Expand Down
7 changes: 2 additions & 5 deletions lua/nvim-test/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local ts_utils = require "nvim-treesitter.ts_utils"

local Runner = {
config = {},
config = { args = "" },
}
Runner.__index = Runner

Expand Down Expand Up @@ -56,16 +56,13 @@ function Runner:build_cmd(filename, opts)
end

function Runner:build_args(filename, opts)
local args = ""
local args = self.config.args
if filename then
args = args .. " " .. filename
end
if opts.tests and #opts.tests > 0 then
args = args .. self:build_test_args(opts.tests)
end
if self.config.args then
args = args .. " " .. self.config.args
end
return args
end

Expand Down
7 changes: 4 additions & 3 deletions lua/nvim-test/runners/cargo-test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ end

function cargotest:build_args(filename, opts)
-- for whole suite do nothing
local args = self.config.args
if not filename then
return ""
return args
end

local parts = vim.fn.split(vim.fn.fnamemodify(filename, ":.:r"), "/")
Expand All @@ -42,10 +43,10 @@ function cargotest:build_args(filename, opts)
end

if opts.tests and #opts.tests > 0 then
return " " .. table.concat(opts.tests, "::") .. " -- --exact"
return args .. " " .. table.concat(opts.tests, "::") .. " -- --exact"
end

return modname or ""
return args .. (modname or "")
end

return cargotest
7 changes: 4 additions & 3 deletions lua/nvim-test/runners/go-test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ function gotest:is_test(name)
end

function gotest:build_args(filename, opts)
local args = self.config.args
if not filename then
return " ./..."
return args .. " ./..."
end

local args = "./" .. vim.fn.fnamemodify(filename, ":.:h")
args = (args == "./.") and "" or (args .. "/...")
local path = "./" .. vim.fn.fnamemodify(filename, ":.:h")
args = args .. ((path == "./.") and "" or (path .. "/..."))
if opts.tests then
args = string.format(" -run %s ", vim.fn.shellescape(opts.tests[1] .. "$")) .. args
end
Expand Down
5 changes: 1 addition & 4 deletions lua/nvim-test/runners/pyunit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ function pyunit:is_test(name)
end

function pyunit:build_args(filename, opts)
local args = ""
local args = self.config.args
if filename then
args = args .. " " .. vim.fn.fnamemodify(filename, ":.:r"):gsub("/", ".")
end
if opts.tests and #opts.tests > 0 then
args = args .. "." .. table.concat(opts.tests, ".")
end
if self.config.args then
args = args .. " " .. self.config.args
end
return args
end

Expand Down
2 changes: 0 additions & 2 deletions spec/lua/test/busted_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec.lua.conftest"

local helpers = require "spec.lua.helpers"

describe("busted", function()
Expand Down
2 changes: 0 additions & 2 deletions spec/lua/test/cargo-test_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec.lua.conftest"

local helpers = require "spec.lua.helpers"

describe("cargotest", function()
Expand Down
2 changes: 0 additions & 2 deletions spec/lua/test/go-test_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec.lua.conftest"

local helpers = require "spec.lua.helpers"

describe("gotest", function()
Expand Down
2 changes: 0 additions & 2 deletions spec/lua/test/init_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec.lua.conftest"

local helpers = require "spec.lua.helpers"

describe("nvim-test", function()
Expand Down
2 changes: 0 additions & 2 deletions spec/lua/test/jest_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec.lua.conftest"

local helpers = require "spec.lua.helpers"

describe("jest", function()
Expand Down
2 changes: 0 additions & 2 deletions spec/lua/test/mocha_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec.lua.conftest"

local helpers = require "spec.lua.helpers"

describe("mocha", function()
Expand Down
2 changes: 0 additions & 2 deletions spec/lua/test/pytest_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec.lua.conftest"

local helpers = require "spec.lua.helpers"

describe("pytest", function()
Expand Down
2 changes: 0 additions & 2 deletions spec/lua/test/pyunit_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec.lua.conftest"

local helpers = require "spec.lua.helpers"

describe("pyunit", function()
Expand Down
2 changes: 0 additions & 2 deletions spec/lua/test/ts-mocha_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "spec.lua.conftest"

local helpers = require "spec.lua.helpers"

describe("tsmocha", function()
Expand Down

0 comments on commit c4d816e

Please sign in to comment.