Skip to content

Commit 0836183

Browse files
zhangjian3032igaw
authored andcommitted
test: check the namespace is not cluttered with min/max
libnvme defined a min/max macro before and exposed to all users. This has been removed but let's sure it doesn't come back, thus add a test for this. Before renaming the macro, the cpp's std::min will fail to compile. ``` ./test/cpp.cc: In function ‘int min_compile_test()’: ../src/nvme/util.h:563:19: error: expected unqualified-id before ‘(’ token 563 | #define min(x, y) ((x) > (y) ? (y) : (x)) ``` Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com> [wagi: move the test to a seperate file] Signed-off-by: Daniel Wagner <wagi@kernel.org>
1 parent a9daa6a commit 0836183

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

test/meson.build

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ if cxx_available
2323
dependencies: libnvme_dep,
2424
include_directories: [incdir, internal_incdir]
2525
)
26+
27+
test('cpp-dump', cpp)
28+
29+
misc = executable(
30+
'test-misc',
31+
['misc.cc'],
32+
dependencies: libnvme_dep,
33+
include_directories: [incdir, internal_incdir]
34+
)
35+
test('cpp-misc', misc)
36+
2637
endif
2738

2839
register = executable(

test/misc.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: LGPL-2.1-or-later
2+
/**
3+
* This file is part of libnvme.
4+
* Copyright (c) 2025 Daniel Wagner, SUSE LLC
5+
*/
6+
7+
#include <algorithm>
8+
#include <libnvme.h>
9+
10+
static int minmax_test()
11+
{
12+
/*
13+
* Ensure libnvme doesn't spoil the namespace, e.g. by exposing a
14+
* min/max macro.
15+
*/
16+
return !(std::min(1, 2) == 1 && std::max(1, 2) == 2);
17+
}
18+
19+
int main(int argc, char *argv[])
20+
{
21+
return minmax_test();
22+
}

0 commit comments

Comments
 (0)