|
| 1 | +--- |
| 2 | +title: Tests |
| 3 | +--- |
| 4 | + |
| 5 | +Hyprland and some other projects under the hypr* umbrella have _tests_ that |
| 6 | +try to catch bugs and regressions before code is merged. |
| 7 | + |
| 8 | +Building in Debug will by default build tests. |
| 9 | + |
| 10 | +## Running tests |
| 11 | + |
| 12 | +### GTests |
| 13 | + |
| 14 | +GTests are GoogleTests that are _unit tests_. These tests simply check how |
| 15 | +some elements behave when they can run on their own. |
| 16 | + |
| 17 | +In all hypr* projects, GTests are ran by ctest. Run: |
| 18 | + |
| 19 | +```sh |
| 20 | +ctest -j$(nproc) -C Debug --test-dir=build |
| 21 | +``` |
| 22 | + |
| 23 | +And make sure your tests pass. |
| 24 | + |
| 25 | +### Hyprland's hyprtester |
| 26 | + |
| 27 | +A lot of hyprland's code cannot be unit tested, thus we have our own Hyprtester |
| 28 | +binary which runs hyprland and issues commands and expects results. |
| 29 | + |
| 30 | +To run Hyprtester, `cd` into `./hyprtester`, then run: |
| 31 | + |
| 32 | +```sh |
| 33 | +../build/hyprtester/hyprtester --plugin ./plugin/hyprtestplugin.so |
| 34 | +``` |
| 35 | + |
| 36 | +*This will run for a while!* At the end, it will print summary results |
| 37 | +of how many tests passed, and how many failed. |
| 38 | + |
| 39 | +The goal of failed tests is to be **0**. |
| 40 | + |
| 41 | +## Submitting new tests |
| 42 | + |
| 43 | +New tests have to either be a GTest, if the thing tested is possible to be unit tested, |
| 44 | +or a part of hyprtester. |
| 45 | + |
| 46 | +For both test types, you can check the test directories in the project. GTests live in `tests/`, |
| 47 | +while hyprtester tests live in `hyprtester/`. |
| 48 | + |
| 49 | +### What to test |
| 50 | + |
| 51 | +If you're submitting a new feature, it's obviously your feature. For a fix, try to write a test |
| 52 | +case that would fail before your fix. |
| 53 | + |
| 54 | +For new tests, you can inspect the coverage report. |
| 55 | + |
| 56 | +First, run _both_ ctest and hyprtester. Then, run (from the repo root): |
| 57 | + |
| 58 | +```sh |
| 59 | +gcovr -r . build --html --html-details -o build/coverage.html --gcov-ignore-parse-errors="negative_hits.warn" && xdg-open ./build/coverage.html |
| 60 | +``` |
| 61 | + |
| 62 | +this will run for a while, then open a report in your browser. You can see which files have been tested in |
| 63 | +what amount, and click on the files to see a line-by-line breakdown. |
| 64 | + |
| 65 | +If there are paths untested, we'd be very happy to receive tests for them. |
0 commit comments