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

Re: [RFC PATCH 0/2] add an external testing library for unit tests

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 2, 2023, 15:28 UTC
Message-ID
<64512c0b1237b_1ba2d29426@chronos.notmuch>
In-Reply-To
<230502.861qjyj0cb.gmgdl@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason wrote:
Show 16 quoted lines
> We already have pure-C libraries that we add a really shim to unit test,
> the most extreme example of this is t0032-reftable-unittest.sh, whose
> body is simply (excluding comments):
> 	
> 	#!/bin/sh
> 	test_description='reftable unittests'
> 	
> 	TEST_PASSES_SANITIZE_LEAK=true
> 	. ./test-lib.sh
> 	
> 	test_expect_success 'unittests' '
> 		TMPDIR=$(pwd) && export TMPDIR &&
> 		test-tool reftable
> 	'
> 	
> 	test_done

Yeah, but an output of 'ok 1 - unittests' is not very useful, neither is an output of 'not ok 1 - unittests'.

This completely misses the point of a TAP interface, which is to parse the status of individual test cases, or even individual assertions.

If all we are doing is check the exit code of some program, then we don't need TAP.

Show 5 quoted lines
> Now, that goes into reftable/test_framework.h which basically implements
> its own mini-test framework, so that's at least a *partial* argument for
> what you're suggesting here, but note that it doesn't emit TAP, it just
> returns an exit code, the EXPECT() etc. is purely internal. I.e. "what
> should we return?".
You are just describing the status quo.

I think this is a naturaistic fallacy: confusing what is versus what ought to be.

Can we test C code with our current testing framework? Yes.
Should we? That's the actual question.
> None of those are perfect, but I think the current arrangement is rather
> ideal.
I think misuing TAP is far from ideal.
In my view an ideal framework would:
 1. Be able to test C code
 2. Report individual test cases success/failure
 3. Report relevant context in the case of failure (actual vs. expected)
 4. Don't create forks on every individual test case or assertion
 5. Properly handle crashes
Doing basically the following is not an ideal framework:
  echo '1..1'
  test-tool reftable > /dev/null 2>&1 && echo 'ok 1' || { echo 'not ok 1'; false; }

Yes, it works. But "it works" has never been a good enough reason to stay on the status quo.

> We can write most or all of the test in C, but we just do so by
> calling a function that returns an exit code.
Yes, we *can*, but should we?
---

If we can test C code in a way that individual test case failures are reported (as is the intention with TAP), why would we reject that in favor of the status quo which basically is just reporting the exit code of the whole test file?

-- 
Felipe Contreras
Previous: Ævar Arnfjörð Bjarmason
Message 29 of 29 in “add an external testing library for unit tests”
  1. 0/2 add an external testing library for unit testsCalvin Wan, Apr 27, 2023
  2. 1/2 Add C TAP harnessCalvin Wan, Apr 27, 2023
  3. SZEDER GáborApr 27, 2023
  4. Calvin WanApr 27, 2023
  5. Phillip WoodApr 27, 2023
  6. Calvin WanApr 28, 2023
  7. Felipe ContrerasMay 2, 2023
  8. Phillip WoodMay 10, 2023
  9. Glen ChooMay 11, 2023
  10. Phillip WoodMay 18, 2023
  11. Linus ArverJun 21, 2023
  12. Phillip WoodJun 26, 2023
  13. Linus ArverJun 28, 2023
  14. Oswald BuddenhagenJun 29, 2023
  15. Phillip WoodJun 30, 2023
  16. Felipe ContrerasMay 2, 2023
  17. Ævar Arnfjörð BjarmasonMay 2, 2023
  18. Felipe ContrerasMay 2, 2023
  19. Ævar Arnfjörð BjarmasonMay 2, 2023
  20. Phillip WoodMay 10, 2023
  21. 2/2 unit test: add basic exampleCalvin Wan, Apr 27, 2023
  22. Junio C HamanoApr 27, 2023
  23. Felipe ContrerasMay 2, 2023
  24. Junio C HamanoApr 27, 2023
  25. Calvin WanApr 27, 2023
  26. brian m. carlsonApr 27, 2023
  27. Felipe ContrerasMay 2, 2023
  28. Ævar Arnfjörð BjarmasonMay 2, 2023
  29. Felipe ContrerasMay 2, 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.