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. Hope this is constructive Dave