Skip to content

Commit 9196d75

Browse files
committed
Fix portability
1 parent af8fe94 commit 9196d75

5 files changed

Lines changed: 63 additions & 30 deletions

File tree

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class rusty_cppRecipe(ConanFile):
55
name = "rusty-cpp"
6-
version = "0.1.11"
6+
version = "0.1.12"
77

88
# Optional metadata
99
license = "dual licensed under the Apache License v2.0 and the MIT License"

include/rusty/macro.h

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,30 @@
2525
} \
2626
} while (0)
2727

28-
#define __rusty_first_arg(a, ...) a
29-
#define __rusty_drop_first_arg_with_prepended_comma(a, ...) , ## __VA_ARGS__
30-
31-
#define rusty_assert_eq(l, r, ...) do { \
28+
#define __rusty_assert_eq(l, r, fmt, ...) do { \
3229
auto left= (l); \
3330
auto right= (r); \
34-
if (sizeof(#__VA_ARGS__) == 1) { \
35-
rusty_assert( \
36-
left == right, "left = %s, right = %s", \
37-
std::to_string(left).c_str(), std::to_string(right).c_str() \
38-
); \
39-
} else { \
40-
rusty_assert( \
41-
left == right, "left = %s, right = %s. " __rusty_first_arg(__VA_ARGS__), \
42-
std::to_string(left).c_str(), std::to_string(right).c_str() \
43-
__rusty_drop_first_arg_with_prepended_comma(__VA_ARGS__) \
44-
); \
45-
} \
31+
rusty_assert( \
32+
left == right, "left = %s, right = %s. " fmt, \
33+
std::to_string(left).c_str(), std::to_string(right).c_str() \
34+
, ## __VA_ARGS__ \
35+
); \
4636
} while (0)
4737

48-
#define rusty_assert_ne(l, r, ...) do { \
38+
#define rusty_assert_eq(l, r, ...) \
39+
__rusty_assert_eq(l, r, "" __VA_ARGS__)
40+
41+
#define __rusty_assert_ne(l, r, fmt, ...) do { \
4942
auto left= (l); \
5043
auto right= (r); \
51-
if (sizeof(#__VA_ARGS__) == 1) { \
52-
rusty_assert( \
53-
left != right, "left = %s, right = %s", \
54-
std::to_string(left).c_str(), std::to_string(right).c_str() \
55-
); \
56-
} else { \
57-
rusty_assert( \
58-
left != right, "left = %s, right = %s. " __rusty_first_arg(__VA_ARGS__), \
59-
std::to_string(left).c_str(), std::to_string(right).c_str() \
60-
__rusty_drop_first_arg_with_prepended_comma(__VA_ARGS__) \
61-
); \
62-
} \
44+
rusty_assert( \
45+
left != right, "left = %s, right = %s. " fmt, \
46+
std::to_string(left).c_str(), std::to_string(right).c_str() \
47+
, ## __VA_ARGS__ \
48+
); \
6349
} while (0)
6450

51+
#define rusty_assert_ne(l, r, ...) \
52+
__rusty_assert_ne(l, r, "" __VA_ARGS__)
53+
6554
#endif // RUSTY_MACRO_H_

test_package/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(test_package LANGUAGES CXX)
3+
4+
find_package(rusty-cpp REQUIRED CONFIG)
5+
6+
add_executable(${PROJECT_NAME} test_package.cpp)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE rusty-cpp)

test_package/conanfile.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import cmake_layout, CMake
4+
import os
5+
6+
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeDeps", "CMakeToolchain"
10+
11+
def layout(self):
12+
cmake_layout(self)
13+
14+
def requirements(self):
15+
self.requires(self.tested_reference_str)
16+
17+
def build(self):
18+
cmake = CMake(self)
19+
cmake.configure()
20+
cmake.build()
21+
22+
def test(self):
23+
if can_run(self):
24+
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
25+
self.run(bin_path, env="conanrun")

test_package/test_package.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <iostream>
2+
#include <rusty/macro.h>
3+
#include <rusty/primitive.h>
4+
5+
int main(void) {
6+
rusty_assert(1);
7+
rusty_assert_eq(rusty::next_power_of_two((size_t)42), 64,
8+
"Math doesn't exist anymore");
9+
rusty_assert_eq(rusty::next_power_of_two((size_t)233), 256);
10+
11+
return EXIT_SUCCESS;
12+
}

0 commit comments

Comments
 (0)