Skip to content

Commit a221c94

Browse files
author
livecodeali
committed
[[ Tests ]] Add ability to load all extensions in test lib
1 parent 93218ae commit a221c94

2 files changed

Lines changed: 86 additions & 21 deletions

File tree

docs/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Before running each test command, the test framework inserts a test library stac
6262
* `TestGetEngineRepositoryPath`: A function that returns the path to the main LiveCode engine repository.
6363
* `TestGetIDERepositoryPath`: A function that returns the path to the LiveCode IDE repository.
6464
* `TestLoadExtension pName`: Attempt to load the extension with name `pName`, eg `TestLoadExtension "json"` will load the JSON library extension.
65-
65+
* `TestLoadAllExtensions`: Attempt to load all available extensions.
6666
Tests can have additional setup requirements before running, for example loading custom libraries. If the script test contains a handler called `TestSetup`, this will be run prior to running each test command. For example:
6767
````
6868
on TestSetup

tests/_testlib.livecodescript

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,30 @@ private command _TestWriteOutput pMessage
107107
write textEncode(pMessage, "UTF8") to stdout
108108
end _TestWriteOutput
109109

110+
private function _TestGetBuiltExtensionsFolder
111+
local tPath, tRepoPath
112+
put specialfolderpath("engine") into tPath
113+
put TestGetEngineRepositoryPath() into tRepoPath
114+
115+
# Find the built extensions folder
116+
set the itemdelimiter to slash
117+
repeat while tPath is not tRepoPath and tPath is not empty
118+
if there is a folder (tPath & slash & "packaged_extensions") then
119+
return (tPath & slash & "packaged_extensions")
120+
end if
121+
delete item -1 of tPath
122+
end repeat
123+
end _TestGetBuiltExtensionsFolder
124+
125+
private command _TestLoadExtension pFolder, pPath
126+
if there is a folder (pFolder & slash & "resources") then
127+
do "load extension from file pPath with resource path (pFolder & slash & " & quote & "resources" & quote & ")"
128+
else
129+
do "load extension from file pPath"
130+
end if
131+
return the result
132+
end _TestLoadExtension
133+
110134
----------------------------------------------------------------
111135
-- Unit test library functions
112136
----------------------------------------------------------------
@@ -153,24 +177,12 @@ on TestLoadExtension pName
153177
set the itemdelimiter to "."
154178
local tExtensionUnzipFolder
155179
put pName into tExtensionUnzipFolder
156-
157-
local tPath, tRepoPath
158-
put specialfolderpath("engine") into tPath
159-
put TestGetEngineRepositoryPath() into tRepoPath
160180

161181
local tError
162182
put "extension" && pName && "not found" into tError
163183

164-
# Find the built extensions folder
165184
local tExtensionsFolder
166-
set the itemdelimiter to slash
167-
repeat while tPath is not tRepoPath and tPath is not empty
168-
if there is a folder (tPath & slash & "packaged_extensions") then
169-
put (tPath & slash & "packaged_extensions") into tExtensionsFolder
170-
exit repeat
171-
end if
172-
delete item -1 of tPath
173-
end repeat
185+
put _TestGetBuiltExtensionsFolder() into tExtensionsFolder
174186

175187
local tExtensionFolder
176188
if tExtensionsFolder is not empty then
@@ -187,18 +199,71 @@ on TestLoadExtension pName
187199
end if
188200

189201
if tExtensionFile is not empty then
190-
if there is a folder (tExtensionFolder & slash & "resources") then
191-
do "load extension from file tExtensionFile with resource path (tExtensionFolder & slash & " & quote & "resources" & quote
192-
else
193-
do "load extension from file tExtensionFile"
194-
end if
195-
196-
put the result into tError
202+
_TestLoadExtension tExtensionFolder, tExtensionFile
197203
end if
204+
put the result into tError
198205

199206
if tError is not empty then
200207
write tError & return to stderr
201208
quit 1
202209
end if
203210

204211
end TestLoadExtension
212+
213+
on TestLoadAllExtensions
214+
local tDefaultFolder
215+
put the defaultFolder into tDefaultFolder
216+
217+
local tExtFolder
218+
put _TestGetBuiltExtensionsFolder() into tExtFolder
219+
set the defaultFolder to tExtFolder
220+
221+
local tExtensions
222+
put the folders into tExtensions
223+
224+
local tFiles, tAllExtensionsA
225+
local tHasCompiled, tSource
226+
227+
# Collect all the valid (and compiled) extension files
228+
repeat for each line tFolder in tExtensions
229+
if tFolder begins with "." then
230+
next repeat
231+
end if
232+
put false into tHasCompiled
233+
put empty into tSource
234+
put tExtFolder & slash before tFolder
235+
set the defaultFolder to tFolder
236+
put the files into tFiles
237+
repeat for each line tFile in tFiles
238+
if tFile ends with ".lcb" then
239+
put tFile into tSource
240+
else if tFile is "module.lcm" then
241+
put true into tHasCompiled
242+
end if
243+
if tHasCompiled and tSource is not empty then
244+
put tFolder into tAllExtensionsA[tFolder & slash & tSource]
245+
exit repeat
246+
end if
247+
end repeat
248+
end repeat
249+
250+
251+
set the defaultFolder to tDefaultFolder
252+
253+
# Use the lc-compile --deps option to sort by dependency
254+
local tLCCompile, tLCBFiles
255+
put the keys of tAllExtensionsA into tLCBFiles
256+
replace return with " " in tLCBFiles
257+
set the itemdelimiter to slash
258+
put item 1 to -2 of tExtFolder & slash & "lc-compile" into tLCCompile
259+
put shell(tLCCompile && "--deps order --" && tLCBFiles) into tLCBFiles
260+
if the result is not 0 then
261+
write the result & return to stderr
262+
quit 1
263+
end if
264+
265+
# Load the extensions in order
266+
repeat for each line tExtFile in tLCBFiles
267+
_TestLoadExtension tAllExtensionsA[tExtFile], tExtFile
268+
end repeat
269+
end TestLoadAllExtensions

0 commit comments

Comments
 (0)