jj/docs/style_guide.md
Martin von Zweigbergk e8f91696fe style-guide: say that we prefer lower-level tests over e2e test
End-to-end tests using the `jj` binary are often easy and natural to
write, but it's easy to miss how much slower they are than `jj-lib`
tests.
2025-08-19 06:30:00 +00:00

1.1 KiB

Style guide

Panics

Panics are not allowed, especially in code that may run on a server. Calling .unwrap() is okay if it's guaranteed to be safe by previous checks or documented invariants. For example, if a function is documented as requiring a non-empty slice as input, it's fine to call slice[0] and panic.

Markdown

Try to wrap at 80 columns. We don't have a formatter yet.

Prefer lower-level tests to end-to-end tests

When possible, prefer lower-level tests that don't use the jj binary. End-to-end tests are much slower than similar tests that create a repo using jj-lib (roughly 100x slower). It's also often easier to test edge cases in lower-level tests.

It can still be useful to add a test case or two to check that the lower-level functionality is correctly hooked up in the CLI. For example, the end-to-end tests for jj log don't need to test that all kinds of revsets are evaluated correctly (we have tests in jj-lib for that), but they should check that the -r flag is respected.

Use end-to-end tests for testing the CLI commands themselves.