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

Re: [PATCH v2 1/1] t/unit-tests: convert hash to use clar test framework

From
Seyi Chamber <kuforiji98@gmail.com>
Date
Jan 9, 2025, 07:30 UTC
Message-ID
<CAGedMtd8GxYHj_N9XRwFb11jyRxk4qFASoKHw8iU2KWMPfucoA@mail.gmail.com>
In-Reply-To
<xmqqv7upnwsp.fsf@gitster.g>
On Wed, 8 Jan 2025 at 16:35, Junio C Hamano <gitster@pobox.com> wrote:
Show 24 quoted lines
>
> Seyi Kuforiji <kuforiji98@gmail.com> writes:
>
> >  CLAR_TEST_SUITES += u-ctype
> > +CLAR_TEST_SUITES += u-hash
> >  CLAR_TEST_SUITES += u-strvec
>
> This is inserted in the middle, presumably because a list without
> inherent ordering is by default maintained as a lexicographically
> sorted list.
>
> > diff --git a/t/meson.build b/t/meson.build
> > index 602ebfe6a2..d722bc7dff 100644
> > --- a/t/meson.build
> > +++ b/t/meson.build
> > @@ -1,6 +1,7 @@
> >  clar_test_suites = [
> >    'unit-tests/u-ctype.c',
> >    'unit-tests/u-strvec.c',
> > +  'unit-tests/u-hash.c',
> >  ]
>
> So, shouldn't we do the same here?
>

Yes, we should. I'll make the necessary adjustment in the next iteration. Thanks!

Show 53 quoted lines
> > diff --git a/t/unit-tests/t-hash.c b/t/unit-tests/u-hash.c
> > similarity index 79%
> > rename from t/unit-tests/t-hash.c
> > rename to t/unit-tests/u-hash.c
> > ...
> >  #define TEST_HASH_STR(data, expected_sha1, expected_sha256) do { \
> >               const char *expected_hashes[] = { expected_sha1, expected_sha256 }; \
> > -             TEST(check_hash_data(data, strlen(data), expected_hashes), \
> > -                  "SHA1 and SHA256 (%s) works", #data); \
> > -     } while (0)
> > +             check_hash_data(data, strlen(data), expected_hashes); \
> > +     } while(0)
>
> Unwanted droppage of SP between "while" and "(0)".
>
> >  /* Only works with a literal string, useful when it contains a NUL character. */
> >  #define TEST_HASH_LITERAL(literal, expected_sha1, expected_sha256) do { \
> >               const char *expected_hashes[] = { expected_sha1, expected_sha256 }; \
> > -             TEST(check_hash_data(literal, (sizeof(literal) - 1), expected_hashes), \
> > -                  "SHA1 and SHA256 (%s) works", #literal); \
> > -     } while (0)
> > +             check_hash_data(literal, (sizeof(literal) - 1), expected_hashes); \
> > +     } while(0)
>
> Ditto.
>
> > -int cmd_main(int argc UNUSED, const char **argv UNUSED)
> > +void test_hash__empty_string(void)
> >  {
> > -     struct strbuf aaaaaaaaaa_100000 = STRBUF_INIT;
> > -     struct strbuf alphabet_100000 = STRBUF_INIT;
> > -
> > -     strbuf_addstrings(&aaaaaaaaaa_100000, "aaaaaaaaaa", 100000);
> > -     strbuf_addstrings(&alphabet_100000, "abcdefghijklmnopqrstuvwxyz", 100000);
> > -
> >       TEST_HASH_STR("",
> >               "da39a3ee5e6b4b0d3255bfef95601890afd80709",
> >               "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
> > +}
> > +
> > +void test_hash__single_character(void)
> > +{
> >       TEST_HASH_STR("a",
> >               "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8",
> >               "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb");
> > +}
>
> OK.
>
> I'll skip the rest as I expect they would be faithful conversions.
>
> Thanks.
>
I'll make the required changes, thank you for pointing them out.

Thanks Seyi

Previous: Junio C HamanoNext: Junio C Hamano
Message 13 of 18 in “t/unit-tests: convert hash tests to use clar”
  1. 0/2 t/unit-tests: convert hash tests to use clarSeyi Kuforiji, Jan 7, 2025
  2. 1/2 t/unit-tests: match functions signature with trailing codeSeyi Kuforiji, Jan 7, 2025
  3. Junio C HamanoJan 7, 2025
  4. Junio C HamanoJan 7, 2025
  5. Patrick SteinhardtJan 8, 2025
  6. Seyi ChamberJan 8, 2025
  7. Junio C HamanoJan 8, 2025
  8. Patrick SteinhardtJan 8, 2025
  9. 2/2 t/unit-tests: convert hash to use clar test frameworkSeyi Kuforiji, Jan 7, 2025
  10. 0/1 t/unit-tests: convert hash to use clar test frameworkSeyi Kuforiji, Jan 8, 2025
  11. 1/1 t/unit-tests: convert hash to use clar test frameworkSeyi Kuforiji, Jan 8, 2025
  12. Junio C HamanoJan 8, 2025
  13. Seyi ChamberJan 9, 2025
  14. Junio C HamanoJan 8, 2025
  15. Seyi ChamberJan 9, 2025
  16. t/unit-tests: convert hash to use clar test frameworkSeyi Kuforiji, Jan 9, 2025
  17. Patrick SteinhardtJan 9, 2025
  18. Junio C HamanoJan 9, 2025

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.