Skip to content

Commit

Permalink
✅tests: now support windows WSL.
Browse files Browse the repository at this point in the history
Also, the tests directory is now detected correctly even if the plugin
is not installed in `.local/nvim/lazy`.
  • Loading branch information
Zeioth committed Jun 14, 2024
1 parent 62b48f0 commit 32ae37c
Show file tree
Hide file tree
Showing 32 changed files with 53 additions and 37 deletions.
15 changes: 15 additions & 0 deletions lua/compiler/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,19 @@ function M.os_path(path, surround)
return string.gsub(path, '[/\\]', separator)
end

---Returns the tests dir + a subdir if specified.
---The returned path support unix and windows.
---@param path string (optional) A subdirectory to append to he returned dir.
---@return string resulting path.
function M.get_tests_dir(path)
local plugin_directory = vim.fn.fnamemodify(
vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h"),
":h:h"
)
if path then
plugin_directory = M.os_path(plugin_directory .. "/tests/" .. path)
end
return plugin_directory
end

return M
3 changes: 2 additions & 1 deletion tests/tests-bau.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--- @usage :luafile ~/.local/share/nvim/lazy/compiler.nvim/tests/tests-bau.lua

-- path of this script → tests
local tests_dir = (debug.getinfo(1, 'S').source:sub(2):match '(.*/)') .. "/tests/bau/"
local tests_dir = require("compiler.utils").plugin_dir_append("tests/bau/")
local ms = 1000 -- wait time

coroutine.resume(coroutine.create(function()
Expand All @@ -12,6 +12,7 @@ coroutine.resume(coroutine.create(function()
vim.defer_fn(function() coroutine.resume(co) end, _ms)
coroutine.yield()
end

dofile(tests_dir .. 'make.lua')
sleep()
dofile(tests_dir .. 'cmake.lua')
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- in this file, and in every individual test.

-- path of this script → tests
local tests_dir = (debug.getinfo(1, 'S').source:sub(2):match '(.*/)') .. "/tests/languages/"
local tests_dir = require("compiler.utils").get_tests_dir("tests/languages/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/bau/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local bau = require("compiler.bau.cmake")
local example = vim.fn.stdpath "data" .. "/lazy/compiler.nvim/tests/code samples/bau/cmake"
local example = require("compiler.utils").get_tests_dir("code samples/bau/cmake")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/bau/gradle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ coroutine.resume(coroutine.create(function()
end

-- Run gradlew > build.gradlew.kts > build.gradlew (first occurence by priority)
local example = vim.fn.stdpath "data" .. "/lazy/compiler.nvim/tests/code samples/bau/gradle/parse-file"
local example = require("compiler.utils").get_tests_dir("code samples/bau/gradle/parse-file")
vim.api.nvim_set_current_dir(example)
bau.action("hello_world")
sleep()

-- Run gradlew > build.gradlew.kts > build.gradlew (first occurence by priority)
example = vim.fn.stdpath "data" .. "/lazy/compiler.nvim/tests/code samples/bau/gradle/parse-cmd"
example = require("compiler.utils").get_tests_dir("code samples/bau/gradle/parse-cmd")
vim.api.nvim_set_current_dir(example)
bau.action("bootRun")
sleep()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/bau/make.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local bau = require("compiler.bau.make")
local example = vim.fn.stdpath "data" .. "/lazy/compiler.nvim/tests/code samples/bau/make"
local example = require("compiler.utils").get_tests_dir("code samples/bau/make")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/bau/meson.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local bau = require("compiler.bau.meson")
local example = vim.fn.stdpath "data" .. "/lazy/compiler.nvim/tests/code samples/bau/meson"
local example = require("compiler.utils").get_tests_dir("code samples/bau/meson")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/bau/nodejs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local bau = require("compiler.bau.nodejs")
local example = vim.fn.stdpath "data" .. "/lazy/compiler.nvim/tests/code samples/bau/nodejs/"
local example = require("compiler.utils").get_tests_dir("code samples/bau/nodejs")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/asm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.asm")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/asm/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/asm/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.c")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/c/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/c/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.cpp")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/cpp/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/cpp/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/cs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.cs")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/cs/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/cs/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/languages/dart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ coroutine.resume(coroutine.create(function()
end

-- ============================= INTERPRETED ================================
example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/dart/interpreted/"
example = require("compiler.utils").get_tests_dir("code samples/languages/dart/interpreted/")

-- Run program
vim.api.nvim_set_current_dir(example .. "run-program/")
Expand All @@ -33,7 +33,7 @@ coroutine.resume(coroutine.create(function()
sleep()

-- ============================= MACHINE CODE ===============================
example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/dart/machine-code/"
example = require("compiler.utils").get_tests_dir("code samples/languages/dart/machine-code/")

-- Build and run
vim.api.nvim_set_current_dir(example .. "build-and-run/")
Expand All @@ -60,7 +60,7 @@ coroutine.resume(coroutine.create(function()
sleep()

-- =============================== FLUTTER ==================================
example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/dart/fluttr/"
example = require("compiler.utils").get_tests_dir("code samples/languages/dart/fluttr/")
vim.api.nvim_set_current_dir(example)

-- We don't test run program (flutter because it is a loop)
Expand All @@ -84,7 +84,7 @@ coroutine.resume(coroutine.create(function()
sleep()

-- =============================== OTHER ====================================
example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/dart/transpiled/"
example = require("compiler.utils").get_tests_dir("code samples/languages/dart/transpiled/")

-- Transpile to javascript
vim.api.nvim_set_current_dir(example .. "to-javascript/")
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/elixir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.elixir")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/elixir/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/elixir/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/fortran.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.fortran")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/fortran/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/fortran/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/fsharp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.fsharp")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/fsharp/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/fsharp/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 6000 -- wait time
local language = require("compiler.languages.go")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/go/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/go/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/java.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.java")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/java/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/java/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/javascript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.javascript")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/javascript/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/javascript/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/kotlin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.kotlin")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/kotlin/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/kotlin/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.lua")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/lua/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/lua/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/make.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.make")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages"
local example = require("compiler.utils").get_tests_dir("code samples/languages")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/perl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.perl")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/perl/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/perl/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/languages/python.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ coroutine.resume(coroutine.create(function()
end

-- ============================= INTERPRETED ==================================
example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/python/interpreted/"
example = require("compiler.utils").get_tests_dir("code samples/languages/python/interpreted/")

-- Run program
vim.api.nvim_set_current_dir(example .. "run-program/")
Expand All @@ -32,7 +32,7 @@ coroutine.resume(coroutine.create(function()
sleep()

-- ============================= MACHINE CODE =================================
example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/python/machine-code/"
example = require("compiler.utils").get_tests_dir("code samples/languages/python/machine-code/")

-- Build and run
vim.api.nvim_set_current_dir(example .. "build-and-run/")
Expand All @@ -59,7 +59,7 @@ coroutine.resume(coroutine.create(function()
sleep()

-- =============================== BYTECODE ===================================
example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/python/bytecode/"
example = require("compiler.utils").get_tests_dir("code samples/languages/python/bytecode/")

-- Build and run
vim.api.nvim_set_current_dir(example .. "build-and-run/")
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/r.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.r")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/r/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/r/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/ruby.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.ruby")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/ruby/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/ruby/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/rust.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.rust")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/rust/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/rust/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/sh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.sh")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/sh/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/sh/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/swift.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.swift")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/swift/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/swift/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/typescript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.typescript")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/typescript/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/typescript/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/vb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.vb")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/vb/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/vb/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/languages/zig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local ms = 1000 -- wait time
local language = require("compiler.languages.zig")
local example = vim.fn.stdpath("data") .. "/lazy/compiler.nvim/tests/code samples/languages/zig/"
local example = require("compiler.utils").get_tests_dir("code samples/languages/zig/")

coroutine.resume(coroutine.create(function()
local co = coroutine.running()
Expand Down

0 comments on commit 32ae37c

Please sign in to comment.