Re: expressive test macros (was: Report test_atomic_ops() failures consistently, via macros)

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Noah Misch <noah(at)leadboat(dot)com>, Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: expressive test macros (was: Report test_atomic_ops() failures consistently, via macros)
Date: 2019-10-07 19:56:20
Message-ID: f0906c55-87cb-e940-b27b-99d41c14d44d@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

On 2019-10-06 04:20, Noah Misch wrote:
>> Seems like putting ASSERT_{EQ,LT,...}_{U32,S32,...} (or Assert_Eq_...,
>> but that'd imo look weirder than the inconsistency) into c.h would make
>> sense, and EXPECT_ somewhere in common/pg_test.h or such?
>
> Sounds reasonable. For broader use, I would include the expected value, not
> just expected_expr:
>
> elog(ERROR, \
> "%s yielded %u, expected %s (%u) in file \"%s\" line %u", \
> #result_expr, result, #expected_expr, expected, __FILE__, __LINE__); \
>
> I didn't do that for the atomics tests, where expected_expr is always trivial.
> The codebase has plenty of Assert(x == y) where either of x or y could have
> the surprising value.

I've been meaning to propose some JUnit-style more-specific Assert
variants such as AssertEquals for this reason. But as Tom writes
nearby, it should be a straight wrapper around Assert, not elog. So
these need to be named separately.

Btw., JUnit uses the ordering convention assertEquals(expected, actual),
whereas Perl Test::More uses is(actual, expected). Let's make sure we
pick something and stick with it.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2019-10-07 19:58:08 Re: expressive test macros (was: Report test_atomic_ops() failures consistently, via macros)
Previous Message Bruce Momjian 2019-10-07 18:33:40 pgsql: doc: move mention of log_min_error_statement in a better spot

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2019-10-07 19:58:08 Re: expressive test macros (was: Report test_atomic_ops() failures consistently, via macros)
Previous Message Robert Haas 2019-10-07 19:55:58 Re: Missed check for too-many-children in bgworker spawning