From 6b0a027a662f8dfc4a78e42b057388875b7ced4e Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Thu, 29 May 2025 13:36:29 +0200 Subject: [PATCH 1/3] refactor: :wastebasket: removed submodules Added a script which pulls the dependencies. Removed Submodules. Old Repositories which had utilized this repo need to be updated --- .github/workflows/test.yml | 6 +++-- .gitignore | 5 +++- .gitmodules | 6 ----- README.md | 50 +++++++++++++++-------------------- ccClass/ccClass.lua | 52 ------------------------------------- ccPackage.lua | 11 -------- eventCallStack-lib | 1 - fetch-deps.sh | 39 ++++++++++++++++++++++++++++ files.txt | 11 ++++---- helperFunctions | 1 - {fs => libs}/fs.lua | 0 {http => libs}/http.lua | 0 {json => libs}/json.lua | 0 scm.lua => libs/scm.lua | 0 {vector => libs}/vector.lua | 4 +-- vector/tests/test_spec.lua | 8 +----- 16 files changed, 75 insertions(+), 119 deletions(-) delete mode 100644 .gitmodules delete mode 100644 ccClass/ccClass.lua delete mode 100644 ccPackage.lua delete mode 160000 eventCallStack-lib create mode 100755 fetch-deps.sh delete mode 160000 helperFunctions rename {fs => libs}/fs.lua (100%) rename {http => libs}/http.lua (100%) rename {json => libs}/json.lua (100%) rename scm.lua => libs/scm.lua (100%) rename {vector => libs}/vector.lua (96%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f4a0d9..6c2b304 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,9 @@ jobs: luarocks install luasocket luarocks install luasec + - name: fetch dependencies + run: .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 f351d1d..0000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +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 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 e0dbc05..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..f8a135f --- /dev/null +++ b/fetch-deps.sh @@ -0,0 +1,39 @@ +#!/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") +} + +for i in "${libs[@]}"; do + fetch "$i" +done \ No newline at end of file diff --git a/files.txt b/files.txt index aab975c..06d9f1a 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 +libs/vector.lua +libs/http.lua +libs/fs.lua +libs/json.lua +libs/scm.lua \ No newline at end of file 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/fs/fs.lua b/libs/fs.lua similarity index 100% rename from fs/fs.lua rename to libs/fs.lua diff --git a/http/http.lua b/libs/http.lua similarity index 100% rename from http/http.lua rename to libs/http.lua diff --git a/json/json.lua b/libs/json.lua similarity index 100% rename from json/json.lua rename to libs/json.lua diff --git a/scm.lua b/libs/scm.lua similarity index 100% rename from scm.lua rename to libs/scm.lua diff --git a/vector/vector.lua b/libs/vector.lua similarity index 96% rename from vector/vector.lua rename to libs/vector.lua index 5f85473..32a9270 100644 --- a/vector/vector.lua +++ b/libs/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() From 20f5afe34f9f6c8074d8b6db47a1fde030d45364 Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Thu, 29 May 2025 13:42:08 +0200 Subject: [PATCH 2/3] refactor: moved files add modifed gitaction --- .github/workflows/test.yml | 2 +- files.txt | 10 +++++----- libs/fs.lua => fs.lua | 0 libs/http.lua => http.lua | 0 libs/json.lua => json.lua | 0 libs/scm.lua => scm.lua | 0 libs/vector.lua => vector.lua | 0 7 files changed, 6 insertions(+), 6 deletions(-) rename libs/fs.lua => fs.lua (100%) rename libs/http.lua => http.lua (100%) rename libs/json.lua => json.lua (100%) rename libs/scm.lua => scm.lua (100%) rename libs/vector.lua => vector.lua (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6c2b304..4e617e1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: luarocks install luasec - name: fetch dependencies - run: .fetch-deps.sh + run: ./fetch-deps.sh - name: test run: | diff --git a/files.txt b/files.txt index 06d9f1a..d38e55b 100644 --- a/files.txt +++ b/files.txt @@ -1,5 +1,5 @@ -libs/vector.lua -libs/http.lua -libs/fs.lua -libs/json.lua -libs/scm.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/libs/fs.lua b/fs.lua similarity index 100% rename from libs/fs.lua rename to fs.lua diff --git a/libs/http.lua b/http.lua similarity index 100% rename from libs/http.lua rename to http.lua diff --git a/libs/json.lua b/json.lua similarity index 100% rename from libs/json.lua rename to json.lua diff --git a/libs/scm.lua b/scm.lua similarity index 100% rename from libs/scm.lua rename to scm.lua diff --git a/libs/vector.lua b/vector.lua similarity index 100% rename from libs/vector.lua rename to vector.lua From 9dc08ffd9c3fb06ad4f7fd954385c727dcc3ef8e Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Thu, 29 May 2025 13:48:25 +0200 Subject: [PATCH 3/3] mkdir targetFolder --- .github/workflows/test.yml | 4 +++- fetch-deps.sh | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4e617e1..25e5482 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,9 @@ jobs: luarocks install luasec - name: fetch dependencies - run: ./fetch-deps.sh + run: | + chmod +x ./fetch-deps.sh + ./fetch-deps.sh - name: test run: | diff --git a/fetch-deps.sh b/fetch-deps.sh index f8a135f..ef5a6c3 100755 --- a/fetch-deps.sh +++ b/fetch-deps.sh @@ -34,6 +34,8 @@ fetch() { done < <(echo "$files_txt") } +mkdir -p $targetFolderName + for i in "${libs[@]}"; do fetch "$i" done \ No newline at end of file