git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH RFC v2 0/4] Add an external testing library for unit tests

From
steadmon@google.com <steadmon@google.com>
Date
May 17, 2023, 23:56 UTC
Message-ID
<20230517-unit-tests-v2-v2-0-21b5b60f4b32@google.com>

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.

Unit testing in C requires a separate testing harness that we ideally would like to be TAP-style and to come with a non-restrictive license. Fortunately, there already exists a C TAP harness library[2] with an MIT license (at least for the files included in this series). Phillip Wood has also proposed an alternative implementation[3]. I have not had a chance to review that patch in much detail, but I have hopefully made the Makefile integration here somewhat pluggable so that we can easily switch to his version if it proves superior. For now, I have continued with the C TAP library.

The first patch is a small cleanup to allow linking common_exit() separately from common-main.o. In the second patch, I've added a rough draft project plan listing some goals. Patch 3 adds the C TAP libraries. Patch 4 is a modified version of Calvin's previous implemenation with better integration to our Makefiles.

[1] https://lore.kernel.org/git/CAJoAoZ=Cig_kLocxKGax31sU7Xe4==BGzC__Bg2_pr7krNq6MA@mail.gmail.com/ [2] https://github.com/rra/c-tap-harness/ [3]: https://lore.kernel.org/git/c902a166-98ce-afba-93f2-ea6027557176@gmail.com/

Signed-off-by: Josh Steadmon <steadmon@google.com>
---
Calvin Wan (1):
      Add C TAP harness
Josh Steadmon (3):
      common-main: split common_exit() into a new file
      unit tests: Add a project plan document
      unit test: add basic example and build rules
 .gitignore                             |    2 +
 Documentation/Makefile                 |    1 +
 Documentation/technical/unit-tests.txt |   47 +
 Makefile                               |   25 +-
 common-exit.c                          |   26 +
 common-main.c                          |   24 -
 t/Makefile                             |   10 +
 t/runtests.c                           | 1789 ++++++++++++++++++++++++++++++++
 t/strbuf-test.c                        |   54 +
 t/tap/basic.c                          | 1029 ++++++++++++++++++
 t/tap/basic.h                          |  198 ++++
 t/tap/macros.h                         |  109 ++
 12 files changed, 3289 insertions(+), 25 deletions(-)
---
base-commit: 69c786637d7a7fe3b2b8f7d989af095f5f49c3a8
change-id: 20230517-unit-tests-v2-94f50a7ccd8a
Best regards,
-- 
Josh Steadmon <steadmon@google.com>
Next: steadmon@google.com
Message 1 of 32 in “Add an external testing library for unit tests”
  1. 0/4 Add an external testing library for unit testssteadmon@google.com, May 17, 2023
  2. 1/4 common-main: split common_exit() into a new filesteadmon@google.com, May 17, 2023
  3. Junio C HamanoMay 18, 2023
  4. Splitting common-main (Was: Re: [PATCH RFC v2 1/4] common-main: split common_exit() into a new file)Josh Steadmon, Jul 14, 2023
  5. Junio C HamanoJul 15, 2023
  6. Jeff HostetlerAug 14, 2023
  7. 2/4 unit tests: Add a project plan documentsteadmon@google.com, May 17, 2023
  8. Phillip WoodMay 18, 2023
  9. Glen ChooMay 18, 2023
  10. Josh SteadmonMay 24, 2023
  11. Phillip WoodJun 1, 2023
  12. 3/4 Add C TAP harnesssteadmon@google.com, May 17, 2023
  13. Phillip WoodMay 18, 2023
  14. Josh SteadmonMay 18, 2023
  15. 4/4 unit test: add basic example and build rulessteadmon@google.com, May 17, 2023
  16. Phillip WoodMay 18, 2023
  17. 0/1 Add a project document for adding unit testsJosh Steadmon, Jun 9, 2023
  18. 1/1 unit tests: Add a project plan documentJosh Steadmon, Jun 9, 2023
  19. Junio C HamanoJun 13, 2023
  20. Josh SteadmonJun 30, 2023
  21. Linus ArverJun 29, 2023
  22. Josh SteadmonJun 29, 2023
  23. Linus ArverJun 30, 2023
  24. Glen ChooJul 6, 2023
  25. Junio C HamanoJul 6, 2023
  26. Glen ChooJul 6, 2023
  27. Josh SteadmonJun 30, 2023
  28. Junio C HamanoJun 29, 2023
  29. Linus ArverJun 30, 2023
  30. Phillip WoodJun 30, 2023
  31. K WanJun 30, 2023
  32. Josh SteadmonJun 30, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.