Re: expressive test macros (was: Report test_atomic_ops() failuresconsistently, via macros) - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: expressive test macros (was: Report test_atomic_ops() failuresconsistently, via macros)
Date
Msg-id f0906c55-87cb-e940-b27b-99d41c14d44d@2ndquadrant.com
Whole thread Raw
In response to Re: expressive test macros (was: Report test_atomic_ops() failuresconsistently, via macros)  (Noah Misch <noah@leadboat.com>)
Responses Re: expressive test macros (was: Report test_atomic_ops() failuresconsistently, via macros)
List 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



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Missed check for too-many-children in bgworker spawning
Next
From: Peter Eisentraut
Date:
Subject: Re: expressive test macros (was: Report test_atomic_ops() failuresconsistently, via macros)