Skip to content

Commit

Permalink
test: check the namespace is not cluttered with min/max
Browse files Browse the repository at this point in the history
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 <[email protected]>
[wagi: move the test to a seperate file]
Signed-off-by: Daniel Wagner <[email protected]>
  • Loading branch information
zhangjian3032 authored and igaw committed Feb 6, 2025
1 parent a9daa6a commit 0836183
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ if cxx_available
dependencies: libnvme_dep,
include_directories: [incdir, internal_incdir]
)

test('cpp-dump', cpp)

misc = executable(
'test-misc',
['misc.cc'],
dependencies: libnvme_dep,
include_directories: [incdir, internal_incdir]
)
test('cpp-misc', misc)

endif

register = executable(
Expand Down
22 changes: 22 additions & 0 deletions test/misc.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/**
* This file is part of libnvme.
* Copyright (c) 2025 Daniel Wagner, SUSE LLC
*/

#include <algorithm>
#include <libnvme.h>

static int minmax_test()
{
/*
* Ensure libnvme doesn't spoil the namespace, e.g. by exposing a
* min/max macro.
*/
return !(std::min(1, 2) == 1 && std::max(1, 2) == 2);
}

int main(int argc, char *argv[])
{
return minmax_test();
}

0 comments on commit 0836183

Please sign in to comment.