-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecutionPlanTests.cpp
More file actions
156 lines (135 loc) · 4.97 KB
/
Copy pathExecutionPlanTests.cpp
File metadata and controls
156 lines (135 loc) · 4.97 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
*
* @file ExecutionPlanTests.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira. All rights reserved.
* https://github.com/vixcpp/vix
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Vix.cpp
*
* Execution plan, preset and build-context tests
*
*/
#include <vix/engine.hpp>
#include <cassert>
#include <filesystem>
#include <string>
#include <type_traits>
#include <vector>
namespace
{
namespace fs = std::filesystem;
using namespace vix::engine;
ExecutionPlan minimal_plan()
{
ExecutionPlan plan;
plan.userProjectDir = "/tmp/project";
plan.cmakeSourceDir = "/tmp/project";
plan.projectDir = "/tmp/project";
plan.preset = Preset{"dev-ninja", "Ninja", "Debug", "build-ninja"};
plan.buildDir = "/tmp/project/build-ninja";
return plan;
}
}
int main()
{
{
const std::vector<Preset> presets = builtin_presets();
assert(presets.size() == 3);
assert(presets[0].name == "dev");
assert(presets[0].generator == "Ninja");
assert(presets[0].buildType == "Debug");
assert(presets[0].buildDirName == "build-dev");
assert(presets[1].name == "dev-ninja");
assert(presets[1].generator == "Ninja");
assert(presets[1].buildType == "Debug");
assert(presets[1].buildDirName == "build-ninja");
assert(presets[2].name == "release");
assert(presets[2].generator == "Ninja");
assert(presets[2].buildType == "Release");
assert(presets[2].buildDirName == "build-release");
assert(resolve_builtin_preset("dev").has_value());
assert(resolve_builtin_preset("dev-ninja").has_value());
assert(resolve_builtin_preset("release").has_value());
assert(!resolve_builtin_preset("invalid-preset").has_value());
assert(!resolve_builtin_preset("").has_value());
assert((Preset{"x", "Ninja", "Debug", "build-x"}.valid()));
assert((!Preset{"", "Ninja", "Debug", "build-x"}.valid()));
assert((!Preset{"x", "", "Debug", "build-x"}.valid()));
assert((!Preset{"x", "Ninja", "", "build-x"}.valid()));
assert((!Preset{"x", "Ninja", "Debug", ""}.valid()));
}
{
static_assert(std::is_copy_constructible_v<Preset>);
static_assert(std::is_move_constructible_v<Preset>);
static_assert(std::is_copy_constructible_v<ExecutionPlan>);
static_assert(std::is_move_constructible_v<ExecutionPlan>);
ExecutionPlan empty;
assert(!empty.valid());
ExecutionPlan plan = minimal_plan();
assert(plan.valid());
assert(plan.configureLog.empty());
assert(plan.buildLog.empty());
assert(plan.sigFile.empty());
assert(plan.toolchainFile.empty());
assert(plan.sdkConfigDir.empty());
assert(plan.cmakeVars.empty());
assert(plan.signature.empty());
assert(!plan.launcher.has_value());
assert(!plan.fastLinkerFlag.has_value());
assert(plan.projectFingerprint.empty());
ExecutionPlan missingUser = plan;
missingUser.userProjectDir.clear();
assert(!missingUser.valid());
ExecutionPlan missingSource = plan;
missingSource.cmakeSourceDir.clear();
assert(!missingSource.valid());
ExecutionPlan missingBuild = plan;
missingBuild.buildDir.clear();
assert(!missingBuild.valid());
ExecutionPlan missingPreset = plan;
missingPreset.preset = Preset{};
assert(!missingPreset.valid());
plan.generatedFromVixApp = true;
plan.defaultTargetName = "hello";
plan.cmakeVars.push_back({"CMAKE_BUILD_TYPE", "Debug"});
plan.launcher = "ccache";
plan.fastLinkerFlag = "-fuse-ld=lld";
ExecutionPlan copy = plan;
assert(copy.generatedFromVixApp);
assert(copy.defaultTargetName == "hello");
assert(copy.cmakeVars.size() == 1);
assert(copy.launcher == "ccache");
assert(copy.fastLinkerFlag == "-fuse-ld=lld");
}
{
ExecutionPlan plan = minimal_plan();
BuildTargetOptions options;
options.buildTarget = "explicit";
assert(default_build_target_name(options, plan) == "explicit");
assert(default_graph_target_name(options, plan) == "explicit");
#ifdef _WIN32
const fs::path explicitExe = "/tmp/project/build-ninja/explicit.exe";
#else
const fs::path explicitExe = "/tmp/project/build-ninja/explicit";
#endif
assert(default_project_executable_path(options, plan) == explicitExe);
options.buildTarget.clear();
plan.defaultTargetName = "default-target";
assert(default_build_target_name(options, plan) == "default-target");
assert(default_graph_target_name(options, plan) == "default-target");
plan.defaultTargetName.clear();
assert(default_build_target_name(options, plan) == "project");
assert(default_graph_target_name(options, plan) == "project");
plan.projectDir.clear();
plan.userProjectDir = "/tmp/user-project";
assert(default_build_target_name(options, plan) == "user-project");
assert(default_graph_target_name(options, plan) == "user-project");
assert(default_build_target_name("direct", plan) == "direct");
assert(default_graph_target_name("direct", plan) == "direct");
}
return 0;
}