-
Notifications
You must be signed in to change notification settings - Fork 34
Testing
Testing is located in the CWToolsTest project and uses the Expecto library. Tests are run by running the project with dotnet run; the default with no args is to run all tests.
The bulk of the testing is integration testing, running a full instance of the validation against a test folder and checking that errors are only raised on expected lines. /testfiles/configtests/rulestest contains the majority of these tests.
The test runner searches for folders, so simply adding a new folder to rulestests will add it to the test suite.
A test folder such as STL/values consists of two parts:
A rules.cwt file containing all the rules setup for these tests. These are in the format that is used for the final application. A snippet:
types = {
type[event] = {
path = "game/events"
...
}
alias[effect:date] = date_field
alias[effect:datetime] = datetime_field
These files are organised in folder as if this were a real mod. So for the above rules, it will validate the files in the events folder. These are treated as real script files and validated using the rules above. The single test.txt file in this test contains a series of statements testing that simple values are validated correctly.
For the above snippet from the rules, the relevant lines are:
#error
date = 10
#error
date = 1000.13.30
#error
date = 1000.12.35
date = 1000.12.30
#error
datetime = 10
#error
datetime = 1000.13.30
#error
datetime = 1000.12.35
datetime = 1000.12.30
#error
datetime = 1000.12.30.50
datetime = 1000.12.30.15
The test runner expects a single error per line marked with #error, and no errors anywhere else.
There is also a limited setup for testing completion as demonstrated here.
## Test dot chain completion
#@? 18 simple_province
#@ 18 simple_character
simple_province.simple_character = {
}
...
#@! 3 event
without_alias = {
where
-
#@ 18 simple_character: requiressimple_characterto be suggested at character 18 of the next line -
#@? 18 simple_province: requiressimple_provinceto be suggested with reduced priority at character 18 -
#@! 3 event: requiredeventto not be suggested at character 3 of the next line