Skip to content

Commit db1058e

Browse files
committed
Add some docs on how to write tests for PRs. NFC
1 parent f24ee6f commit db1058e

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

docs/process.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ webside.
3434
* Add a `[prefix]` to start of the PR title to signify the subsystem or area
3535
that the PR targets. e.g. `[test] Update foo test` or `[ports] Fix zlib port`
3636

37+
### Writing Tests
38+
39+
See [Emscripten Test Suite][test_suite] for information on how to get started
40+
running tests.
41+
42+
Almost all PRs should be accompanied by some kind of test.
43+
44+
* For bug fixes, try to update an existing test rather than adding a new one.
45+
* The majority of tests live in `test_other.py` and `test_core.py`. The
46+
difference between these is that tests in `test_core.py` are testing under
47+
many different combinations of settings, and so each test added there is
48+
the equivalent of adding ~10 new tests to `test_other.py`.
49+
* Prefer black box testing where possible (i.e. test the compiler using its
50+
public command line interface).
51+
* For C/C++ tests longer than a few lines, prefer separate source files over
52+
inline C/C++ within python.
53+
* C/C++ should use `assert` internally to check expectations and should return
54+
0 from their `main` function.
55+
* For regression tests, try to minimize and understand the reproducer so that
56+
a minimal test can be created.
57+
* For simple tests, always prefer C over C++ since it comes with less baggage
58+
(i.e. it minimizes the scope of the system under test) and can be compiled
59+
very fast.
60+
* When testing changes to system libraries, remember to rebuild the libraries
61+
you touch (e.g. using `./embuilder`) before running tests (or use `emcc
62+
--clear-cache` as a blunt implement for forcing a rebuild of all libraries).
63+
3764
## Coding Style
3865

3966
### C/C++ Code
@@ -365,3 +392,4 @@ decide collectively to abandon the deprecation, or to delay it.
365392
[update_libunwind_emscripten]: https://github.com/emscripten-core/emscripten/blob/main/system/lib/update_libunwind.py
366393
[update_musl_emscripten]: https://github.com/emscripten-core/emscripten/blob/main/system/lib/update_musl.py
367394
[global_github_search]: https://github.com/search?q=%2F%28%3F-i%29%5CbMY_SETTING%5Cb%2F+-org%3Aemscripten-core+-path%3Aemcc.*+-path%3Asettings.*+-path%3Asettings_reference.*&type=code
395+
[test_suite]: https://emscripten.org/docs/getting_started/test-suite.html

site/source/docs/getting_started/test-suite.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Emscripten Test Suite
66

77
Emscripten has a comprehensive test suite, which covers virtually all Emscripten
88
functionality. These tests are an excellent resource for developers as they
9-
provide practical examples of most features, and are known to pass on the master
10-
branch. In addition to correctness tests, there are also benchmarks that you can
11-
run.
9+
provide practical examples of most features, and are known to pass on the
10+
``main`` branch. In addition to correctness tests, there are also benchmarks
11+
that you can run.
1212

1313
This article explains how to run the test and benchmark suite, and provides an
1414
overview of what tests are available.

0 commit comments

Comments
 (0)