test(build): a source's declaration and imports, as its compile reads them
SourceScan builds copies of six fixtures and checks what the build read
in their sources, by the modules and units it gives each configuration,
and runs the program where what it does depends on that:
- text, three of the four inputs of #45: `import Base;` and
`import Spaced ;` are imports, and an import in a comment that spans
lines or under #if 0 is none. A build with nothing changed then
rewrites none of the scans, and one that cannot be read is taken
again.
- quoted, the fourth: an implementation source whose string literal
holds "export module std;" is a unit of no module, and the build
succeeds.
- partition: a .cppm that declares an implementation partition
(`module X:Impl;`) is the partition Impl of X, and the implementation
unit that imports it has its edge to it.
- define: an #ifdef on a define that the test sets after listing the
source decides whether the source imports a module.
- switch: an #if on a header of the library the app is built on decides
it. The header is edited, and the source is scanned again; then the
app is built on another library, whose header of that name says the
other thing, so that only the command the scan was taken with has
changed.
- missing: an #include of a header that is not there fails the build
with a message naming the header, and nothing is compiled of the
source.
On the engine of the range's base, with only this test added, every case
but missing fails. Each of the three inputs of the text case is read the
old way, and its first build fails outright whenever Spaced.cppm, whose
import of Base was missed, is compiled before Base's BMI is there; the
string literal makes the listing throw "Module std not found not found",
and the implementation partition the listing of the partition case, "No
module declaration found"; the import under the #ifdef counts without
the define, and the one under the #if after the edit and after the swap;
and there is no scan to look at. The missing case passes there too, the
compile reporting the header as the scan now does.
2026-11-27 09:25:53 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
|
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
|
|
|
|
|
|
|
|
|
// No unit of any module: what reads as a module declaration below is the
|
|
|
|
|
// text of a string literal.
|
|
|
|
|
int QuotedLength() {
|
|
|
|
|
constexpr char text[] = "export module std;";
|
|
|
|
|
return static_cast<int>(sizeof(text)) - 1;
|
|
|
|
|
}
|