diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f4a0d9..25e5482 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,11 @@ jobs: luarocks install luasocket luarocks install luasec + - name: fetch dependencies + run: | + chmod +x ./fetch-deps.sh + ./fetch-deps.sh + - name: test run: | - busted vector - # further tests here + busted vector \ No newline at end of file diff --git a/.gitignore b/.gitignore index 55b4e93..9b1e5f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ /config /.vscode -/computer \ No newline at end of file +/computer +/libs/eventCallStack.lua +/libs/helperFunctions.lua +/libs/ccClass.lua \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 95f7189..0000000 --- a/.gitmodules +++ /dev/null @@ -1,7 +0,0 @@ -[submodule "helperFunctions"] - path = helperFunctions - url = https://github.com/mc-cc-scripts/helperFunctions-lib.git -[submodule "eventCallStack-lib"] - path = eventCallStack-lib - url = https://github.com/mc-cc-scripts/eventCallStack-lib.git - branch = master \ No newline at end of file diff --git a/README.md b/README.md index e79589e..ccb1b34 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,21 @@ -# Install - -in your testfile(s), just add these few lines to automaticly install the test-suites in the /suits folder of your current path. - -```lua --- Check if relvant suit is found(only relevant when testing locally) --- otherwise run the installer -if not pcall(function () io.open("./suits/vector/vector.lua", "r"):close() end) then - print("Downloading TestSuite-lib") - local http = require("socket.http") - local url = "https://raw.githubusercontent.com/mc-cc-scripts/TestSuite-lib/master/installSuit.lua" -- URL of the installer - local body, statusCode = http.request(url) - if statusCode == 200 then - local loader - if _VERSION == "Lua 5.1" then - loader = loadstring - else - loader = load - end - local installScript = loader(body)().install() - else - error("Failed to download TestSuite-lib: " .. tostring(statusCode)) - end -end -``` - -## Planned features -Specify the install location for the suit -update files already present / add missing files \ No newline at end of file +# TestSuite + +This emulates the basic ccTweaked functions missing in basic-lua. + +- fs +- http +- vector-functions + +Additionally it emulates our **[scm](https://github.com/mc-cc-scripts/script-manager)** script and includes the **[json](https://gist.github.com/tylerneylon/59f4bcf316be525b30ab)** handler - which makes tests a lot easier. + +# Usage + +As this repo emulates many functionalites given by ccTweaked, you might want to test you code **outside** of Minecraft, maybe even automated. To achieve that, you need to download the scripts listed above and save them in your testingenv. + +Ideally you want to add those scripts to your .gitignore and only add them locally / for github actions. + +### Example + +For how to import the scipts, an example is already used by this repo for some of its dependancies: + +[fetch-deps.sh](fetch-deps.sh) \ No newline at end of file diff --git a/ccClass/ccClass.lua b/ccClass/ccClass.lua deleted file mode 100644 index d4502b3..0000000 --- a/ccClass/ccClass.lua +++ /dev/null @@ -1,52 +0,0 @@ ---- Returns only the class, not in instance of it! ---- ---- Init by _classname_(...), which returns an Instance! ----@source http://lua-users.org/wiki/SimpleLuaClasses ----@param base function | table initfunction | baseclass ----@param init function | nil new InitFunction, overrides base init ----@return table -function Class(base, init) - local c = {} - if not init and type(base) == 'function' then - -- New class - init = base; - base = nil; - elseif type(base) == "table" then - -- Inherited from base - for i, v in pairs(base) do - c[i] = v - end - c._base = base - end - -- the class will be the metatable for all its objects, - -- and they will look up their methods in it. - c.__index = c - - --constructor - local mt = {} - mt.__call = function(class_tbl, ...) - local obj = {} - setmetatable(obj, c) - if init then - init(obj, ...) - else - if base and base.init then - base.init(obj, ...) - end - end - return obj - end - c.init = init - c.is_a = function(self, class) - local m = getmetatable(self) - while m do - if m == class then return true end - m = m._base - end - return false - end - setmetatable(c, mt) - return c -end - -return Class \ No newline at end of file diff --git a/ccPackage.lua b/ccPackage.lua deleted file mode 100644 index ceddffd..0000000 --- a/ccPackage.lua +++ /dev/null @@ -1,11 +0,0 @@ -local spath = - debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$","") -package.path = spath.."?.lua;" - ..spath.."ccClass/?.lua;" - ..spath.."fs/?.lua;" - ..spath.."helperFunctions/?.lua;" - ..spath.."http/?.lua;" - ..spath.."json/?.lua;" - ..spath.."vector/?.lua;" - ..spath.."eventCallStack-lib/?.lua;" - ..package.path diff --git a/eventCallStack-lib b/eventCallStack-lib deleted file mode 160000 index fa366ad..0000000 --- a/eventCallStack-lib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fa366add9335ea5249459e855befa8ae82c98254 diff --git a/fetch-deps.sh b/fetch-deps.sh new file mode 100755 index 0000000..ef5a6c3 --- /dev/null +++ b/fetch-deps.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# ---- Whats happening ---- # + +# This fetches the dependencies listed in the "libs" variable and saves them in the targetFolder + + + +set -e + +libs=( + "helperFunctions-lib" + "eventCallStack-lib" + "ccClass-lib" +) + +# Basic setup variables +repo="mc-cc-scripts" +branch="master" +targetFolderName=libs + + +# fetch files.txt and save each file into the targetFolder +fetch() { + + files_txt=$(curl -fsSL "https://raw.githubusercontent.com/$repo/$1/$branch/files.txt") + if [ -z "$files_txt" ]; then + echo "Could not load files.txt for $1" + exit 1 + fi + while IFS= read -r FILE; do + rm -f $targetFolderName/$1.lua # rm existing file + curl -s "https://raw.githubusercontent.com/$repo/$1/$branch/$FILE" -o "$targetFolderName/$FILE" + done < <(echo "$files_txt") +} + +mkdir -p $targetFolderName + +for i in "${libs[@]}"; do + fetch "$i" +done \ No newline at end of file diff --git a/files.txt b/files.txt index aab975c..d38e55b 100644 --- a/files.txt +++ b/files.txt @@ -1,6 +1,5 @@ -vector/vector.lua -ccClass/ccClass.lua -http/http.lua -fs/fs.lua -helperFunctions/helperFunctions.lua -json/json.lua \ No newline at end of file +vector.lua +http.lua +fs.lua +json.lua +scm.lua \ No newline at end of file diff --git a/fs/fs.lua b/fs.lua similarity index 100% rename from fs/fs.lua rename to fs.lua diff --git a/helperFunctions b/helperFunctions deleted file mode 160000 index 2e6bcf5..0000000 --- a/helperFunctions +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2e6bcf578ded029b4c1ab097b7a5c7b6b58797ff diff --git a/http/http.lua b/http.lua similarity index 100% rename from http/http.lua rename to http.lua diff --git a/json/json.lua b/json.lua similarity index 100% rename from json/json.lua rename to json.lua diff --git a/vector/vector.lua b/vector.lua similarity index 96% rename from vector/vector.lua rename to vector.lua index 5f85473..32a9270 100644 --- a/vector/vector.lua +++ b/vector.lua @@ -1,7 +1,5 @@ -local cPath = debug.getinfo(1).source:match("@?(.*/)") -cPath = string.gsub(cPath, "/vector/", "/ccClass/ccClass") ---@type function -local class = require(cPath) +local class = require("ccClass") ---@class Vector ---@field x number diff --git a/vector/tests/test_spec.lua b/vector/tests/test_spec.lua index 8df5c22..634e8a6 100644 --- a/vector/tests/test_spec.lua +++ b/vector/tests/test_spec.lua @@ -1,10 +1,4 @@ - -local spath = - debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$",""):gsub("/vector/tests", ""):gsub("vector/tests", "") - if spath == "" then - spath = "./" - end -require(spath .. "ccPackage") +package.path = package.path.. ";libs/?.lua" local vector = require("vector") describe('Vector', function()