Skip to content

Commit 9eb7963

Browse files
committed
[[ Tests ]] Add TestSkipIf[Not] command
This patch adds `TestSkipIf` and `TestSkipIfNot` commands to simplify the handling of particular features that are unupported in a given environment. This allows us to change the condition for skip centrally. For example, should Emscripten start supporting wait we could turn all those tests on with a one line change.
1 parent aa92d7a commit 9eb7963

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed

docs/development/testing.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ Before running each test command, the test framework inserts a test library stac
6060
* `TestDiagnostic pMessage`: Write *pMessage* to the test log as a message.
6161
* `TestAssert pDescription, pExpectTrue`: Make a test assertion. The test is recorded as a failure if *pExpectTrue* is false. *pDescription* should be a short string that describes the test (e.g. "clipboard is clear").
6262
* `TestSkip pDescription, pReasonSkipped`: Record a test as having been skipped. *pReasonSkipped* should be a short explanation of why the test was skipped (e.g. "not supported on Windows").
63+
* `TestSkipIf pRequirement, pOptions`: Skip a test if the requirements
64+
are met. `pOptions` varies depending on the `pRequirement` enum. The
65+
following requirements are implemented:
66+
- `ide` - the IDE repo is available. No options.
67+
- `lcb` - LCB compilation supported
68+
- `docs` - the docs are available. No options.
69+
- `securityPermissions` - Option `set` to skip if a test should not
70+
set the `securityPermissions`
71+
- `platform` - options are comma delimited platform strings
72+
- `processor` - options are comma delimited processor strings
73+
- `stack` - options are comma delimited stack names to test if they
74+
are available
75+
- `environment` - options are comma delimited environment strings
76+
* `TestSkipIfNot pRequirement, pOptions`: Skip a test if the
77+
requirements are not met. Requirements and options are the same as for
78+
`TestSkipIf`.
6379
* `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".
6480
* `TestAssertThrow pDescription, pHandlerName, pTarget, pExpectedError, pParam`: Assert that a given handler triggers the expected error message. *pHandlerName* is the name of the handler containing the script expected to cause an error; it is dispatched to *pTarget* with *pParam* as a parameter within a try/catch structure. *pExpectedError* is the expected script execution error name in the enumeration in engine/src/executionerrors.h - e.g. `"EE_PROPERTY_CANTSET"`.
6581
* `TestAssertDoesNotThrow pDescription, pHandlerName, pTarget, pParam`: Assert that a given handler does not trigger any exceptions. *pHandlerName* is the name of the handler containing the script expected to cause an error; it is dispatched to *pTarget* with *pParam* as a parameter within a try/catch structure.
@@ -73,19 +89,27 @@ Before running each test command, the test framework inserts a test library stac
7389
- `pTimeOut` is the amount of milliseconds to continue testing the result of the handler.
7490
- `pParamsArray` is an array of parameters, keyed by the 1-based index of the required parameter to be passed to the handler.
7591
* `TestAssertErrorDialog pDescription, pErrorCode`: Assert that this test triggers an errorDialog message with the given error.
92+
* `TestIsInStandalone()`: Checks if the test is being run by the
93+
standalone test runner.
94+
7695
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:
7796
````
7897
on TestSetup
98+
TestSkipIfNot "docs"
7999
-- All the tests in this script require access to the docs parser
80100
start using stack (TestGetEngineRepositoryPath() & slash & "ide-support" & slash & "revdocsparser.livecodescript")
81101
end TestSetup
82102
````
83103

84-
The `TestSetup` handler can indicate that a test should be skipped *entirely* by returning a value that begins with the word "skip". For example:
104+
The `TestSetup` handler can indicate that a test should be skipped
105+
*entirely* by returning a value that begins with the word "skip" or by
106+
using the `TestSkipIf` or `TestSkipIfNot` commands. For example:
85107

86108
````
87109
on TestSetup
88-
if the platform is not "Windows" then
110+
TestSkipIfNot "platform", "Win32"
111+
-- is the same as
112+
if the platform is not "Win32" then
89113
return "SKIP Feature is only supported on Windows"
90114
end if
91115
end TestSetup

tests/_testlib.livecodescript

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,63 @@ on TestRunStack pOptions, pStackFilePath
483483

484484
return the result
485485
end TestRunStack
486+
487+
function TestIsInStandalone
488+
return "StandaloneTestRunnerMainstack" is among the lines of the mainstacks
489+
end TestIsInStandalone
490+
491+
on TestSkipIf pRequirement, pOptions
492+
if __MeetsRequirements(pRequirement, pOptions) then
493+
if pOptions is not empty then
494+
put " :" & pOptions after pRequirement
495+
end if
496+
throw "SKIP test incompatible with" && pRequirement
497+
end if
498+
end TestSkipIf
499+
500+
on TestSkipIfNot pRequirement, pOptions
501+
if not __MeetsRequirements(pRequirement, pOptions) then
502+
if pOptions is not empty then
503+
put " :" & pOptions after pRequirement
504+
end if
505+
throw "SKIP test requires" && pRequirement
506+
end if
507+
end TestSkipIfNot
508+
509+
private function __MeetsRequirements pRequirement, pOptions
510+
switch pRequirement
511+
case "ide"
512+
case "docs"
513+
case "lcb"
514+
return not TestIsInStandalone()
515+
break
516+
case "securitypermissions"
517+
if "set" is among the items of pOptions then
518+
return not TestIsInStandalone()
519+
end if
520+
break
521+
case "platform"
522+
return the platform is among the items of pOptions
523+
break
524+
case "processor"
525+
return the processor is among the items of pOptions
526+
break
527+
case "environment"
528+
return the environment is among the items of pOptions
529+
break
530+
case "stack"
531+
repeat for each item tStack in pOptions
532+
if there is not a stack tStack then
533+
return false
534+
end if
535+
end repeat
536+
case "clipboard"
537+
case "wait"
538+
case "security"
539+
return the platform is not "HTML5"
540+
case "write"
541+
return the platform is not "HTML5" and ("disk" is in the securityPermissions or the secureMode is false)
542+
end switch
543+
544+
return true
545+
end __MeetsRequirements

0 commit comments

Comments
 (0)