From 649829fe96e418b5c78c962456ce42258f2bc166 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 4 Mar 2023 01:34:03 +0100 Subject: [PATCH] Provide version major/minor/patch macros (#2014) --- CHANGELOG.md | 2 ++ api/include/opentelemetry/version.h | 4 ++++ api/test/core/BUILD | 15 +++++++++++++++ api/test/core/CMakeLists.txt | 8 ++++++++ api/test/core/version_test.cc | 16 ++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 api/test/core/version_test.cc diff --git a/CHANGELOG.md b/CHANGELOG.md index 19420f94e6..2e85d23935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ Increment the: * Fix Prometheus server crash on listening to already used port [#1986](https://github.com/open-telemetry/opentelemetry-cpp/pull/1986) * [EXPORTER] Boolean environment variables not parsed per the spec [#1982](https://github.com/open-telemetry/opentelemetry-cpp/pull/1982) +* Provide version major/minor/patch macros + [#2014](https://github.com/open-telemetry/opentelemetry-cpp/pull/2014) ## [1.8.2] 2023-01-31 diff --git a/api/include/opentelemetry/version.h b/api/include/opentelemetry/version.h index 0672a7546f..82bfa8811c 100644 --- a/api/include/opentelemetry/version.h +++ b/api/include/opentelemetry/version.h @@ -8,6 +8,10 @@ #define OPENTELEMETRY_ABI_VERSION_NO 1 #define OPENTELEMETRY_VERSION "1.8.2" +#define OPENTELEMETRY_VERSION_MAJOR 1 +#define OPENTELEMETRY_VERSION_MINOR 8 +#define OPENTELEMETRY_VERSION_PATCH 2 + #define OPENTELEMETRY_ABI_VERSION OPENTELEMETRY_STRINGIFY(OPENTELEMETRY_ABI_VERSION_NO) // clang-format off diff --git a/api/test/core/BUILD b/api/test/core/BUILD index 2736bbc474..38c65e6d31 100644 --- a/api/test/core/BUILD +++ b/api/test/core/BUILD @@ -15,3 +15,18 @@ cc_test( "@com_google_googletest//:gtest_main", ], ) + +cc_test( + name = "version_test", + srcs = [ + "version_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/api/test/core/CMakeLists.txt b/api/test/core/CMakeLists.txt index ebb9c1625b..7123f9a708 100644 --- a/api/test/core/CMakeLists.txt +++ b/api/test/core/CMakeLists.txt @@ -10,3 +10,11 @@ gtest_add_tests( TARGET timestamp_test TEST_PREFIX trace. TEST_LIST timestamp_test) + +add_executable(version_test version_test.cc) +target_link_libraries(version_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) +gtest_add_tests( + TARGET version_test + TEST_PREFIX version. + TEST_LIST version_test) diff --git a/api/test/core/version_test.cc b/api/test/core/version_test.cc new file mode 100644 index 0000000000..2e360ffdad --- /dev/null +++ b/api/test/core/version_test.cc @@ -0,0 +1,16 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/version.h" + +#include + +TEST(VersionTest, Consistency) +{ + char expected[10]; + snprintf(expected, sizeof(expected), "%d.%d.%d", OPENTELEMETRY_VERSION_MAJOR, + OPENTELEMETRY_VERSION_MINOR, OPENTELEMETRY_VERSION_PATCH); + + std::string actual = OPENTELEMETRY_VERSION; + EXPECT_EQ(actual, expected); +}