Skip to content

Commit b1b6da6

Browse files
committed
test
1 parent 02cae81 commit b1b6da6

File tree

6 files changed

+102
-30
lines changed

6 files changed

+102
-30
lines changed

.github/workflows/c-cpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ jobs:
7575
xmake-version: branch@dev
7676
actions-cache-folder: ".xmake-cache"
7777

78-
- run: deno run -A xmake.ts --toolchain=llvm --sdk=/usr/local/opt/llvm/
78+
- run: deno run -A xmake.ts --mode=test --group=test --toolchain=llvm --sdk=/usr/local/opt/llvm/
7979
- run: xmake clean && xmake f --toolchain=llvm --sdk=/usr/local/opt/llvm/ -y -v --project=. "--file=./xmake.lua"
8080
- run: xmake build -v -y -w --project=. "--file=./xmake.lua"

.github/workflows/msbuild.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ jobs:
2020

2121
steps:
2222
- uses: actions/checkout@v3
23-
# - name: Cache xmake
24-
# id: cache-xmake
25-
# uses: actions/cache@v3
26-
# with:
27-
# path: C:\hostedtoolcache\windows\xmake\dev\x64
28-
# key: ${{ runner.os }}-xmake-4fe1c80f57ce093a0f0c38100a773e9b2ad0512c
23+
2924
- uses: actions/cache@v3
3025
with:
3126
key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }}-${{ hashFiles('**/import_map.json') }}
@@ -64,12 +59,12 @@ jobs:
6459
with:
6560
deno-version: v1.33.1
6661
- uses: xmake-io/github-action-setup-xmake@v1
67-
#if: steps.cache-xmake.outputs.cache-hit != 'true'
62+
6863
with:
6964
xmake-version: branch@dev
7065
actions-cache-folder: ".xmake-cache"
7166

7267
- run: deno task cache
73-
- run: deno run -A xmake.ts --executable=C:\hostedtoolcache\windows\xmake\dev\x64\xmake.exe
68+
- run: deno run -A xmake.ts --mode=test --group=test --executable=C:\hostedtoolcache\windows\xmake\dev\x64\xmake.exe
7469
- run: C:\hostedtoolcache\windows\xmake\dev\x64\xmake.exe clean && C:\hostedtoolcache\windows\xmake\dev\x64\xmake.exe f -y -v --project=. "--file=./xmake.lua"
7570
- run: C:\hostedtoolcache\windows\xmake\dev\x64\xmake.exe build -v -y -w --project=. "--file=./xmake.lua"

split-a-circular-linked-list/ListNode.ixx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
module;
2+
#ifdef __TEST__
3+
#include <eventpp/callbacklist.h>
4+
#endif
15
export module leetcode_test.split_a_circular_linked_list.ListNode;
26
namespace leetcode_test::split_a_circular_linked_list {
37
export struct ListNode {
@@ -8,6 +12,25 @@ export struct ListNode {
812
: val(x)
913
, next(next)
1014
{
15+
#ifdef __TEST__
16+
CallbackNew(this);
17+
#endif
1118
}
19+
~ListNode()
20+
21+
{
22+
#ifdef __TEST__
23+
CallbackDelete(this);
24+
#endif
25+
}
26+
27+
#ifdef __TEST__
28+
static eventpp::CallbackList<void(ListNode*)> CallbackNew;
29+
static eventpp::CallbackList<void(ListNode*)> CallbackDelete;
30+
#endif
1231
};
32+
#ifdef __TEST__
33+
eventpp::CallbackList<void(ListNode*)> ListNode::CallbackDelete {};
34+
eventpp::CallbackList<void(ListNode*)> ListNode::CallbackNew {};
35+
#endif
1336
}

split-a-circular-linked-list/test.cpp

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,35 @@ import leetcode_test.split_a_circular_linked_list.TraversalCircularListNode;
88
#include <iterator>
99
#include <unordered_set>
1010
#include <vector>
11-
11+
#ifdef __TEST__
12+
#include <eventpp/callbacklist.h>
13+
#endif
1214
using namespace leetcode_test::split_a_circular_linked_list;
1315
using namespace std;
1416
using std::vector;
1517
template <class T>
16-
concept sizable = requires(T& t)
17-
{
18+
concept sizable = requires(T& t) {
1819
{
1920
t.size()
20-
} -> std::same_as<size_t>;
21+
} -> std::same_as<size_t>;
2122
};
2223
template <class T>
23-
concept iterable = requires(T& t)
24-
{
24+
concept iterable = requires(T& t) {
2525
++t.begin();
2626
{
2727
t.begin() != t.end()
2828

29-
} -> std::same_as<bool>;
29+
} -> std::same_as<bool>;
3030
};
3131

3232
template <class T, typename Y>
33-
concept equalable = requires(T& t, Y& y, size_t i)
34-
{
33+
concept equalable = requires(T& t, Y& y, size_t i) {
3534
{
3635
*t.begin() == *y.begin()
37-
} -> std::same_as<bool>;
36+
} -> std::same_as<bool>;
3837
};
3938
template <typename T, typename Y>
40-
requires sizable<T> and sizable<Y> and equalable<T, Y> and iterable<T> and iterable<Y>
39+
requires sizable<T> and sizable<Y> and equalable<T, Y> and iterable<T> and iterable<Y>
4140
auto assertContentEquals(T& left, Y& right)
4241
{
4342

@@ -51,8 +50,37 @@ auto assertContentEquals(T& left, Y& right)
5150
ASSERT_EQ(*a, *b);
5251
}
5352
}
53+
#ifdef __TEST__
54+
struct ListNodeInspector {
55+
unordered_set<ListNode*> nodes;
56+
eventpp::CallbackList<void(ListNode*)>::Handle handleNew;
57+
eventpp::CallbackList<void(ListNode*)>::Handle handleDelete;
58+
ListNodeInspector()
59+
{
60+
auto handleNew = ListNode::CallbackNew.append([this](auto* node) {
61+
std::cout << "ListNode New:" << node << std::endl;
62+
nodes.insert(node);
63+
});
64+
this->handleNew = handleNew;
65+
auto handleDelete = ListNode::CallbackDelete.append([this](auto* node) {
66+
std::cout << "ListNode Delete:" << node << std::endl;
67+
68+
nodes.erase(node);
69+
});
70+
this->handleDelete = handleDelete;
71+
}
72+
~ListNodeInspector()
73+
{
74+
ListNode::CallbackNew.remove(handleNew);
75+
ListNode::CallbackDelete.remove(handleDelete);
76+
}
77+
};
78+
#endif
5479
TEST(split_a_circular_linked_list, test1)
5580
{
81+
#ifdef __TEST__
82+
ListNodeInspector inspector;
83+
#endif
5684
using std::ranges::views::transform;
5785
auto input = vector<int> { 1, 5, 7 };
5886
auto output = vector<vector<int>> { { 1, 5 }, { 7 } };
@@ -67,9 +95,15 @@ TEST(split_a_circular_linked_list, test1)
6795
for (auto* node : nodes) {
6896
delete node;
6997
}
98+
#ifdef __TEST__
99+
ASSERT_EQ(size_t(0), inspector.nodes.size());
100+
#endif
70101
}
71102
TEST(split_a_circular_linked_list, test2)
72103
{
104+
#ifdef __TEST__
105+
ListNodeInspector inspector;
106+
#endif
73107
using std::ranges::views::transform;
74108
auto input = vector<int> { 2, 6, 1, 5 };
75109
auto output = vector<vector<int>> { { 2, 6 }, { 1, 5 } };
@@ -81,6 +115,9 @@ TEST(split_a_circular_linked_list, test2)
81115
for (auto* node : nodes) {
82116
delete node;
83117
}
118+
#ifdef __TEST__
119+
ASSERT_EQ(size_t(0), inspector.nodes.size());
120+
#endif
84121
}
85122

86123
int main(int argc, char** argv)

split-a-circular-linked-list/xmake.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
if is_mode("test") then add_requires("vcpkg::eventpp") end
12
set_policy("platform.longpaths", true)
23

34
add_rules("mode.debug", "mode.release");
45

56
set_languages("c17", "cxx20");
67
add_requires("vcpkg::gtest");
78
target("split-a-circular-linked-list-test");
9+
-- 如果当前编译模式是test
10+
if is_mode("test") then
11+
12+
-- 添加test编译宏
13+
add_defines("__TEST__")
14+
add_packages("vcpkg::eventpp")
15+
end
816
set_group("test")
917
set_default(false)
1018
set_kind("binary");

xmake.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ async function main() {
3030
const args = parse(Deno.args);
3131
const __dirname = Deno.cwd();
3232
console.log(JSON.stringify(args));
33-
const { sdk, toolchain } = args;
33+
const { sdk, toolchain, group, mode } = args;
3434
const { executable = "xmake" } = args;
3535
for await (const file of findFilesRecursive(__dirname, "test.cpp")) {
36-
await RunXmake(file, toolchain, sdk, executable);
36+
await RunXmake(file, toolchain, sdk, executable, group, mode);
3737
}
3838
}
3939

@@ -42,10 +42,12 @@ async function RunXmake(
4242
toolchain: string,
4343
sdk: string,
4444
executable: string,
45+
group: string,
46+
mode: string,
4547
) {
4648
//const os = Deno.build.os;
47-
await RunXmakeConfig(file, toolchain, sdk, executable);
48-
await retry(RunXmakeBuild.bind(null, file, executable), {
49+
await RunXmakeConfig(file, toolchain, sdk, executable, mode);
50+
await retry(RunXmakeBuild.bind(null, file, executable, group), {
4951
//maxAttempts: os === "windows" ? 10 : 1,
5052
retryOnError: async (e) => {
5153
const regexp = /error:.*cannot open file:(.*), Unknown/g;
@@ -67,22 +69,25 @@ async function RunXmake(
6769
} else return false;
6870
},
6971
});
70-
await RunXmakeTest(file, executable);
72+
await RunXmakeTest(file, executable, group);
7173
}
7274

7375
async function RunXmakeConfig(
7476
file: string,
7577
toolchain: string,
7678
sdk: string,
7779
executable: string,
80+
mode: string,
7881
) {
7982
console.log({ file });
8083
const cwd = path.dirname(file);
8184
const others = [
8285
`${executable} clean `,
8386
`${executable} f ${toolchain ? "--toolchain=" + toolchain : ""} ${
8487
sdk ? "--sdk=" + sdk : ""
85-
} -y -v --project=. "--file=./xmake.lua" `,
88+
} -y -v --project=. "--file=./xmake.lua" ${
89+
mode ? "--mode=" + mode : ""
90+
}`,
8691
];
8792
await RunCommandShell(others, cwd);
8893
}
@@ -117,23 +122,27 @@ export async function RunCommandShell(others: string[], cwd?: string) {
117122
}
118123
}
119124

120-
async function RunXmakeBuild(file: string, executable: string) {
125+
async function RunXmakeBuild(file: string, executable: string, group: string) {
121126
const cwd = path.dirname(file);
122127

123128
console.log({ file });
124129
// console.log({ os });
125130

126131
const others = [
127-
`${executable} build -v -y -w --project=. "--file=./xmake.lua" -g test`,
132+
`${executable} build -v -y -w --project=. "--file=./xmake.lua" ${
133+
group ? "--group=" + group : ""
134+
}`,
128135
];
129136
await RunCommandShell(others, cwd);
130137
}
131138

132-
async function RunXmakeTest(file: string, executable: string) {
139+
async function RunXmakeTest(file: string, executable: string, group: string) {
133140
console.log({ file });
134141
// console.log({ os });
135142
const others = [
136-
`${executable} run -v --project=. "--file=./xmake.lua" -g test`,
143+
`${executable} run -v --project=. "--file=./xmake.lua" ${
144+
group ? "--group=" + group : ""
145+
} `,
137146
];
138147
const cwd = path.dirname(file);
139148
await RunCommandShell(others, cwd);

0 commit comments

Comments
 (0)