Skip to content

Commit adec0a6

Browse files
ChristophLHRColdIV
andcommitted
Fixed Testing - FileSystem
Removed SCMInstaller Co-authored-by: Josh <[email protected]>
1 parent cb3cd8b commit adec0a6

File tree

3 files changed

+55
-36
lines changed

3 files changed

+55
-36
lines changed

scmInstaller.lua

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/Suite/fs.lua

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local fs = {}
2+
23
fs.libPath = "tmpLibs/"
34
fs.progPath = "tmpProg/"
45

@@ -28,7 +29,28 @@ do
2829
if mode == "w" then
2930
assert(file, "file could not be opened in : "..path.. " Mode : "..mode)
3031
end
31-
return file
32+
if not file then
33+
return nil
34+
end
35+
local file2 = {}
36+
setmetatable(file2, {__index = file})
37+
file2.base = file
38+
file2.readAll = function()
39+
return file2.base:read("*a")
40+
end
41+
file2["readLine"] = function()
42+
return file2.base:read("*l")
43+
end
44+
file2["write"] = function(content)
45+
return file2.base:write(content)
46+
end
47+
file2["read"] = function(...)
48+
return file2.base:read(...)
49+
end
50+
file2["close"] = function()
51+
file2.base:close()
52+
end
53+
return file2
3254
end
3355

3456
fs.exists = function(path)
@@ -100,9 +122,24 @@ do
100122
os.execute("mkdir " .. dir)
101123
end
102124
end
125+
end
126+
end
103127

128+
fs.delete = function (path)
129+
assert("string" == type(path), "path must be a string")
130+
if fs.exists(path) then
131+
os.execute("rm -rf " .. path)
104132
end
105133
end
134+
fs.readAll = function (path)
135+
assert("string" == type(path), "path must be a string")
136+
local file = io.open(path, "r")
137+
if not file then
138+
return nil
139+
end
140+
local content = file:read("*a")
141+
file:close()
142+
return content
143+
end
106144
end
107-
108-
return fs
145+
return fs

tests/test_spec.lua

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ end
6969
---@param ... any
7070
local function runTests(func, ...)
7171
---@class SCM
72+
7273
local scm = require("../scm")
7374
saveConfig(scm)
7475
saveScripts(scm)
@@ -87,16 +88,16 @@ end
8788

8889

8990
describe("Testing everything about SCM:", function()
90-
91+
--only neccessary for local testing
9192
describe("Copy Files", function()
93+
9294
assert.is_true(fs.copy("./scm.lua", "tmpFiles/scm.lua"), "Could not copy scm.lua")
9395
assert.is_true(fs.copy("./libs/scm/config.lua", "tmpFiles/config.lua"), "Could not copy config.lua")
9496
assert.is_true(fs.copy("./libs/scm/net.lua", "tmpFiles/net.lua"), "Could not copy net.lua")
9597
assert.is_true(fs.copy("./libs/scm/log.lua", "tmpFiles/log.lua"), "Could not copy log.lua")
9698
assert.is_true(fs.copy("./libs/scm/scriptManager.lua", "tmpFiles/scriptManager.lua"), "Could not copy scriptManager.lua")
9799
assert.is_true(fs.copy("./libs/scm/autocomplete.lua", "tmpFiles/autocomplete.lua"), "Could not copy autocomplete.lua")
98100
assert.is_true(fs.copy("./libs/scm/ui.lua", "tmpFiles/ui.lua"), "Could not copy ui.lua")
99-
assert.is_true(fs.copy("./scmInstaller.lua", "tmpFiles/scmInstaller.lua"), "Could not copy scmInstaller.lua")
100101
end)
101102

102103
describe("Require all SCM Modules", function()
@@ -109,7 +110,6 @@ describe("Testing everything about SCM:", function()
109110
assert.is.truthy(scm.UI)
110111
assert.is.truthy(scm.ScriptManager)
111112
assert.is.truthy(scm.Log)
112-
-- print("Require of all modules test passed")
113113
end)
114114
end)
115115

@@ -129,7 +129,6 @@ describe("Testing everything about SCM:", function()
129129
assert.equal("Wrong", config:getAll()["verbose"])
130130
config:set("verbose", true)
131131
assert.is.truthy(config:getAll()["verbose"] == true)
132-
-- print("Config test passed")
133132
end)
134133
end)
135134
end)
@@ -144,8 +143,6 @@ describe("Testing everything about SCM:", function()
144143
local scripts = scriptManager.scripts
145144
assert.is.truthy(scripts)
146145
assert.is.truthy(type(scripts) == "table")
147-
148-
-- print("1. ScriptManager test passed (Load Empty)")
149146
end
150147
)
151148
end)
@@ -163,7 +160,6 @@ describe("Testing everything about SCM:", function()
163160
assert.is.truthy(tFile)
164161
assert.is.truthy(tFile.test)
165162
os.remove("localtestFile.lua")
166-
-- print("2. ScriptManager test passed (Load Local)")
167163
end
168164
)
169165
end)
@@ -176,13 +172,24 @@ describe("Testing everything about SCM:", function()
176172
local scriptManager = scm.ScriptManager
177173
assert.is.truthy(testScript)
178174
assert.is.truthy(testScript.test)
179-
-- print("3. ScriptManager test passed (Load Remote)")
180175
end
181176
)
182177
end)
183178
end)
179+
describe("Update SCM", function()
180+
it("Update SCM", function()
181+
runTests(
182+
---@param scm SCM
183+
function(scm)
184+
-- TODO: implement
185+
end
186+
)
187+
end)
188+
end)
189+
184190
end)
185191

192+
-- only neccessary for local testing
186193
describe("Restore Files", function()
187194
assert.is_true(fs.copy("tmpFiles/scm.lua", "./scm.lua"), "Could not restore scm.lua")
188195
assert.is_true(fs.copy("tmpFiles/config.lua", "./libs/scm/config.lua"), "Could not restore config.lua")
@@ -191,7 +198,6 @@ describe("Testing everything about SCM:", function()
191198
assert.is_true(fs.copy("tmpFiles/scriptManager.lua", "./libs/scm/scriptManager.lua"), "Could not restore scriptManager.lua")
192199
assert.is_true(fs.copy("tmpFiles/autocomplete.lua", "./libs/scm/autocomplete.lua"), "Could not restore autocomplete.lua")
193200
assert.is_true(fs.copy("tmpFiles/ui.lua", "./libs/scm/ui.lua"), "Could not restore ui.lua")
194-
assert.is_true(fs.copy("tmpFiles/scmInstaller.lua", "./scmInstaller.lua"), "Could not restore scmInstaller.lua")
195201
os.execute("rm --recursive ./tmpFiles")
196202
end)
197203
end)

0 commit comments

Comments
 (0)