Skip to content

Commit 630f6f1

Browse files
author
livecodeali
committed
[[ Tests ]] Add extension testing capabilities
This patch adds extension testing to our continuous integration, by adding a further check target in the extensions directory. At some point the tests/Makefile will need tweaking to make sure that only <extension>/tests/ directories are searched for suitable test handlers. Also TestLoadExtension has been added to the test library to facilitate loading of extensions in the TestSetup handler. At some point it might make sense for extension tests to automatically load themselves but for now it seems fine to have them do it explicitly. Note this does no dependency analysis, so it is currently not possible to test extensions that rely on modules other than those built in to the engine.
1 parent 1fe9bca commit 630f6f1

5 files changed

Lines changed: 111 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ check: check-$(guess_platform)
7070
check-common-%:
7171
$(MAKE) -C tests bin_dir=../$*-bin
7272
$(MAKE) -C ide/tests bin_dir=../../$*-bin
73+
$(MAKE) -C extensions bin_dir=../$*-bin
7374

7475
################################################################
7576
# Linux rules

docs/testing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Before running each test command, the test framework inserts a test library stac
4848
* `TestAssertBroken pDescription, pExpectTrue, pReasonBroken`: The same as `TestAssert`, but marking the test as "expected to fail". *pReasonBroken* should be a short explanation of why the test is currently expected to fail; it should almost always be a reference to a bug report, e.g. "bug 54321".
4949
* `TestGetEngineRepositoryPath`: A function that returns the path to the main LiveCode engine repository.
5050
* `TestGetIDERepositoryPath`: A function that returns the path to the LiveCode IDE repository.
51+
* `TestLoadExtension pName`: Attempt to load the extension with name `pName`, eg `TestLoadExtension "json"` will load the JSON library extension.
5152

5253
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:
5354
````

extensions/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This Makefile takes advantage of the fact that the engine's
2+
# "tests/Makefile" already does pretty much everything required for
3+
# running extension tests. Rather than duplicating it, it can
4+
# just be included with a few tweaks to its configuration.
5+
6+
# Only do livecodescript-based checks
7+
extensions-check: lcs-check
8+
.DEFAULT: extensions-check
9+
10+
top_srcdir ?= ..
11+
12+
# Things have now been setup enough that the engine's test Makefile
13+
# can perform the tests without any further configuration.
14+
include $(top_srcdir)/tests/Makefile
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
script "JSONLibrary"
2+
/*
3+
Copyright (C) 2015 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
on TestSetup
20+
TestLoadExtension "json"
21+
end TestSetup
22+
23+
on TestExportArray
24+
local tArray
25+
put "value" into tArray["key"]
26+
27+
local tExpected
28+
put "{" & quote & "key" & quote & ":" & quote & "value" & quote & "}" into tExpected
29+
30+
local tJson
31+
put JsonExport(tArray) into tJson
32+
# Ignore whitespace
33+
replace " " with empty in tJson
34+
35+
TestAssert "simple array export", tExpected is tJson
36+
end TestExportArray
37+
38+
on TestImportArray
39+
local tJson, tArray
40+
put "{" & quote & "key" & quote & ":" & quote & "value" & quote & "}" into tJson
41+
put JsonImport(tJson) into tArray
42+
43+
TestAssert "simple array import", tArray["key"] is "value"
44+
end TestImportArray

tests/_testlib.livecodescript

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,54 @@ end TestGetEngineRepositoryPath
126126
function TestGetIDERepositoryPath
127127
set the itemdelimiter to "/"
128128
return item 1 to -3 of the filename of me & slash & "ide"
129-
end TestGetIDERepositoryPath
129+
end TestGetIDERepositoryPath
130+
131+
on TestLoadExtension pName
132+
local tPath, tEnginePath
133+
put specialfolderpath("engine") into tPath
134+
put TestGetEngineRepositoryPath() into tEnginePath
135+
136+
local tError
137+
put "extension" && pName && "not found" into tError
138+
139+
# Find the built extensions folder
140+
local tExtensionsFolder
141+
set the itemdelimiter to slash
142+
repeat while tPath is not tEnginePath and tPath is not empty
143+
delete item -1 of tPath
144+
if there is a folder (tPath & slash & "packaged_extensions") then
145+
put (tPath & slash & "packaged_extensions") into tExtensionsFolder
146+
exit repeat
147+
end if
148+
end repeat
149+
150+
local tExtensionFolder
151+
if tExtensionsFolder is not empty then
152+
if there is a folder (tExtensionsFolder & slash & "com.livecode.extensions.livecode." & pName) then
153+
put (tExtensionsFolder & slash & "com.livecode.extensions.livecode." & pName) into tExtensionFolder
154+
end if
155+
end if
156+
157+
local tExtensionFile
158+
if tExtensionFolder is not empty then
159+
if there is a file (tExtensionFolder & slash & "module.lcm") then
160+
put (tExtensionFolder & slash & "module.lcm") into tExtensionFile
161+
end if
162+
end if
163+
164+
if tExtensionFile is not empty then
165+
if there is a folder (tExtensionFolder & slash & "resources") then
166+
load extension from file tExtensionFile with resource path (tExtensionFolder & slash & "resources")
167+
else
168+
load extension from file tExtensionFile
169+
end if
170+
171+
put the result into tError
172+
end if
173+
174+
if tError is not empty then
175+
write tError & return to stderr
176+
quit 1
177+
end if
178+
179+
end TestLoadExtension

0 commit comments

Comments
 (0)