Am 28.12.23 um 00:48 schrieb Junio C Hamano: > René Scharfe <l.s.r@xxxxxx> writes: > >>> Also it might not be a big issue here, but when the new unit test >>> framework was proposed, I commented on the fact that "left" and >>> "right" were perhaps a bit less explicit than "actual" and "expected". >> >> True. >> ... >> The added repetition is a bit grating. With a bit of setup, loop >> unrolling and stringification you can retain the property of only having >> to mention the class name once. Demo patch below. > > Nice. > > This (and your mempool thing) being one of the early efforts to > adopt the unit-test framework outside the initial set of sample > tests, it is understandable that we might find what framework offers > is still lacking. But at the same time, while the macro tricks > demonstrated here are all amusing to read and admire, it feels a bit > too much to expect that the test writers are willing to invent > something like these every time they want to test. > > Being a relatively faithful conversion of the original ctype tests, > with its thorough enumeration of test samples and expected output, > is what makes this test program require these macro tricks, and it > does not have much to do with the features (or lack thereof) of the > framework, I guess. *nod* > >> +struct ctype { >> + const char *name; >> + const char *expect; >> + int actual[256]; >> +}; >> + >> +static void test_ctype(const struct ctype *class) >> +{ >> + for (int i = 0; i < 256; i++) { >> + int expect = is_in(class->expect, i); >> + int actual = class->actual[i]; >> + int res = test_assert(TEST_LOCATION(), class->name, >> + actual == expect); >> + if (!res) >> + test_msg("%s classifies char %d (0x%02x) wrongly", >> + class->name, i, i); >> + } >> } > > Somehow, the "test_assert" does not seem to be adding much value > here (i.e. we can do "res = (actual == expect)" there). Is this > because we want to be able to report success, too? > > ... goes and looks at test_assert() ... > > Ah, is it because we want to be able to "skip" (which pretends that > the assert() was satisified). OK, but then the error reporting from > it is redundant with our own test_msg(). True, the test_msg() emits the old message here, but it doesn't have to report that the check failed anymore, because test_assert() already covers that part. It would only have to report the misclassified character and perhaps the expected result. René