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

Commit bd1dfc5

Browse files
committed
tests: Move colour-logging code into tester common library.
1 parent c2fa711 commit bd1dfc5

File tree

3 files changed

+76
-136
lines changed

3 files changed

+76
-136
lines changed

tests/_compilertestrunner.livecodescript

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ end getCommandLineInfo
7070
command CompilerTestRunnerMain
7171
local tInfo
7272
put getCommandLineInfo() into tInfo
73-
logInit
7473

7574
switch tInfo["args"][1]
7675
case "run"
@@ -189,7 +188,7 @@ private command runTestProcessOutput pScriptfile, pCommand, pOutput
189188
local tTapResults
190189
put TesterTapAnalyse(tTestLog) into tTapResults
191190

192-
logSummaryLine tTapResults, (TesterGetPrettyTestName(pScriptFile, "compilertest") & ":" && pCommand)
191+
TesterLogSummaryLine tTapResults, (TesterGetPrettyTestName(pScriptFile, "compilertest") & ":" && pCommand)
193192

194193
return tTapResults
195194
end runTestProcessOutput
@@ -232,6 +231,7 @@ private command runCompilerTest pInfo, pScriptFile, pTest
232231
reportCompilerTestDiag tCompilerOutput
233232

234233
-- Process the assertions and make sure each one matches up
234+
local tTestOutput
235235
repeat for each line tAssertion in tTestInfo["assertions"]
236236
if doesCompilerOutputSatisfyAssertion(tCompilerOutput, tCompilerExitStatus, tAssertion, tTestInfo["positions"]) then
237237
put "ok - " after tTestOutput
@@ -400,6 +400,7 @@ private command processCompilerTest pInfo, pScriptFile, pTest, @rCompilerTest
400400
throw format("can't open file '%s'", pScriptFile)
401401
end if
402402

403+
local tScript
403404
read from file pScriptFile until end
404405
put it into tScript
405406

@@ -653,68 +654,3 @@ private command reportCompilerTestDiagWithLineNumbers pMessage
653654
end repeat
654655
end if
655656
end reportCompilerTestDiagWithLineNumbers
656-
657-
----------------------------------------------------------------
658-
-- Logging helpers
659-
----------------------------------------------------------------
660-
661-
local sLogInfo
662-
663-
-- Figure out what the highlighting escape codes are for the terminal
664-
--
665-
-- FIXME this really doesn't work properly if LiveCode's stdout
666-
-- *isn't* a TTY.
667-
private command logInit
668-
-- We can only do colour on Linux and OS X
669-
if the platform is not "Linux" and the platform is not "MacOS" then
670-
put false into sLogInfo
671-
end if
672-
673-
-- Check if colouring is possible
674-
local tTput
675-
put shell("tput colors") into tTput
676-
if the result is not empty or tTput <= 8 then
677-
put false into sLogInfo
678-
end if
679-
680-
-- Get colours
681-
put shell("tput sgr0") into sLogInfo["normal"]
682-
put shell("tput bold") into sLogInfo["bold"]
683-
put shell("tput setaf 1") into sLogInfo["red"]
684-
put shell("tput setaf 2") into sLogInfo["green"]
685-
put shell("tput setaf 3") into sLogInfo["yellow"]
686-
put shell("tput setaf 6") into sLogInfo["cyan"]
687-
end logInit
688-
689-
private function logHighlight pString
690-
if pString is "fail" then
691-
return sLogInfo["red"] & sLogInfo["bold"] & pString & sLogInfo["normal"]
692-
else if pString is "xfail" or pString is "xpass" then
693-
return sLogInfo["yellow"] & pString & sLogInfo["normal"]
694-
else if pString is "pass" then
695-
return sLogInfo["green"] & pString & sLogInfo["normal"]
696-
else if pString is "skip" then
697-
return sLogInfo["cyan"] & pString & sLogInfo["normal"]
698-
else
699-
return pString
700-
end if
701-
end logHighlight
702-
703-
private command logSummaryLine pTapResults, pTestName
704-
local tTotal, tPassed, tWorst, tMessage
705-
706-
put pTapResults["xpass"] + pTapResults["pass"] + pTapResults["skip"] into tPassed
707-
put TesterTapGetTestCount(pTapResults) into tTotal
708-
709-
put TesterTapGetWorstResult(pTapResults) into tWorst
710-
put logHighLight(the toUpper of tWorst) into tMessage
711-
put ":" after tMessage
712-
if the number of chars in tWorst < 5 then
713-
put space after tMessage
714-
end if
715-
716-
put space & pTestName after tMessage
717-
718-
put space & "[" & tPassed & "/" & tTotal & "]" after tMessage
719-
write tMessage & return to stdout
720-
end logSummaryLine

tests/_testerlib.livecodescript

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
script "TesterLib"
22
/*
3-
Copyright (C) 2015 LiveCode Ltd.
3+
Copyright (C) 2015-2016 LiveCode Ltd.
44
55
This file is part of LiveCode.
66
@@ -248,3 +248,73 @@ function TesterTapCombine pAnalysisA, pAnalysisB
248248
end if
249249
return tCombined
250250
end TesterTapCombine
251+
252+
----------------------------------------------------------------
253+
-- Logging helpers
254+
----------------------------------------------------------------
255+
256+
local sLogInfo
257+
258+
-- Figure out what the highlighting escape codes are for the terminal
259+
--
260+
-- FIXME this really doesn't work properly if LiveCode's stdout
261+
-- *isn't* a TTY.
262+
private command logInit
263+
if sLogInfo is false or sLogInfo is an array then
264+
exit logInit
265+
end if
266+
267+
-- We can only do colour on Linux and OS X
268+
if the platform is not "Linux" and the platform is not "MacOS" then
269+
put false into sLogInfo
270+
end if
271+
272+
-- Check if colouring is possible
273+
local tTput
274+
put shell("tput colors") into tTput
275+
if the result is not empty or tTput <= 8 then
276+
put false into sLogInfo
277+
end if
278+
279+
-- Get colours
280+
put shell("tput sgr0") into sLogInfo["normal"]
281+
put shell("tput bold") into sLogInfo["bold"]
282+
put shell("tput setaf 1") into sLogInfo["red"]
283+
put shell("tput setaf 2") into sLogInfo["green"]
284+
put shell("tput setaf 3") into sLogInfo["yellow"]
285+
put shell("tput setaf 6") into sLogInfo["cyan"]
286+
end logInit
287+
288+
private function logHighlight pString
289+
logInit
290+
if pString is "fail" then
291+
return sLogInfo["red"] & sLogInfo["bold"] & pString & sLogInfo["normal"]
292+
else if pString is "xfail" or pString is "xpass" then
293+
return sLogInfo["yellow"] & pString & sLogInfo["normal"]
294+
else if pString is "pass" then
295+
return sLogInfo["green"] & pString & sLogInfo["normal"]
296+
else if pString is "skip" then
297+
return sLogInfo["cyan"] & pString & sLogInfo["normal"]
298+
else
299+
return pString
300+
end if
301+
end logHighlight
302+
303+
command TesterLogSummaryLine pTapResults, pTestName
304+
local tTotal, tPassed, tWorst, tMessage
305+
306+
put pTapResults["xpass"] + pTapResults["pass"] + pTapResults["skip"] into tPassed
307+
put TesterTapGetTestCount(pTapResults) into tTotal
308+
309+
put TesterTapGetWorstResult(pTapResults) into tWorst
310+
put logHighLight(the toUpper of tWorst) into tMessage
311+
put ":" after tMessage
312+
if the number of chars in tWorst < 5 then
313+
put space after tMessage
314+
end if
315+
316+
put space & pTestName after tMessage
317+
318+
put space & "[" & tPassed & "/" & tTotal & "]" after tMessage
319+
write tMessage & return to stdout
320+
end TesterLogSummaryLine

tests/_testrunner.livecodescript

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
script "TestRunner"
22
/*
3-
Copyright (C) 2015 LiveCode Ltd.
3+
Copyright (C) 2015-2016 LiveCode Ltd.
44
55
This file is part of LiveCode.
66
@@ -65,7 +65,6 @@ end getCommandLineInfo
6565
command TestRunnerMain
6666
local tInfo
6767
put getCommandLineInfo() into tInfo
68-
logInit
6968

7069
switch tInfo["args"][1]
7170
case "invoke"
@@ -245,7 +244,7 @@ private command runTestProcessOutput pScriptfile, pCommand, pOutput
245244
local tTapResults
246245
put TesterTapAnalyse(tTestLog) into tTapResults
247246

248-
logSummaryLine tTapResults, (TesterGetPrettyTestName(pScriptFile) & ":" && pCommand)
247+
TesterLogSummaryLine tTapResults, (TesterGetPrettyTestName(pScriptFile) & ":" && pCommand)
249248

250249
return tTapResults
251250
end runTestProcessOutput
@@ -318,68 +317,3 @@ private command runPrintSummary pAnalysis
318317

319318
write tSummaryString to stdout
320319
end runPrintSummary
321-
322-
----------------------------------------------------------------
323-
-- Logging helpers
324-
----------------------------------------------------------------
325-
326-
local sLogInfo
327-
328-
-- Figure out what the highlighting escape codes are for the terminal
329-
--
330-
-- FIXME this really doesn't work properly if LiveCode's stdout
331-
-- *isn't* a TTY.
332-
private command logInit
333-
-- We can only do colour on Linux and OS X
334-
if the platform is not "Linux" and the platform is not "MacOS" then
335-
put false into sLogInfo
336-
end if
337-
338-
-- Check if colouring is possible
339-
local tTput
340-
put shell("tput colors") into tTput
341-
if the result is not empty or tTput <= 8 then
342-
put false into sLogInfo
343-
end if
344-
345-
-- Get colours
346-
put shell("tput sgr0") into sLogInfo["normal"]
347-
put shell("tput bold") into sLogInfo["bold"]
348-
put shell("tput setaf 1") into sLogInfo["red"]
349-
put shell("tput setaf 2") into sLogInfo["green"]
350-
put shell("tput setaf 3") into sLogInfo["yellow"]
351-
put shell("tput setaf 6") into sLogInfo["cyan"]
352-
end logInit
353-
354-
private function logHighlight pString
355-
if pString is "fail" then
356-
return sLogInfo["red"] & sLogInfo["bold"] & pString & sLogInfo["normal"]
357-
else if pString is "xfail" or pString is "xpass" then
358-
return sLogInfo["yellow"] & pString & sLogInfo["normal"]
359-
else if pString is "pass" then
360-
return sLogInfo["green"] & pString & sLogInfo["normal"]
361-
else if pString is "skip" then
362-
return sLogInfo["cyan"] & pString & sLogInfo["normal"]
363-
else
364-
return pString
365-
end if
366-
end logHighlight
367-
368-
private command logSummaryLine pTapResults, pTestName
369-
local tTotal, tPassed, tWorst, tMessage
370-
371-
put pTapResults["xpass"] + pTapResults["pass"] + pTapResults["skip"] into tPassed
372-
put TesterTapGetTestCount(pTapResults) into tTotal
373-
374-
put TesterTapGetWorstResult(pTapResults) into tWorst
375-
put logHighLight(the toUpper of tWorst) into tMessage
376-
put ":" after tMessage
377-
if the number of chars in tWorst < 5 then
378-
put space after tMessage
379-
end if
380-
381-
put space & pTestName after tMessage
382-
383-
put space & "[" & tPassed & "/" & tTotal & "]" after tMessage
384-
write tMessage & return to stdout
385-
end logSummaryLine

0 commit comments

Comments
 (0)