Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
compiler_module_resolver_test.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
36#include <gtest/gtest.h>
37
39
40using namespace Aleph;
41
43{
45
47 main_module.name = "main.aw";
48 main_module.imports.append({"math.aw", {}});
49 modules.append(std::move(main_module));
50
52 math_module.name = "math.aw";
53 modules.append(std::move(math_module));
54
55 const auto result = compiler_resolve_module_order(modules);
56 ASSERT_TRUE(result.valid);
57 ASSERT_TRUE(result.issues.is_empty());
58 ASSERT_EQ(result.order.size(), 2u);
59 EXPECT_EQ(modules.access(result.order.access(0)).name, "math.aw");
60 EXPECT_EQ(modules.access(result.order.access(1)).name, "main.aw");
61
62 const auto artifact = compiler_render_module_order(result.order, modules);
64 "ImportOrder\n"
65 " [0] math.aw\n"
66 " [1] main.aw\n");
67}
68
70{
72
74 main_module.name = "main.aw";
75 main_module.imports.append({"missing.aw", {}});
76 modules.append(std::move(main_module));
77
78 const auto result = compiler_resolve_module_order(modules);
79 ASSERT_FALSE(result.valid);
80 ASSERT_EQ(result.issues.size(), 1u);
81 EXPECT_EQ(result.issues.access(0).kind,
82 Compiler_Module_Resolution_Issue_Kind::Missing_Dependency);
83 EXPECT_EQ(result.issues.access(0).module_name, "main.aw");
84 EXPECT_EQ(result.issues.access(0).dependency_name, "missing.aw");
85}
86
88{
90
92 a.name = "a.aw";
93 a.imports.append({"b.aw", {}});
94 modules.append(std::move(a));
95
97 b.name = "b.aw";
98 b.imports.append({"a.aw", {}});
99 modules.append(std::move(b));
100
101 const auto result = compiler_resolve_module_order(modules);
102 ASSERT_FALSE(result.valid);
103 ASSERT_EQ(result.issues.size(), 1u);
104 EXPECT_EQ(result.issues.access(0).kind,
105 Compiler_Module_Resolution_Issue_Kind::Cyclic_Dependency);
106 EXPECT_EQ(result.issues.access(0).module_name, "b.aw");
107 EXPECT_EQ(result.issues.access(0).dependency_name, "a.aw");
108}
109
111{
113
115 a.name = "a.aw";
116 a.imports.append({"b.aw", {}});
117 modules.append(std::move(a));
118
120 b.name = "b.aw";
121 b.imports.append({"a.aw", {}});
122 modules.append(std::move(b));
123
125 util.name = "util.aw";
126 modules.append(std::move(util));
127
129 main_module.name = "main.aw";
130 main_module.imports.append({"util.aw", {}});
131 modules.append(std::move(main_module));
132
133 const auto result = compiler_resolve_module_order(modules);
134 ASSERT_FALSE(result.valid);
135 ASSERT_EQ(result.issues.size(), 1u);
136 EXPECT_EQ(result.issues.access(0).kind,
137 Compiler_Module_Resolution_Issue_Kind::Cyclic_Dependency);
138
139 ASSERT_EQ(result.order.size(), 2u);
140 EXPECT_EQ(modules.access(result.order.access(0)).name, "util.aw");
141 EXPECT_EQ(modules.access(result.order.access(1)).name, "main.aw");
142}
143
145{
147
149 self_module.name = "self.aw";
150 self_module.imports.append({"self.aw", {}});
151 modules.append(std::move(self_module));
152
153 const auto result = compiler_resolve_module_order(modules);
154 ASSERT_FALSE(result.valid);
155 ASSERT_EQ(result.issues.size(), 1u);
156 EXPECT_EQ(result.issues.access(0).kind,
157 Compiler_Module_Resolution_Issue_Kind::Cyclic_Dependency);
158 EXPECT_EQ(result.issues.access(0).module_name, "self.aw");
159 EXPECT_EQ(result.issues.access(0).dependency_name, "self.aw");
160
161 ASSERT_EQ(result.order.size(), 1u);
162 EXPECT_EQ(modules.access(result.order.access(0)).name, "self.aw");
163}
Reusable source-name module dependency resolution helpers.
T & access(const size_t i) const noexcept
Fast access without checking allocation and bound_min_clock checking.
T & append()
Allocate a new entry to the end of array.
#define TEST(name)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
std::string compiler_render_module_order(const DynArray< size_t > &order, const DynArray< Compiler_Module_Descriptor > &modules)
Renders one deterministic text artifact for a module order.
Compiler_Module_Resolution_Result compiler_resolve_module_order(const DynArray< Compiler_Module_Descriptor > &modules)
Resolves one dependency-first order for exact-name module imports.
One module descriptor consumed by the reusable resolver.
DynArray< Compiler_Module_Dependency > imports
Ordered dependency list.
std::string name
Stable module/source name.