From 8d054c968d3245ee6b2607beb33954d0a9be94f2 Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:55:41 +0200 Subject: [PATCH 1/7] test: :sparkles: adding Testing (big WIP) --- .github/workflows/test.yml | 40 ++++++++++++++++++++++++++++++++++++++ .gitmodules | 6 ++++++ cc.pretty.lua | 1 + ccPackage.lua | 5 +++++ libs/miningClient-lib | 1 + scm.lua | 35 +++++++++++++++++++++++++++++++++ tests/test_spec.lua | 21 ++++++++++++++++++++ turtleEmulator-lib | 1 + 8 files changed, 110 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 .gitmodules create mode 100644 cc.pretty.lua create mode 100644 ccPackage.lua create mode 160000 libs/miningClient-lib create mode 100644 scm.lua create mode 100644 tests/test_spec.lua create mode 160000 turtleEmulator-lib diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5347502 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,40 @@ +name: Busted + + +on: [push, pull_request] + + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: checkout + uses: actions/checkout@v2 + with: + submodules: true + + - name: get lua + uses: leafo/gh-actions-lua@v10 + with: + luaVersion: "5.1" + + - name: get luarocks + uses: leafo/gh-actions-luarocks@v4 + with: + luaVersion: "5.1" + + - name: get busted and luasocket + run: | + luarocks install busted + luarocks install luasocket + luarocks install luasec + + - name: Git Submodule Update + run: | + git pull --recurse-submodules + git submodule update --init --remote --recursive + + - name: test + run: | + busted tests diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..005b303 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "turtleEmulator-lib"] + path = turtleEmulator-lib + url = https://github.com/mc-cc-scripts/turtleEmulator-lib +[submodule "libs/miningClient-lib"] + path = libs/miningClient-lib + url = https://github.com/mc-cc-scripts/miningClient-lib.git diff --git a/cc.pretty.lua b/cc.pretty.lua new file mode 100644 index 0000000..752cddd --- /dev/null +++ b/cc.pretty.lua @@ -0,0 +1 @@ +return print \ No newline at end of file diff --git a/ccPackage.lua b/ccPackage.lua new file mode 100644 index 0000000..0e435ea --- /dev/null +++ b/ccPackage.lua @@ -0,0 +1,5 @@ +local spath = + debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$","") +package.path = spath.."?.lua;" + ..package.path +require(spath.."turtleEmulator-lib/ccPackage") \ No newline at end of file diff --git a/libs/miningClient-lib b/libs/miningClient-lib new file mode 160000 index 0000000..3f95f83 --- /dev/null +++ b/libs/miningClient-lib @@ -0,0 +1 @@ +Subproject commit 3f95f83cc73035f8f864647ff1629b251886f1f3 diff --git a/scm.lua b/scm.lua new file mode 100644 index 0000000..4fd1302 --- /dev/null +++ b/scm.lua @@ -0,0 +1,35 @@ +--- This simulates the files requried from the SCM module +local scm = {} + +local settingsManager = {settings = {}} + +local require2 = require + +local function required(name) + print("Required: " .. name) + if (name == "settingsManager") then + return settingsManager + end + if (name == "cc.pretty") then + return print + end + return require2(name) +end + + +_G.require = required + + +function settingsManager:setget(name, value, default) + if value ~= nil then + self.settings[name] = value + end + value = self.settings[name] + return value or default +end + + function scm:load(name) + return required(name) + end + +return scm \ No newline at end of file diff --git a/tests/test_spec.lua b/tests/test_spec.lua new file mode 100644 index 0000000..6e56fe5 --- /dev/null +++ b/tests/test_spec.lua @@ -0,0 +1,21 @@ + +local spath = + debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$",""):gsub("/tests", ""):gsub("tests","") +if spath == "" then + spath = "./" +end +require(spath.."ccPackage") +--#region Globals + +---@type TurtleEmulator +local turtleEmulator = require("turtleEmulator") +_G.turtle = turtleEmulator:createTurtle() +-- local miner = require("miningClientSmall") + +--#endregion + +describe("test_spec", function() + it("should be able to run tests", function() + assert.is_true(true) + end) +end) \ No newline at end of file diff --git a/turtleEmulator-lib b/turtleEmulator-lib new file mode 160000 index 0000000..8d3331b --- /dev/null +++ b/turtleEmulator-lib @@ -0,0 +1 @@ +Subproject commit 8d3331b352b1c2ec775c55bd374e8b331a12f6e7 From bd9c6df154f7ea89d86816d2513d21b0e40f0afa Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:04:57 +0200 Subject: [PATCH 2/7] feat: :white_check_mark: Added Working Testing-Enviorment & First test --- .gitmodules | 6 + .vscode/settings.json | 7 + cc.pretty.lua | 1 - ccPackage.lua | 5 + libs/miningClient-lib | 2 +- miningClientSmall.lua | 8 +- scanResultMock.lua | 260 +++++++++++++++++++++++++++++++++++ scanner-lib | 1 + scm.lua | 35 ----- testSuit/eventCallStack.lua | 6 + testSuit/settingsManager.lua | 23 ++++ tests/test_spec.lua | 173 ++++++++++++++++++++++- turtleController-lib | 1 + turtleEmulator-lib | 2 +- 14 files changed, 479 insertions(+), 51 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 cc.pretty.lua create mode 100644 scanResultMock.lua create mode 160000 scanner-lib delete mode 100644 scm.lua create mode 100644 testSuit/eventCallStack.lua create mode 100644 testSuit/settingsManager.lua create mode 160000 turtleController-lib diff --git a/.gitmodules b/.gitmodules index 005b303..cc6a22e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,9 @@ [submodule "libs/miningClient-lib"] path = libs/miningClient-lib url = https://github.com/mc-cc-scripts/miningClient-lib.git +[submodule "turtleController-lib"] + path = turtleController-lib + url = https://github.com/mc-cc-scripts/turtleController-lib.git +[submodule "scanner-lib"] + path = scanner-lib + url = https://github.com/mc-cc-scripts/scanner-lib.git diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..af0bf3d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "Lua.diagnostics.globals": [ + "describe", + "before_each", + "it" + ] +} \ No newline at end of file diff --git a/cc.pretty.lua b/cc.pretty.lua deleted file mode 100644 index 752cddd..0000000 --- a/cc.pretty.lua +++ /dev/null @@ -1 +0,0 @@ -return print \ No newline at end of file diff --git a/ccPackage.lua b/ccPackage.lua index 0e435ea..5891afe 100644 --- a/ccPackage.lua +++ b/ccPackage.lua @@ -1,5 +1,10 @@ local spath = debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$","") package.path = spath.."?.lua;" + .. spath.."libs/miningClient-lib/?.lua;" + .. spath.."testSuit/?.lua;" + .. spath.."turtleController-lib/?.lua;" + .. spath.."scanner-lib/?.lua;" ..package.path + require(spath.."turtleEmulator-lib/ccPackage") \ No newline at end of file diff --git a/libs/miningClient-lib b/libs/miningClient-lib index 3f95f83..e7268fe 160000 --- a/libs/miningClient-lib +++ b/libs/miningClient-lib @@ -1 +1 @@ -Subproject commit 3f95f83cc73035f8f864647ff1629b251886f1f3 +Subproject commit e7268feb6e6f62178fcea5807b3e24c8bffdee82 diff --git a/miningClientSmall.lua b/miningClientSmall.lua index 0d56c47..a75012d 100644 --- a/miningClientSmall.lua +++ b/miningClientSmall.lua @@ -1,8 +1,5 @@ ---Requirements -local pretty = require "cc.pretty" - ---@class scm -local scm = require("./scm") +local scm = require("scm") ---@class SettingManager local sM = scm:load("settingsManager") ---@class HelperFunctions @@ -42,7 +39,6 @@ local function config() }; miningSettings = sM.setget('MiningSettings', miningSettings, miningSettings); end - pretty.pretty_print(miningSettings) end ---main script Function @@ -56,7 +52,7 @@ local function main() config() return end - miningLib.permanentFacingPostition = facingPostition() + miningLib.scanStartFacingTo = facingPostition() --Manuell Distance selection print("How far in Blocks?") diff --git a/scanResultMock.lua b/scanResultMock.lua new file mode 100644 index 0000000..5bea597 --- /dev/null +++ b/scanResultMock.lua @@ -0,0 +1,260 @@ +return { + { + y = 0, + x = -1, + name = "minecraft:deepslate_iron_ore", + z = -2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 1, + x = -1, + name = "minecraft:deepslate_iron_ore", + z = -2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 2, + x = -1, + name = "minecraft:deepslate_iron_ore", + z = -2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 2, + x = -1, + name = "minecraft:deepslate_iron_ore", + z = -1, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 2, + x = -1, + name = "minecraft:deepslate_iron_ore", + z = 0, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 2, + x = -1, + name = "minecraft:deepslate_iron_ore", + z = 1, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 2, + x = -1, + name = "minecraft:deepslate_iron_ore", + z = 2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 0, + x = 0, + name = "minecraft:deepslate_iron_ore", + z = -2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 0, + x = 0, + name = "computercraft:turtle_advanced", + z = 0, + tags = { + "minecraft:block/computercraft:turtle", + "minecraft:block/minecraft:mineable/pickaxe", + }, + }, + { + y = 1, + x = 0, + name = "minecraft:deepslate_iron_ore", + z = -2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 2, + x = 0, + name = "minecraft:deepslate_iron_ore", + z = 2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 1, + x = 1, + name = "minecraft:deepslate_iron_ore", + z = -2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 2, + x = 1, + name = "minecraft:deepslate_iron_ore", + z = -2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 2, + x = 1, + name = "minecraft:deepslate_iron_ore", + z = 2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 2, + x = 2, + name = "minecraft:deepslate_iron_ore", + z = -2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 2, + x = 2, + name = "minecraft:deepslate_iron_ore", + z = 2, + tags = { + "minecraft:block/minecraft:mineable/pickaxe", + "minecraft:block/forge:ores/iron", + "minecraft:block/minecraft:needs_stone_tool", + "minecraft:block/minecraft:overworld_carver_replaceables", + "minecraft:block/forge:ore_rates/singular", + "minecraft:block/forge:ores_in_ground/deepslate", + "minecraft:block/forge:ores", + "minecraft:block/minecraft:iron_ores", + }, + }, + { + y = 0, + x = 1, + name = "minecraft:dirt", + z = -3, + tags = { + }, + }, +} \ No newline at end of file diff --git a/scanner-lib b/scanner-lib new file mode 160000 index 0000000..2bbb708 --- /dev/null +++ b/scanner-lib @@ -0,0 +1 @@ +Subproject commit 2bbb7084dd7556af3d4e243775e00ad35dfc0626 diff --git a/scm.lua b/scm.lua deleted file mode 100644 index 4fd1302..0000000 --- a/scm.lua +++ /dev/null @@ -1,35 +0,0 @@ ---- This simulates the files requried from the SCM module -local scm = {} - -local settingsManager = {settings = {}} - -local require2 = require - -local function required(name) - print("Required: " .. name) - if (name == "settingsManager") then - return settingsManager - end - if (name == "cc.pretty") then - return print - end - return require2(name) -end - - -_G.require = required - - -function settingsManager:setget(name, value, default) - if value ~= nil then - self.settings[name] = value - end - value = self.settings[name] - return value or default -end - - function scm:load(name) - return required(name) - end - -return scm \ No newline at end of file diff --git a/testSuit/eventCallStack.lua b/testSuit/eventCallStack.lua new file mode 100644 index 0000000..aa17cc1 --- /dev/null +++ b/testSuit/eventCallStack.lua @@ -0,0 +1,6 @@ +local class = require("ccClass") +local eventCallStack = class("eventCallStack") +function eventCallStack:invoke() + return +end +return eventCallStack \ No newline at end of file diff --git a/testSuit/settingsManager.lua b/testSuit/settingsManager.lua new file mode 100644 index 0000000..8fb68a3 --- /dev/null +++ b/testSuit/settingsManager.lua @@ -0,0 +1,23 @@ +local settingsManager = {} +function settingsManager:setget(name, value, default) + if not self.settings then + self.settings = {} + end + if value ~= nil then + self.settings[name] = value + end + value = self.settings[name] + return value or default +end +local proxy = {} +local mt = { + __index = function (_, key) + local value = settingsManager[key] + return function(...) + return value(settingsManager, ...) + end + end +} +-- create Proxy +setmetatable(proxy, mt) +return proxy \ No newline at end of file diff --git a/tests/test_spec.lua b/tests/test_spec.lua index 6e56fe5..d010d0c 100644 --- a/tests/test_spec.lua +++ b/tests/test_spec.lua @@ -1,21 +1,180 @@ +---@class are +---@field same function +---@field equal function +---@field equals function + +---@class is +---@field truthy function +---@field falsy function +---@field not_true function +---@field not_false function + +---@class has +---@field error function +---@field errors function + +---@class assert +---@field are are +---@field is is +---@field are_not are +---@field is_not is +---@field has has +---@field has_no has +---@field True function +---@field False function +---@field has_error function +---@field is_false function +---@field is_true function +---@field equal function +assert = assert local spath = - debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$",""):gsub("/tests", ""):gsub("tests","") +debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$",""):gsub("/tests", ""):gsub("tests","") if spath == "" then spath = "./" end require(spath.."ccPackage") ---#region Globals +local Vector = require("vector") +local scanResultMock = require("scanResultMock") ---@type TurtleEmulator local turtleEmulator = require("turtleEmulator") -_G.turtle = turtleEmulator:createTurtle() --- local miner = require("miningClientSmall") + + +-- require the files which depend on the globals +local geoScanner +local miningClient + +local geoScannerPeripheral +local readOperationCounter = 0 +_G.read = function () + readOperationCounter = readOperationCounter + 1 + if readOperationCounter == 1 then + return "X" + end + if readOperationCounter == 2 then + return "1" + end +end --#endregion -describe("test_spec", function() - it("should be able to run tests", function() - assert.is_true(true) +---comment +---@param turtle TurtleProxy +---@param distance number +---@return Vector[] +local function createPoints(turtle, distance, areaSize) + local points = distance / areaSize + local pointTable = {} + local currentPositon = turtle.position * 1 + table.insert(pointTable, currentPositon) + for i = 1, points,1 do + currentPositon = currentPositon + (turtle.facing * areaSize) + table.insert(pointTable, currentPositon) + end + return pointTable +end +local function beforeEach() + local geoScannerItem = { + name = "advancedperipherals:geo_scanner", + count = 1, + equipable = true, + placeAble = false + } + local chuckyItem = { + name = "advancedperipherals:chunk_controller", + count = 1, + equipable = true, + placeAble = false + } + local pickaxe = { + name = "minecraft:diamond_pickaxe", + count = 1, + equipable = true, + placeAble = false + } + local coal = { + name = "minecraft:coal", + count = 64, + equipable = false, + placeAble = false, + fuelgain = 8 + } + + turtleEmulator:clearBlocks() + turtleEmulator:clearTurtles() + + if package.loaded["turtleController"] ~= nil then + package.loaded["turtleController"] = nil + package.loaded["miningClient"] = nil + end + -- reset globals + _G.turtle = turtleEmulator:createTurtle() + local peripheral = turtle.getPeripheralModule() + _G.peripheral = peripheral + + -- require the files which depend on the "new" globals + geoScanner = require("geoScanner") + miningClient = require("miningClient") + geoScannerPeripheral = turtleEmulator:addPeripheralToItem(geoScannerItem, geoScanner, turtle) + + turtle.addItemToInventory(geoScannerItem, 1) + turtle.addItemToInventory(chuckyItem, 2) + turtle.addItemToInventory(pickaxe, 3) + turtle.addItemToInventory(coal, 4) + + -- require the files which depend on the globals +end + + +describe("empty World", function() + before_each(function() + beforeEach() + end) + it(" - return to start", function() + ---@cast geoScannerPeripheral GeoScanner + geoScannerPeripheral.scanResult = {} + miningClient.scanStartFacingTo = "X" + miningClient:main(createPoints(turtle, 10, 1)) + assert.are.equal(Vector.new(0, 0, 0), turtle.position) + end) +end) +describe("World with ores", function() + before_each(function() + beforeEach() + end) + it(" - cleared all Ores", function() + local mappingFunc = function(scanData) + return { + item = { + name = scanData.name, + tags = scanData.tags + }, + position = Vector.new(scanData.x, scanData.y, scanData.z), + checkActionValidFunc = function() + return false + end + } + end + turtleEmulator:readBlocks(scanResultMock, mappingFunc) + ---@cast geoScannerPeripheral GeoScanner + geoScannerPeripheral.scanEmulator = true + miningClient.scanStartFacingTo = "X" + miningClient:main(createPoints(turtle, 2, 1)) + local count = 0 + local dirt + for _, block in pairs(turtleEmulator.blocks) do + if block.item.name == "minecraft:deepslate_iron_ore" then + count = count + 1 + elseif block.item.name == "minecraft:dirt" then + dirt = block + else + error("unknown block found") + end + end + assert.are.equal(0, count) + assert.are.equal(Vector.new(0, 0, 0), turtle.position) + assert.are.equal(Vector.new(1, 0, 0), turtle.facing) + assert.is.not_false(dirt) end) end) \ No newline at end of file diff --git a/turtleController-lib b/turtleController-lib new file mode 160000 index 0000000..43a308c --- /dev/null +++ b/turtleController-lib @@ -0,0 +1 @@ +Subproject commit 43a308ce912d933342fa850e19bf90dde3df67db diff --git a/turtleEmulator-lib b/turtleEmulator-lib index 8d3331b..5c90511 160000 --- a/turtleEmulator-lib +++ b/turtleEmulator-lib @@ -1 +1 @@ -Subproject commit 8d3331b352b1c2ec775c55bd374e8b331a12f6e7 +Subproject commit 5c90511ab59ef546ec987ff77984cb0f40d4e44e From 1a9c2f0e90d44ebd4ea17914e8cf9d7948500dc1 Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Sun, 25 May 2025 21:53:58 +0200 Subject: [PATCH 3/7] further testing --- miningClientSmall.lua | 2 ++ tests/test_spec.lua | 28 +++++++++++++++++----------- turtleEmulator-lib | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/miningClientSmall.lua b/miningClientSmall.lua index a75012d..fa5d73b 100644 --- a/miningClientSmall.lua +++ b/miningClientSmall.lua @@ -73,3 +73,5 @@ local function main() end main() + +shell.run("gps", "host", x, y, z) \ No newline at end of file diff --git a/tests/test_spec.lua b/tests/test_spec.lua index d010d0c..72ae72f 100644 --- a/tests/test_spec.lua +++ b/tests/test_spec.lua @@ -74,6 +74,19 @@ local function createPoints(turtle, distance, areaSize) end return pointTable end + +local function countblocks(blockName) + local count = 0 + local lastBlock + for _, block in pairs(turtleEmulator.blocks) do + if block.item.name == blockName then + count = count + 1 + lastBlock = block + end + end + return count +end + local function beforeEach() local geoScannerItem = { name = "advancedperipherals:geo_scanner", @@ -127,6 +140,7 @@ local function beforeEach() end + describe("empty World", function() before_each(function() beforeEach() @@ -160,18 +174,10 @@ describe("World with ores", function() ---@cast geoScannerPeripheral GeoScanner geoScannerPeripheral.scanEmulator = true miningClient.scanStartFacingTo = "X" + assert.are.equal(15, countblocks("minecraft:deepslate_iron_ore")) miningClient:main(createPoints(turtle, 2, 1)) - local count = 0 - local dirt - for _, block in pairs(turtleEmulator.blocks) do - if block.item.name == "minecraft:deepslate_iron_ore" then - count = count + 1 - elseif block.item.name == "minecraft:dirt" then - dirt = block - else - error("unknown block found") - end - end + local count = countblocks("minecraft:deepslate_iron_ore") + local dirt = countblocks("minecraft:dirt") assert.are.equal(0, count) assert.are.equal(Vector.new(0, 0, 0), turtle.position) assert.are.equal(Vector.new(1, 0, 0), turtle.facing) diff --git a/turtleEmulator-lib b/turtleEmulator-lib index 5c90511..b6ceaa3 160000 --- a/turtleEmulator-lib +++ b/turtleEmulator-lib @@ -1 +1 @@ -Subproject commit 5c90511ab59ef546ec987ff77984cb0f40d4e44e +Subproject commit b6ceaa3d653b980abf667651b4e9509fb11faed2 From 5853f0606388e67e166bb8619b71aa1e8f2e816a Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Mon, 2 Jun 2025 20:08:32 +0200 Subject: [PATCH 4/7] remove submodules --- .gitignore | 1 + .gitmodules | 12 -------- ccPackage.lua | 10 ------- fetch-deps.sh | 54 ++++++++++++++++++++++++++++++++++++ libs/miningClient-lib | 1 - miningClientSmall.lua | 2 -- scanner-lib | 1 - testSuit/eventCallStack.lua | 6 ---- testSuit/settingsManager.lua | 23 --------------- tests/test_spec.lua | 12 ++++---- turtleController-lib | 1 - turtleEmulator-lib | 1 - 12 files changed, 61 insertions(+), 63 deletions(-) create mode 100644 .gitignore delete mode 100644 .gitmodules delete mode 100644 ccPackage.lua create mode 100755 fetch-deps.sh delete mode 160000 libs/miningClient-lib delete mode 160000 scanner-lib delete mode 100644 testSuit/eventCallStack.lua delete mode 100644 testSuit/settingsManager.lua delete mode 160000 turtleController-lib delete mode 160000 turtleEmulator-lib diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..403acf4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/libs diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index cc6a22e..0000000 --- a/.gitmodules +++ /dev/null @@ -1,12 +0,0 @@ -[submodule "turtleEmulator-lib"] - path = turtleEmulator-lib - url = https://github.com/mc-cc-scripts/turtleEmulator-lib -[submodule "libs/miningClient-lib"] - path = libs/miningClient-lib - url = https://github.com/mc-cc-scripts/miningClient-lib.git -[submodule "turtleController-lib"] - path = turtleController-lib - url = https://github.com/mc-cc-scripts/turtleController-lib.git -[submodule "scanner-lib"] - path = scanner-lib - url = https://github.com/mc-cc-scripts/scanner-lib.git diff --git a/ccPackage.lua b/ccPackage.lua deleted file mode 100644 index 5891afe..0000000 --- a/ccPackage.lua +++ /dev/null @@ -1,10 +0,0 @@ -local spath = - debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$","") -package.path = spath.."?.lua;" - .. spath.."libs/miningClient-lib/?.lua;" - .. spath.."testSuit/?.lua;" - .. spath.."turtleController-lib/?.lua;" - .. spath.."scanner-lib/?.lua;" - ..package.path - -require(spath.."turtleEmulator-lib/ccPackage") \ No newline at end of file diff --git a/fetch-deps.sh b/fetch-deps.sh new file mode 100755 index 0000000..3f00bba --- /dev/null +++ b/fetch-deps.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# ---- Whats happening ---- # + +# This fetches the dependencies listed in the "libs" variable and saves them in the targetFolder + +set -e + +libs=( + "TestSuite-lib" + "TurtleEmulator-lib" + "scanner-lib" + "turtleController-lib" + "ccClass-lib" + "miningClient-lib" + "helperFunctions-lib" + "eventHandler-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 + url="https://raw.githubusercontent.com/$repo/$1/$branch/$FILE" + + mkdir -p "$(dirname "$targetFolderName/$FILE")" # create the folder (and subfolders specified in the files.txt) + rm -f $targetFolderName/$FILE.lua # rm existing file + if ! curl -s -o "$targetFolderName/$FILE" "$url"; then + echo "could not get / write the file $i: '$FILE' to the folder '$targetFolderName'" + exit 1 + fi + # echo "saved $1: '$FILE' in '$targetFolderName'" + done < <(echo "$files_txt") +} + +if [[ $# -eq 0 ]]; then + # No arguments given, fetch all + for i in "${libs[@]}"; do + fetch "$i" + done +else + # Argument given, fetch arguemt + fetch "$1" +fi \ No newline at end of file diff --git a/libs/miningClient-lib b/libs/miningClient-lib deleted file mode 160000 index 55ca04f..0000000 --- a/libs/miningClient-lib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 55ca04f75f582113d1f880caa8149997101832e4 diff --git a/miningClientSmall.lua b/miningClientSmall.lua index 3f2c446..89ccbbf 100644 --- a/miningClientSmall.lua +++ b/miningClientSmall.lua @@ -1,7 +1,5 @@ ---@class scm local scm = require("scm") ----@class SettingManager -local sM = scm:load("settingsManager") ---@class HelperFunctions local helper = scm:load("helperFunctions") ---@class miningLib diff --git a/scanner-lib b/scanner-lib deleted file mode 160000 index 2880a00..0000000 --- a/scanner-lib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2880a007c4c8eb9e06a1a6baee8a968798473cd5 diff --git a/testSuit/eventCallStack.lua b/testSuit/eventCallStack.lua deleted file mode 100644 index aa17cc1..0000000 --- a/testSuit/eventCallStack.lua +++ /dev/null @@ -1,6 +0,0 @@ -local class = require("ccClass") -local eventCallStack = class("eventCallStack") -function eventCallStack:invoke() - return -end -return eventCallStack \ No newline at end of file diff --git a/testSuit/settingsManager.lua b/testSuit/settingsManager.lua deleted file mode 100644 index 8fb68a3..0000000 --- a/testSuit/settingsManager.lua +++ /dev/null @@ -1,23 +0,0 @@ -local settingsManager = {} -function settingsManager:setget(name, value, default) - if not self.settings then - self.settings = {} - end - if value ~= nil then - self.settings[name] = value - end - value = self.settings[name] - return value or default -end -local proxy = {} -local mt = { - __index = function (_, key) - local value = settingsManager[key] - return function(...) - return value(settingsManager, ...) - end - end -} --- create Proxy -setmetatable(proxy, mt) -return proxy \ No newline at end of file diff --git a/tests/test_spec.lua b/tests/test_spec.lua index 72ae72f..fdd13cf 100644 --- a/tests/test_spec.lua +++ b/tests/test_spec.lua @@ -28,13 +28,13 @@ ---@field equal function assert = assert -local spath = -debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$",""):gsub("/tests", ""):gsub("tests","") -if spath == "" then - spath = "./" -end -require(spath.."ccPackage") +package.path = "libs/?.lua;" + .. "libs/inventory/?.lua;" + .. "libs/peripherals/?.lua;" + .. package.path + +_G.settings = require("settings") local Vector = require("vector") local scanResultMock = require("scanResultMock") ---@type TurtleEmulator diff --git a/turtleController-lib b/turtleController-lib deleted file mode 160000 index 8816bf4..0000000 --- a/turtleController-lib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8816bf4de67da590aa75c2a6ad7b537b63aca446 diff --git a/turtleEmulator-lib b/turtleEmulator-lib deleted file mode 160000 index 534fb6c..0000000 --- a/turtleEmulator-lib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 534fb6c851ba1cb76758b299e514668460ed7674 From c31464e426952025b873555ee08ee151f2a2c367 Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Mon, 2 Jun 2025 20:17:18 +0200 Subject: [PATCH 5/7] fixed scm reference --- miningClientSmall.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miningClientSmall.lua b/miningClientSmall.lua index 89ccbbf..7cc7ef2 100644 --- a/miningClientSmall.lua +++ b/miningClientSmall.lua @@ -1,5 +1,5 @@ ---@class scm -local scm = require("scm") +local scm = require("./scm") ---@class HelperFunctions local helper = scm:load("helperFunctions") ---@class miningLib From 97ac154daf4b8fcfcd95cab40fdea4baef3beb30 Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Mon, 2 Jun 2025 20:27:21 +0200 Subject: [PATCH 6/7] fixed text.yml --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5347502..50fdc4b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,11 +30,11 @@ jobs: luarocks install luasocket luarocks install luasec - - name: Git Submodule Update + - name: fetch dependencies run: | - git pull --recurse-submodules - git submodule update --init --remote --recursive - + chmod +x ./fetch-deps.sh + ./fetch-deps.sh + - name: test run: | busted tests From 6d39047eaf3702ee8d4a084e62b69b71b526e046 Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Sun, 8 Jun 2025 19:13:36 +0200 Subject: [PATCH 7/7] added clear Inventory Testing --- fetch-deps.sh | 2 ++ tests/test_spec.lua | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/fetch-deps.sh b/fetch-deps.sh index 3f00bba..0806d65 100755 --- a/fetch-deps.sh +++ b/fetch-deps.sh @@ -15,6 +15,8 @@ libs=( "miningClient-lib" "helperFunctions-lib" "eventHandler-lib" + "turtleResourceManager-lib" + "config-lib" ) # Basic setup variables diff --git a/tests/test_spec.lua b/tests/test_spec.lua index fdd13cf..c8d4d93 100644 --- a/tests/test_spec.lua +++ b/tests/test_spec.lua @@ -122,6 +122,7 @@ local function beforeEach() package.loaded["miningClient"] = nil end -- reset globals + ---@type TurtleMock _G.turtle = turtleEmulator:createTurtle() local peripheral = turtle.getPeripheralModule() _G.peripheral = peripheral @@ -158,6 +159,14 @@ describe("World with ores", function() beforeEach() end) it(" - cleared all Ores", function() + for i = 5, 15, 1 do + turtle.addItemToInventory({name = "minecraft:stone", count = 64, maxcount = 64, placeAble = true}) + end + local tmpChest = {name = "enderchests:ender_chest", count = 1, maxcount = 1, placeAble = true} + turtle.addItemToInventory(tmpChest, 16) + local enderCHest = turtleEmulator:addInventoryToItem(tmpChest) + + local mappingFunc = function(scanData) return { item = { @@ -182,5 +191,6 @@ describe("World with ores", function() assert.are.equal(Vector.new(0, 0, 0), turtle.position) assert.are.equal(Vector.new(1, 0, 0), turtle.facing) assert.is.not_false(dirt) + assert.is.falsy(turtle.getItemDetail(10)) end) end) \ No newline at end of file