Re: [RFC PATCH 0/2] add an external testing library for unit tests
From: Felipe Contreras <hidden>
Date: 2023-05-02 04:18:56
Calvin Wan wrote:
In our current testing environment, we spend a significant amount of effort crafting end-to-end tests for error conditions that could easily be captured by unit tests (or we simply forgo some hard-to-setup and rare error conditions). Unit tests additionally provide stability to the codebase and can simplify debugging through isolation. Turning parts of Git into libraries[1] gives us the ability to run unit tests on the libraries and to write unit tests in C. Writing unit tests in pure C, rather than with our current shell/test-tool helper setup, simplifies test setup, simplifies passing data around (no shell-isms required), and reduces testing runtime by not spawning a separate process for every test invocation.
I agree unit tests would be very helpful, but they don't need to be written in C. I sent a RFC patch series [1] attempting to write unit tests, but using Ruby, the testing framework is less than 100 lines of code, and uses Ruby bindings to use the C functions. I think writing everything in C adds a ton of unnecessary complexity for no gain. In fact some things are simply not possible, like dealing with crashes without forks. Modern languages exist for a reason: C isn't the best tool in every situation, and I believe this is one of them. Cheers. [1] https://lore.kernel.org/git/20230502041113.103385-1-felipe.contreras@gmail.com/T/#t (local) -- Felipe Contreras