From: Christian Couder Date: Fri, 26 Apr 2024 14:51:54 GMT Subject: Re: [PATCH v3 02/10] trailer: add unit tests for trailer iterator Message-ID: In-Reply-To: <4ad0fbbb33cab9d5841689cc5660befe6921d515.1714091170.git.gitgitgadget@gmail.com> On Fri, Apr 26, 2024 at 2:26 AM Linus Arver via GitGitGadget wrote: > > From: Linus Arver > > Test the number of trailers found by the iterator (to be more precise, > the parsing mechanism which the iterator just walks over) when given > some some arbitrary log message. s/some some/some/ > We test the iterator because it is a public interface function exposed > by the trailer API (we generally don't want to test internal > implementation details which are, unlike the API, subject to drastic > changes). > > Signed-off-by: Linus Arver > +static void run_t_trailer_iterator(void) > +{ > + static struct test_cases { > + const char *name; > + const char *msg; > + size_t num_expected_trailers; > + } tc[] = { ... > + }; > + > + for (int i = 0; i < sizeof(tc) / sizeof(tc[0]); i++) { > + TEST(t_trailer_iterator(tc[i].msg, > + tc[i].num_expected_trailers), > + "%s", tc[i].name); Nit: the members of struct test_cases are used in the (msg, num_expected_trailers, name) order, while they are declared in the (name, msg, num_expected_trailers) order. I think it would make it a bit easier to use in struct test_cases the same order in which they are used in the TEST() macro. > + } > +} > + > +int cmd_main(int argc, const char **argv) > +{ > + run_t_trailer_iterator(); > + return test_done(); > +} LGTM otherwise.