On 4/19/21 3:13 PM, Koning, Paul wrote:


On Apr 19, 2021, at 4:50 PM, Martin Sebor via Gcc-patches 
<gcc-patches@gcc.gnu.org> wrote:

On 4/19/21 2:03 PM, David Malcolm wrote:
On Mon, 2021-04-19 at 13:47 -0600, Martin Sebor via Gcc-patches wrote:
The selftests at the end of many source files are only rarely read
or modified, but they contribute to the size/complexity of the files
and make moving within the rest of the code more difficult.

FWIW I prefer having the tests in the same file as the code they test.
Would anyone be opposed to moving any of them into new files of their
own? E.g., those in tree.c to tree-tests.c, etc.?  I would be happy
to do this for a subset of these, with the goal of eventually moving
all of them and adding new ones accordingly.
Having the selftests in the same source file as the thing they test
allows for the selftest to use "static" declarations and anonymous
namespaces from that file.  For example, the selftests in diagnostic-
show-locus.c make use of various things declared in an anonymous
namespace in that file.  If I had to move the selftests to a different
file, I'd have to expose these interfaces, which I don't want to do.

I was actually thinking of just #including each foo-tests.c file
to bring in the code right where it is now, so this shouldn't be
a problem.  Would that work for you?

Martin

How does that help the problem you said need to be solved?  If having self test 
code be part of the compilation unit makes modifying things more difficult, it 
doesn't matter whether that code is in the compilation unit due to being in the 
main source file, or due to being a #include.

The self tests make the sources bigger and so harder to move around
in and difficult to find just the calls to tested functions made
from elsewhere in the file or from other parts of the compiler (i.e.,
not tests).  They are only rarely relevant when reading or changing
the file.

Keeping them separate from the code they exercise will be helpful
to me and I assumed to others as well.  But I wouldn't want to make
some common tasks difficult, so if you or someone else has one that
would be made so by it, I won't pursue it.  Do you?

Martin

Reply via email to