Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 4fb9eac

Browse files
committed
[[ Tests ]] Test extension docs
1 parent f04b00f commit 4fb9eac

2 files changed

Lines changed: 91 additions & 23 deletions

File tree

tests/_testlib.livecodescript

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ function TestGetExtractedDocsFolder
310310
return _TestGetBuildFolder() & slash & "extracted_docs"
311311
end TestGetExtractedDocsFolder
312312

313+
function TestGetPackagedExtensionsFolder
314+
return _TestGetBuildFolder() & slash & "packaged_extensions"
315+
end TestGetPackagedExtensionsFolder
316+
313317
on TestLoadExtension pName
314318
if pName is among the lines of the loadedExtensions then
315319
return empty

tests/lcs/docs/validate-dictionary.livecodescript

Lines changed: 87 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ for more details.
1616
You should have received a copy of the GNU General Public License
1717
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1818

19-
constant kAPITypes = "command,function,property,message,constant,keyword,control structure,operator,statement,expression"
20-
constant kGlossaryTypes = "library,glossary,object,widget"
19+
constant kAPITypes = "command,function,property,message,constant,keyword,control structure,operator,statement,expression,handler"
20+
constant kGlossaryTypes = "library,glossary,object,widget,module"
2121
constant kOS = "iOS,Android,Mac,Windows,Linux,RPi,html5"
2222
constant kPlatform = "desktop,mobile,server,filemaker"
23-
23+
2424
on TestSetup
2525
TestSkipIfNot "docs"
2626

@@ -42,14 +42,19 @@ on TestDocsValidateDictionary
4242
put TestGetEngineRepositoryPath() & "/docs" into tDocsPath
4343
put revDocsParseDictionaryToLibraryArray(tDocsPath) into tDocsArray
4444

45-
__TestDocsLibraryArray tDocsArray
45+
__TestDocsLibraryArray tDocsPath, tDocsArray
4646
end TestDocsValidateDictionary
4747

4848
on TestDocsValidateExtractedLibraries
4949
local tExtractedDocsFolder
5050
put TestGetExtractedDocsFolder() into tExtractedDocsFolder
5151

52-
TestAssert "extracted docs folder exists", there is a folder tExtractedDocsFolder
52+
-- There are not necessarily any docs in the extracted docs folder now.
53+
-- Re-uncomment if and when there are.
54+
//TestAssert "extracted docs folder exists", there is a folder tExtractedDocsFolder
55+
if there is not a folder tExtractedDocsFolder then
56+
exit TestDocsValidateExtractedLibraries
57+
end if
5358

5459
local tFiles
5560
put files(tExtractedDocsFolder) into tFiles
@@ -69,17 +74,75 @@ on TestDocsValidateExtractedLibraries
6974

7075
put revDocsParseDocFileToLibraryArray(tDocsPath, item -2 of tFile, "LiveCode") into tDocsArray
7176

72-
TestAssert "type of" && tFile && "is library", tDocsArray["type"] is "library"
73-
TestAssert "name of" && tFile && "is not empty", tDocsArray["name"] is not empty
74-
TestAssert "display name of" && tFile && "is not empty", tDocsArray["display name"] is not empty
75-
TestAssert "author name of" && tFile && "is not empty", tDocsArray["author"] is not empty
76-
TestAssert "description of" && tFile && "is not empty", tDocsArray["description"] is not empty
77+
TestAssert tDocsPath & ":" && "type of" && tFile && "is library", tDocsArray["type"] is "library"
78+
TestAssert tDocsPath & ":" && "name of" && tFile && "is not empty", tDocsArray["name"] is not empty
79+
TestAssert tDocsPath & ":" && "display name of" && tFile && "is not empty", tDocsArray["display name"] is not empty
80+
TestAssert tDocsPath & ":" && "author name of" && tFile && "is not empty", tDocsArray["author"] is not empty
81+
TestAssert tDocsPath & ":" && "description of" && tFile && "is not empty", tDocsArray["description"] is not empty
7782

78-
__TestDocsLibraryArray tDocsArray["doc"]
83+
__TestDocsLibraryArray tDocsPath, tDocsArray["doc"]
7984
end repeat
8085
end TestDocsValidateExtractedLibraries
8186

82-
command __TestDocsLibraryArray pLibrary
87+
on TestDocsValidateExtensionDocs
88+
local tExtensionsFolder
89+
put TestGetPackagedExtensionsFolder() into tExtensionsFolder
90+
91+
TestAssert "packaged extensions folder exists", there is a folder tExtensionsFolder
92+
93+
local tExtensions
94+
put folders(tExtensionsFolder) into tExtensions
95+
filter tExtensions without ".*"
96+
97+
repeat for each line tExtension in tExtensions
98+
local tFiles
99+
put files(tExtensionsFolder & slash & tExtension) into tFiles
100+
101+
filter tFiles with "*.lcdoc"
102+
103+
TestAssert tExtension && "has docs file", tFiles is not empty
104+
105+
set the itemDelimiter to "."
106+
107+
local tFile
108+
repeat for each line tFile in tFiles
109+
local tDocsPath, tDocsArray
110+
put tExtensionsFolder & slash & tExtension & slash & tFile into tDocsPath
111+
112+
if url("file:" & tDocsPath) is empty then
113+
TestAssertBroken tDocsPath & ": non-empty docs", false
114+
next repeat
115+
end if
116+
117+
put revDocsParseDocFileToLibraryArray(tDocsPath, tExtension, "LiveCode") into tDocsArray
118+
119+
TestAssert tDocsPath & ":" && "type of" && tFile && "is not empty", tDocsArray["type"] is not empty
120+
TestAssert tDocsPath & ":" && "display name of" && tFile && "is not empty", tDocsArray["display name"] is not empty
121+
TestAssert tDocsPath & ":" && "author name of" && tFile && "is not empty", tDocsArray["author"] is not empty
122+
123+
-- At the moment, allow docs to have either summary or description
124+
local tExtensionNoSummary, tExtensionNoDescription
125+
put tDocsArray["summary"] is empty into tExtensionNoSummary
126+
put tDocsArray["description"] is empty into tExtensionNoDescription
127+
128+
if tExtensionNoSummary and tExtensionNoDescription then
129+
TestAssert tDocsPath & ":" && "summary of" && tFile && "is not empty", false
130+
TestAssert tDocsPath & ":" && "description of" && tFile && "is not empty", false
131+
else if tExtensionNoSummary then
132+
TestAssertBroken tDocsPath & ":" && "summary of" && tFile && "is not empty", false
133+
else if tExtensionNoDescription then
134+
TestAssertBroken tDocsPath & ":" && "description of" && tFile && "is not empty", false
135+
else
136+
TestAssert tDocsPath & ":" && "summary of" && tFile && "is not empty", true
137+
TestAssert tDocsPath & ":" && "description of" && tFile && "is not empty", true
138+
end if
139+
140+
__TestDocsLibraryArray tDocsPath, tDocsArray["doc"], tDocsArray["type"] is not "module"
141+
end repeat
142+
end repeat
143+
end TestDocsValidateExtensionDocs
144+
145+
command __TestDocsLibraryArray pDocsPath, pLibrary, pTestSyntax
83146
local tElement
84147

85148
local tReferences
@@ -92,15 +155,15 @@ command __TestDocsLibraryArray pLibrary
92155
local tIndex
93156

94157
-- test name required
95-
TestAssert "name of" && tElement["display name"] && tElement["type"] && "not empty", tElement["display name"] is not empty
158+
TestAssert pDocsPath & ":" && "name of" && tElement["display name"] && tElement["type"] && "not empty", tElement["display name"] is not empty
96159

97160
-- test type is valid
98-
TestAssert "type of" && tElement["display name"] && tElement["type"] && "is valid", tElement["type"] is among the items of (kAPITypes,kGlossaryTypes)
161+
TestAssert pDocsPath & ":" && "type of" && tElement["display name"] && tElement["type"] && "is valid", tElement["type"] is among the items of (kAPITypes,kGlossaryTypes)
99162

100163
-- test syntaxes exist for API entries
101164
local tSyntaxParams
102165
if tElement["type"] is among the items of kAPITypes then
103-
TestAssert "API entry for" && tElement["display name"] && tElement["type"] && "has syntax", tElement["syntax"] is an array
166+
TestAssert pDocsPath & ":" && "API entry for" && tElement["display name"] && tElement["type"] && "has syntax", tElement["syntax"] is an array
104167

105168
-- parse out params to validate against documented params
106169
put 1 into tIndex
@@ -119,25 +182,26 @@ command __TestDocsLibraryArray pLibrary
119182
end repeat
120183

121184
-- test summary required
122-
TestAssert "summary of" && tElement["display name"] && tElement["type"] && "not empty", tElement["summary"] is not empty
185+
TestAssert pDocsPath & ":" && "summary of" && tElement["display name"] && tElement["type"] && "not empty", tElement["summary"] is not empty
123186

124187
end if
125188

126189
-- !TODO test associations are valid
127190

128191
-- test OS
129192
repeat for each element tValue in tElement["OS"]
130-
TestAssert "OS entry" && tValue && "for" && tElement["display name"] && tElement["type"] && "is valid", tValue is among the items of kOS
193+
TestAssert pDocsPath & ":" && "OS entry" && tValue && "for" && tElement["display name"] && tElement["type"] && "is valid", tValue is among the items of kOS
131194
end repeat
132195

133196
-- test platform
134197
repeat for each element tValue in tElement["Platform"]
135-
TestAssert "Platform entry" && tValue && "for" && tElement["display name"] && tElement["type"] && "is valid", tValue is among the items of kPlatform
198+
TestAssert pDocsPath & ":" && "Platform entry" && tValue && "for" && tElement["display name"] && tElement["type"] && "is valid", tValue is among the items of kPlatform
136199
end repeat
137200

138201
-- test examples
139202
put 1 into tIndex
140-
if tElement["display name"] is not among the words of "sessionName errorObject" then
203+
if pTestSyntax is not false and \
204+
tElement["display name"] is not among the words of "sessionName errorObject" then
141205
repeat for each element tValue in tElement["Example"]
142206

143207
if word 1 of tValue is among the words of "end case" then
@@ -216,7 +280,7 @@ command __TestDocsLibraryArray pLibrary
216280
end if
217281
end if
218282

219-
TestAssert "example" && tIndex && "of" && tElement["display name"] && tElement["Type"] && "compiles", tResult is empty
283+
TestAssert pDocsPath & ":" && "example" && tIndex && "of" && tElement["display name"] && tElement["Type"] && "compiles", tResult is empty
220284

221285
if tResult is not empty then
222286
TestDiagnostic "Example:" & return & tTempValue & return & "Script Parsing Error:" & return & \
@@ -249,10 +313,10 @@ command __TestDocsLibraryArray pLibrary
249313
SplitParam tParam
250314

251315
-- params in syntax section may be documented in glossary
252-
TestAssert "param" && tParam[1] && "in param section" && tElement["display name"] && tElement["Type"], tDocumentedParams[tParam[1]] -- or tParamInGlossary
316+
TestAssert pDocsPath & ":" && "param" && tParam[1] && "in param section" && tElement["display name"] && tElement["Type"], tDocumentedParams[tParam[1]] -- or tParamInGlossary
253317

254318
-- params in param section should be in the syntax section otherwise what are they documenting
255-
TestAssert "param" && tParam[1] && "in syntax section" && tElement["display name"] && tElement["Type"], tSyntaxParams[tParam[1]]
319+
TestAssert pDocsPath & ":" && "param" && tParam[1] && "in syntax section" && tElement["display name"] && tElement["Type"], tSyntaxParams[tParam[1]]
256320
end repeat
257321

258322
end if
@@ -261,7 +325,7 @@ command __TestDocsLibraryArray pLibrary
261325
delete variable tSyntaxParams
262326

263327
-- test description required
264-
TestAssert "description of" && tElement["display name"] && tElement["type"] && "not empty", tElement["Description"] is not empty
328+
TestAssert pDocsPath & ":" && "description of" && tElement["display name"] && tElement["type"] && "not empty", tElement["Description"] is not empty
265329

266330
-- !TODO parse all summaries and descriptions etc
267331
-- * test all links are listed in references

0 commit comments

Comments
 (0)