Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: get zig build test working #18207

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft

test: get zig build test working #18207

wants to merge 21 commits into from

Conversation

DonIsaac
Copy link
Contributor

@DonIsaac DonIsaac commented Mar 15, 2025

What does this PR do?

Lets us write and run unit tests directly in Zig.

Running Zig unit tests in CI is blocked by ziglang/zig#23281. We can un-comment relevant code once this is fixed.

Workflow

I'll finish writing this up later, but some initial points are below.
Tl;Dr: bun build:test

Test binaries can be made for any kind of build. They are called <bun>-test and live next to their corresponding bun bin. For example, debug tests compile to build/debug/bun-debug-test.

Test binaries re-use most cmake/zig build steps from normal bun binaries, so building one after a normal bun build is pretty fast.

How did you verify your code works?

I tested that my tests run tests.

@robobun
Copy link

robobun commented Mar 15, 2025

Updated 4:40 PM PT - Mar 19th, 2025

@DonIsaac, your commit 0e2e639 has 1 failures in Build #13541:


🧪   try this PR locally:

bunx bun-pr 18207

Comment on lines +4 to +5
//! Regains control of the calling thread when the function panics or behaves
//! undefined.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm skeptical of this. Recovering from panics isn't really intended to be possible or supported. IMO we should just let it crash, or if we really need fine-grained panic reporting in CI we could run each test in a new process using a filter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDk, I'd personally rather have my test suite finish running all tests instead of aborting early when one of them panics. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that panic recovery will fail or cause unexpected results, since this isn't really something Zig has put time into making possible:

So realistically it could mess up tests that run after the panic. But I guess that might not be terrible for a worst-case scenario since you will just see that fixing the panic causes the tests after it to work again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants