Skip to content

Commit 7e40c8c

Browse files
committed
testing: add new guidelines + cov info
ref hyprwm/Hyprland#12383
1 parent a0a5c14 commit 7e40c8c

File tree

2 files changed

+73
-32
lines changed

2 files changed

+73
-32
lines changed

content/Contributing and Debugging/PR-Guidelines.md

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ _only_ ignore them if it's absolutely necessary.
3030

3131
I've tweaked it so that in 99% of cases you absolutely should fix it.
3232

33+
### Testing
34+
35+
Please check the [Tests](../Tests) page for information about tests in Hyprland, and related
36+
projects.
37+
38+
No test regressions is a _must_, while new tests are _required_ if possible to test (e.g.
39+
graphical stuff is not testable).
40+
3341
### Other
3442

3543
Some stuff clang-tidy / clang-format won't catch:
@@ -87,35 +95,3 @@ src/
8795
If you are in `a.hpp` and want to include `b.hpp`, you _must_ use `../b/b.hpp`, and _cannot_ use `b/b.hpp`. The latter will break plugins.
8896

8997
One exception you might notice in the code is absolute paths from the root are allowed, e.g. `protocols/some-protocol.hpp`.
90-
91-
### Test your changes
92-
Run and test your changes to make sure they work!
93-
94-
## Testing and CI
95-
96-
Since [#9297](https://github.com/hyprwm/Hyprland/pull/9297), we require each MR that fixes an issue
97-
or adds a new feature to include test(s) for the feature, if possible.
98-
99-
The testing framework is incapable of testing visual changes (e.g. graphical effects), and some very
100-
niche parts (real HID devices, etc). However, if your change is related to: binds, layouts, config options,
101-
window management, hyprctl, dispatchers, keywords, etc. your MR _needs_ tests.
102-
103-
### How to run tests locally
104-
105-
In order to run tests locally, build Hyprland, then:
106-
```sh
107-
cd hyprtester
108-
../build/hyprtester/hyprtester --plugin ./plugin/hyprtestplugin.so
109-
```
110-
111-
### How to add tests
112-
113-
In order to add a new test, you can either make a new test file, or add a test to an existing file.
114-
If you are adding a new test file, remember to end on a clean state: close all windows you've opened, and go back to workspace 1.
115-
116-
If you are adding to an existing test file, find a file that's appropriate for the category
117-
of your test.
118-
119-
Tests are done by having a hyprland process active, issuing hyprctl commands, and checking the result with hyprctl queries.
120-
121-
Check the `hyprtester/` directory of the source repo for more.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)