diff --git a/lua/compiler/utils.lua b/lua/compiler/utils.lua index 6a35ed2..a5c7eb3 100644 --- a/lua/compiler/utils.lua +++ b/lua/compiler/utils.lua @@ -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 diff --git a/tests/tests-bau.lua b/tests/tests-bau.lua index 9388a3b..023df77 100644 --- a/tests/tests-bau.lua +++ b/tests/tests-bau.lua @@ -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() @@ -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') diff --git a/tests/tests.lua b/tests/tests.lua index 0a0c4ed..0f9279d 100644 --- a/tests/tests.lua +++ b/tests/tests.lua @@ -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() diff --git a/tests/tests/bau/cmake.lua b/tests/tests/bau/cmake.lua index cf9a34d..9852077 100644 --- a/tests/tests/bau/cmake.lua +++ b/tests/tests/bau/cmake.lua @@ -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() diff --git a/tests/tests/bau/gradle.lua b/tests/tests/bau/gradle.lua index c21067d..ce288cf 100644 --- a/tests/tests/bau/gradle.lua +++ b/tests/tests/bau/gradle.lua @@ -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() diff --git a/tests/tests/bau/make.lua b/tests/tests/bau/make.lua index 1c2f232..5d03dad 100644 --- a/tests/tests/bau/make.lua +++ b/tests/tests/bau/make.lua @@ -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() diff --git a/tests/tests/bau/meson.lua b/tests/tests/bau/meson.lua index e1a8be6..c630f99 100644 --- a/tests/tests/bau/meson.lua +++ b/tests/tests/bau/meson.lua @@ -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() diff --git a/tests/tests/bau/nodejs.lua b/tests/tests/bau/nodejs.lua index 0f27817..bbfe25e 100644 --- a/tests/tests/bau/nodejs.lua +++ b/tests/tests/bau/nodejs.lua @@ -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() diff --git a/tests/tests/languages/asm.lua b/tests/tests/languages/asm.lua index 6745cbd..9690aa3 100644 --- a/tests/tests/languages/asm.lua +++ b/tests/tests/languages/asm.lua @@ -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() diff --git a/tests/tests/languages/c.lua b/tests/tests/languages/c.lua index 0f1ba05..d91e9ed 100644 --- a/tests/tests/languages/c.lua +++ b/tests/tests/languages/c.lua @@ -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() diff --git a/tests/tests/languages/cpp.lua b/tests/tests/languages/cpp.lua index f3ce3c5..84402bd 100644 --- a/tests/tests/languages/cpp.lua +++ b/tests/tests/languages/cpp.lua @@ -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() diff --git a/tests/tests/languages/cs.lua b/tests/tests/languages/cs.lua index 22d8a4e..b2a26dd 100644 --- a/tests/tests/languages/cs.lua +++ b/tests/tests/languages/cs.lua @@ -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() diff --git a/tests/tests/languages/dart.lua b/tests/tests/languages/dart.lua index 0577071..3457bcb 100644 --- a/tests/tests/languages/dart.lua +++ b/tests/tests/languages/dart.lua @@ -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/") @@ -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/") @@ -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) @@ -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/") diff --git a/tests/tests/languages/elixir.lua b/tests/tests/languages/elixir.lua index 7bb01d9..a0a693b 100644 --- a/tests/tests/languages/elixir.lua +++ b/tests/tests/languages/elixir.lua @@ -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() diff --git a/tests/tests/languages/fortran.lua b/tests/tests/languages/fortran.lua index cc87245..d306693 100644 --- a/tests/tests/languages/fortran.lua +++ b/tests/tests/languages/fortran.lua @@ -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() diff --git a/tests/tests/languages/fsharp.lua b/tests/tests/languages/fsharp.lua index 41e48ae..6394cb9 100644 --- a/tests/tests/languages/fsharp.lua +++ b/tests/tests/languages/fsharp.lua @@ -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() diff --git a/tests/tests/languages/go.lua b/tests/tests/languages/go.lua index 538447f..ea62182 100644 --- a/tests/tests/languages/go.lua +++ b/tests/tests/languages/go.lua @@ -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() diff --git a/tests/tests/languages/java.lua b/tests/tests/languages/java.lua index 0079b6d..44fb83a 100644 --- a/tests/tests/languages/java.lua +++ b/tests/tests/languages/java.lua @@ -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() diff --git a/tests/tests/languages/javascript.lua b/tests/tests/languages/javascript.lua index ce6a074..46266e6 100644 --- a/tests/tests/languages/javascript.lua +++ b/tests/tests/languages/javascript.lua @@ -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() diff --git a/tests/tests/languages/kotlin.lua b/tests/tests/languages/kotlin.lua index 84e81b3..0d3b8ae 100644 --- a/tests/tests/languages/kotlin.lua +++ b/tests/tests/languages/kotlin.lua @@ -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() diff --git a/tests/tests/languages/lua.lua b/tests/tests/languages/lua.lua index 78922a3..5c1c68e 100644 --- a/tests/tests/languages/lua.lua +++ b/tests/tests/languages/lua.lua @@ -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() diff --git a/tests/tests/languages/make.lua b/tests/tests/languages/make.lua index 9b2a173..5c18f7f 100644 --- a/tests/tests/languages/make.lua +++ b/tests/tests/languages/make.lua @@ -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() diff --git a/tests/tests/languages/perl.lua b/tests/tests/languages/perl.lua index c671cd3..a6960d2 100644 --- a/tests/tests/languages/perl.lua +++ b/tests/tests/languages/perl.lua @@ -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() diff --git a/tests/tests/languages/python.lua b/tests/tests/languages/python.lua index 9a242cb..41ab713 100644 --- a/tests/tests/languages/python.lua +++ b/tests/tests/languages/python.lua @@ -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/") @@ -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/") @@ -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/") diff --git a/tests/tests/languages/r.lua b/tests/tests/languages/r.lua index 8084be3..a8e73be 100644 --- a/tests/tests/languages/r.lua +++ b/tests/tests/languages/r.lua @@ -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() diff --git a/tests/tests/languages/ruby.lua b/tests/tests/languages/ruby.lua index c44562b..487442b 100644 --- a/tests/tests/languages/ruby.lua +++ b/tests/tests/languages/ruby.lua @@ -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() diff --git a/tests/tests/languages/rust.lua b/tests/tests/languages/rust.lua index 0d7cd26..5af2331 100644 --- a/tests/tests/languages/rust.lua +++ b/tests/tests/languages/rust.lua @@ -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() diff --git a/tests/tests/languages/sh.lua b/tests/tests/languages/sh.lua index 08ecdb1..12ac1e3 100644 --- a/tests/tests/languages/sh.lua +++ b/tests/tests/languages/sh.lua @@ -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() diff --git a/tests/tests/languages/swift.lua b/tests/tests/languages/swift.lua index 7335bb8..268240a 100644 --- a/tests/tests/languages/swift.lua +++ b/tests/tests/languages/swift.lua @@ -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() diff --git a/tests/tests/languages/typescript.lua b/tests/tests/languages/typescript.lua index a2dc344..70e7d05 100644 --- a/tests/tests/languages/typescript.lua +++ b/tests/tests/languages/typescript.lua @@ -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() diff --git a/tests/tests/languages/vb.lua b/tests/tests/languages/vb.lua index 33e0ca5..4c6741e 100644 --- a/tests/tests/languages/vb.lua +++ b/tests/tests/languages/vb.lua @@ -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() diff --git a/tests/tests/languages/zig.lua b/tests/tests/languages/zig.lua index ab5696d..9d52467 100644 --- a/tests/tests/languages/zig.lua +++ b/tests/tests/languages/zig.lua @@ -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()