| 1 | # GDScript integration tests |
| 2 | |
| 3 | The `scripts/` folder contains integration tests in the form of GDScript files |
| 4 | and output files. |
| 5 | |
| 6 | See the |
| 7 | [Integration tests for GDScript documentation](https://docs.godotengine.org/en/latest/engine_details/architecture/unit_testing.html#integration-tests-for-gdscript) |
| 8 | for information about creating and running GDScript integration tests. |
| 9 | |
| 10 | # GDScript Autocompletion tests |
| 11 | |
| 12 | The `scripts/completion` folder contains tests for the GDScript autocompletion. |
| 13 | |
| 14 | Each test case consists of at least one `.gd` file, which contains the code, and one `.cfg` file, which contains expected results and configuration. Inside of the GDScript file the character `➡` represents the cursor position, at which autocompletion is invoked. |
| 15 | |
| 16 | The script files won't be parsable GDScript since it contains an invalid char and often the code is not complete during autocompletion. To allow for a valid base when used with a scene, the |
| 17 | runner will remove the line which contains `➡`. Therefore the scripts need to be valid if this line is removed, otherwise the test might behave in unexpected ways. This may for example require |
| 18 | adding an additional `pass` statement. |
| 19 | |
| 20 | This also means, that the runner will add the script to its owner node, so the script should not be loaded through the scene file. |
| 21 | |
| 22 | The config file contains two section: |
| 23 | |
| 24 | `[input]` contains keys that configure the test environment. The following keys are possible: |
| 25 | |
| 26 | - `cs: boolean = false`: If `true`, the test will be skipped when running a non C# build. |
| 27 | - `use_single_quotes: boolean = false`: Configures the corresponding editor setting for the test. |
| 28 | - `add_node_path_literals: boolean = false`: Configures the corresponding editor setting for the test. |
| 29 | - `add_string_name_literals: boolean = false`: Configures the corresponding editor setting for the test. |
| 30 | - `scene: String`: Allows to specify a scene which is opened while autocompletion is performed. If this is not set the test runner will search for a `.tscn` file with the same basename as the GDScript file. If that isn't found either, autocompletion will behave as if no scene was opened. |
| 31 | - `node_path: String`: The node path of the node which holds the current script inside of the scene. Defaults to the scene root node. |
| 32 | |
| 33 | `[output]` specifies the expected results for the test. The following key are supported: |
| 34 | |
| 35 | - `include: Array`: An unordered list of suggestions that should be in the result. Each entry is one dictionary with the following keys: `display`, `insert_text`, `kind`, `location`, which correspond to the suggestion struct which is used in the code. The runner only tests against specified keys, so in most cases `display` will suffice. |
| 36 | - `exclude: Array`: An array of suggestions which should not be in the result. The entries take the same form as for `include`. |
| 37 | - `call_hint: String`: The expected call hint returned by autocompletion. |
| 38 | - `forced: boolean`: Whether autocompletion is expected to force opening a completion window. |
| 39 | |
| 40 | Tests will only test against entries in `[output]` that were specified. |
| 41 | |
| 42 | ## Writing autocompletion tests |
| 43 | |
| 44 | To avoid failing edge cases a certain behavior needs to be tested multiple times. Some things that tests should account for: |
| 45 | |
| 46 | - All possible types: Test with all possible types that apply to the tested behavior. (For the last points testing against `SCRIPT` and `CLASS` should suffice. `CLASS` can be obtained through C#, `SCRIPT` through GDScript. Relying on autoloads to be of type `SCRIPT` is not good, since this might change in the future.) |
| 47 | |
| 48 | - `BUILTIN` |
| 49 | - `NATIVE` |
| 50 | - GDScripts (with `class_name` as well as `preload`ed) |
| 51 | - C# (as standin for all other language bindings) (with `class_name` as well as `preload`ed) |
| 52 | - Autoloads |
| 53 | |
| 54 | - Possible contexts: the completion might be placed in different places of the program. e.g: |
| 55 | - initializers of class members |
| 56 | - directly inside a suite |
| 57 | - assignments inside a suite |
| 58 | - as parameter to a call |