-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_configure.cpp
More file actions
75 lines (62 loc) · 2.55 KB
/
Copy pathtest_configure.cpp
File metadata and controls
75 lines (62 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <gtest/gtest.h>
import std;
import mcpp.source_kind;
import mcpp.build.configure;
import mcpp.build.plan;
import mcpp.toolchain.model;
namespace {
struct TempDir {
std::filesystem::path path = std::filesystem::temp_directory_path()
/ std::format("mcpp-configure-{}",
std::chrono::steady_clock::now().time_since_epoch().count());
TempDir() { std::filesystem::create_directories(path); }
~TempDir() {
std::error_code ec;
std::filesystem::remove_all(path, ec);
}
};
void write_file(const std::filesystem::path& path, std::string_view text) {
std::filesystem::create_directories(path.parent_path());
std::ofstream out(path);
out << text;
}
TEST(ConfigurePrerequisites, StagesOnlyBmisNeededByLanguageTools) {
TempDir temp;
mcpp::build::BuildPlan plan;
plan.outputDir = temp.path / "out";
plan.toolchain.compiler = mcpp::toolchain::CompilerId::Clang;
plan.stdBmiPath = temp.path / "cache/std.pcm";
plan.stdCompatBmiPath = temp.path / "cache/std.compat.pcm";
write_file(plan.stdBmiPath, "std-bmi");
write_file(plan.stdCompatBmiPath, "std-compat-bmi");
mcpp::build::CompileUnit dep;
dep.servedFromCache = true;
dep.providesModule = "demo.dep";
dep.cachedBmi = temp.path / "cache/demo.dep.pcm";
dep.cachedObject = temp.path / "cache/demo.dep.o";
dep.object = "obj/demo.dep.o";
write_file(dep.cachedBmi, "dep-bmi");
write_file(dep.cachedObject, "dep-object");
plan.compileUnits.push_back(dep);
auto staged = mcpp::build::stage_configure_prerequisites(plan);
ASSERT_TRUE(staged.has_value()) << staged.error();
EXPECT_TRUE(std::filesystem::exists(plan.outputDir / "pcm.cache/std.pcm"));
EXPECT_TRUE(std::filesystem::exists(plan.outputDir / "pcm.cache/std.compat.pcm"));
EXPECT_TRUE(std::filesystem::exists(plan.outputDir / "pcm.cache/demo.dep.pcm"));
EXPECT_FALSE(std::filesystem::exists(plan.outputDir / dep.object));
}
TEST(ConfigurePrerequisites, MissingCachedBmiFailsBeforePublication) {
TempDir temp;
mcpp::build::BuildPlan plan;
plan.outputDir = temp.path / "out";
plan.toolchain.compiler = mcpp::toolchain::CompilerId::Clang;
mcpp::build::CompileUnit dep;
dep.servedFromCache = true;
dep.providesModule = "demo.dep";
dep.cachedBmi = temp.path / "missing/demo.dep.pcm";
plan.compileUnits.push_back(dep);
auto staged = mcpp::build::stage_configure_prerequisites(plan);
ASSERT_FALSE(staged.has_value());
EXPECT_NE(staged.error().find("demo.dep"), std::string::npos);
}
} // namespace