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.
This commit is contained in:
parent
3c8f4ddb54
commit
08a506d34b
23 changed files with 483 additions and 0 deletions
8
tests/SourceScan/fixture/define/Extra.cppm
Normal file
8
tests/SourceScan/fixture/define/Extra.cppm
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module Extra;
|
||||
|
||||
export int ExtraValue() {
|
||||
return 40;
|
||||
}
|
||||
17
tests/SourceScan/fixture/define/main.cpp
Normal file
17
tests/SourceScan/fixture/define/main.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
// Imports Extra when the build defines CRAFTER_TEST_EXTRA, which the test
|
||||
// does after it lists this source.
|
||||
#ifdef CRAFTER_TEST_EXTRA
|
||||
import Extra;
|
||||
#endif
|
||||
|
||||
// Exits with 40 when CRAFTER_TEST_EXTRA is defined, 2 when it is not.
|
||||
int main() {
|
||||
#ifdef CRAFTER_TEST_EXTRA
|
||||
return ExtraValue();
|
||||
#else
|
||||
return 2;
|
||||
#endif
|
||||
}
|
||||
8
tests/SourceScan/fixture/missing/main.cpp
Normal file
8
tests/SourceScan/fixture/missing/main.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
#include "not-there.h"
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
10
tests/SourceScan/fixture/partition/X-Impl.cppm
Normal file
10
tests/SourceScan/fixture/partition/X-Impl.cppm
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
// An implementation partition, listed as an interface unit of the
|
||||
// configuration, as a partition another unit of the module imports has to be.
|
||||
module X:Impl;
|
||||
|
||||
int G() {
|
||||
return 7;
|
||||
}
|
||||
9
tests/SourceScan/fixture/partition/X.cpp
Normal file
9
tests/SourceScan/fixture/partition/X.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
module X;
|
||||
import :Impl;
|
||||
|
||||
int F() {
|
||||
return G();
|
||||
}
|
||||
6
tests/SourceScan/fixture/partition/X.cppm
Normal file
6
tests/SourceScan/fixture/partition/X.cppm
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module X;
|
||||
|
||||
export int F();
|
||||
8
tests/SourceScan/fixture/partition/main.cpp
Normal file
8
tests/SourceScan/fixture/partition/main.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
import X;
|
||||
|
||||
int main() {
|
||||
return F() == 7 ? 0 : 1;
|
||||
}
|
||||
9
tests/SourceScan/fixture/quoted/Quoted.cpp
Normal file
9
tests/SourceScan/fixture/quoted/Quoted.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// 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;
|
||||
}
|
||||
8
tests/SourceScan/fixture/quoted/main.cpp
Normal file
8
tests/SourceScan/fixture/quoted/main.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
int QuotedLength();
|
||||
|
||||
int main() {
|
||||
return QuotedLength() == 18 ? 0 : 1;
|
||||
}
|
||||
8
tests/SourceScan/fixture/switch/app/Extra.cppm
Normal file
8
tests/SourceScan/fixture/switch/app/Extra.cppm
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module Extra;
|
||||
|
||||
export int ExtraValue() {
|
||||
return 40;
|
||||
}
|
||||
19
tests/SourceScan/fixture/switch/app/main.cpp
Normal file
19
tests/SourceScan/fixture/switch/app/main.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
// WITH_EXTRA comes from the switch.h of the library the app is built on:
|
||||
// found through its directory, which is on the include path of what is
|
||||
// built on it.
|
||||
#include <switch.h>
|
||||
#if WITH_EXTRA
|
||||
import Extra;
|
||||
#endif
|
||||
|
||||
// Exits with 40 when WITH_EXTRA is 1, 2 when it is 0.
|
||||
int main() {
|
||||
#if WITH_EXTRA
|
||||
return ExtraValue();
|
||||
#else
|
||||
return 2;
|
||||
#endif
|
||||
}
|
||||
8
tests/SourceScan/fixture/switch/off/Off.cppm
Normal file
8
tests/SourceScan/fixture/switch/off/Off.cppm
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module Off;
|
||||
|
||||
export int OffValue() {
|
||||
return 0;
|
||||
}
|
||||
5
tests/SourceScan/fixture/switch/off/switch.h
Normal file
5
tests/SourceScan/fixture/switch/off/switch.h
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
#pragma once
|
||||
#define WITH_EXTRA 0
|
||||
8
tests/SourceScan/fixture/switch/on/On.cppm
Normal file
8
tests/SourceScan/fixture/switch/on/On.cppm
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module On;
|
||||
|
||||
export int OnValue() {
|
||||
return 1;
|
||||
}
|
||||
6
tests/SourceScan/fixture/switch/on/switch-off.h.in
Normal file
6
tests/SourceScan/fixture/switch/on/switch-off.h.in
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
// Copied over switch.h by the test, mid-run.
|
||||
#pragma once
|
||||
#define WITH_EXTRA 0
|
||||
5
tests/SourceScan/fixture/switch/on/switch.h
Normal file
5
tests/SourceScan/fixture/switch/on/switch.h
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
#pragma once
|
||||
#define WITH_EXTRA 1
|
||||
8
tests/SourceScan/fixture/text/Base.cppm
Normal file
8
tests/SourceScan/fixture/text/Base.cppm
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module Base;
|
||||
|
||||
export int BaseValue() {
|
||||
return 1;
|
||||
}
|
||||
11
tests/SourceScan/fixture/text/Commented.cppm
Normal file
11
tests/SourceScan/fixture/text/Commented.cppm
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module Commented;
|
||||
/*
|
||||
import Spaced;
|
||||
*/
|
||||
|
||||
export int CommentedValue() {
|
||||
return 3;
|
||||
}
|
||||
11
tests/SourceScan/fixture/text/Disabled.cppm
Normal file
11
tests/SourceScan/fixture/text/Disabled.cppm
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module Disabled;
|
||||
#if 0
|
||||
import Spaced;
|
||||
#endif
|
||||
|
||||
export int DisabledValue() {
|
||||
return 4;
|
||||
}
|
||||
10
tests/SourceScan/fixture/text/Spaced.cppm
Normal file
10
tests/SourceScan/fixture/text/Spaced.cppm
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module Spaced;
|
||||
// Two spaces after `import`, as a formatter that lines up columns writes it.
|
||||
import Base;
|
||||
|
||||
export int SpacedValue() {
|
||||
return BaseValue() + 1;
|
||||
}
|
||||
12
tests/SourceScan/fixture/text/main.cpp
Normal file
12
tests/SourceScan/fixture/text/main.cpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
// A space before the semicolon.
|
||||
import Spaced ;
|
||||
import Commented;
|
||||
import Disabled;
|
||||
|
||||
// Exits 0 when each module gives what it should.
|
||||
int main() {
|
||||
return SpacedValue() + CommentedValue() + DisabledValue() == 9 ? 0 : 1;
|
||||
}
|
||||
Loading…
Reference in a new issue