Made version.h static and version_test.cpp dynamic.

Switched around the header and unit test. Now the unit test is created by CMake using the variables
set in there and the version.h header is created manually. Unit test checks that both the CMake
variables and header share the same version.
This commit is contained in:
Sam Kellett 2016-02-01 19:07:39 +00:00
parent cdc906085a
commit f008774edc
6 changed files with 35 additions and 34 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
build/
include/yaml-cpp/version.h
test/version_test.cpp

View File

@ -116,8 +116,6 @@ include_directories(${YAML_CPP_SOURCE_DIR}/include)
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
# Create version.h
configure_file(${header_directory}/version.h.in ${CMAKE_SOURCE_DIR}/${header_directory}/version.h)
###
### General compilation settings

View File

@ -7,11 +7,11 @@
#pragma once
#endif
#define YAML_CPP_VERSION_MAJOR ${YAML_CPP_VERSION_MAJOR}
#define YAML_CPP_VERSION_MINOR ${YAML_CPP_VERSION_MINOR}
#define YAML_CPP_VERSION_PATCH ${YAML_CPP_VERSION_PATCH}
#define YAML_CPP_VERSION_MAJOR 0
#define YAML_CPP_VERSION_MINOR 5
#define YAML_CPP_VERSION_PATCH 2
// String representation of the current version (ie. "0.1.2")
#define YAML_CPP_VERSION "${YAML_CPP_VERSION}"
#define YAML_CPP_VERSION "0.5.2"
#endif // YAML_CPP_VERSION_H

View File

@ -13,6 +13,9 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR
set(yaml_test_flags "-Wno-c99-extensions -Wno-variadic-macros -Wno-sign-compare")
endif()
# Create version_test.cpp
configure_file(${YAML_CPP_SOURCE_DIR}/test/version_test.cpp.in ${YAML_CPP_SOURCE_DIR}/test/version_test.cpp)
file(GLOB test_headers [a-z_]*.h)
file(GLOB test_sources [a-z_]*.cpp integration/[a-z_]*.cpp node/[a-z_]*.cpp)
file(GLOB test_new_api_sources new-api/[a-z]*.cpp)

View File

@ -1,27 +0,0 @@
#include "yaml-cpp/version.h"
#include "gtest/gtest.h"
namespace YAML {
namespace {
TEST(VersionTest, Major)
{
ASSERT_EQ(YAML_CPP_VERSION_MAJOR, 0);
}
TEST(VersionTest, Minor)
{
ASSERT_EQ(YAML_CPP_VERSION_MINOR, 5);
}
TEST(VersionTest, Path)
{
ASSERT_EQ(YAML_CPP_VERSION_PATCH, 2);
}
TEST(VersionTest, String)
{
ASSERT_STREQ(YAML_CPP_VERSION, "0.5.2");
}
}
}

27
test/version_test.cpp.in Normal file
View File

@ -0,0 +1,27 @@
#include "yaml-cpp/version.h"
#include "gtest/gtest.h"
namespace YAML {
namespace {
TEST(VersionTest, Major)
{
ASSERT_EQ(${YAML_CPP_VERSION_MAJOR}, YAML_CPP_VERSION_MAJOR);
}
TEST(VersionTest, Minor)
{
ASSERT_EQ(${YAML_CPP_VERSION_MINOR}, YAML_CPP_VERSION_MINOR);
}
TEST(VersionTest, Path)
{
ASSERT_EQ(${YAML_CPP_VERSION_PATCH}, YAML_CPP_VERSION_PATCH);
}
TEST(VersionTest, String)
{
ASSERT_STREQ("${YAML_CPP_VERSION}", YAML_CPP_VERSION);
}
}
}