[Breaking] Add global versioning. (#4936)
* Use CMake config file for representing version. * Generate c and Python version file with CMake. The generated file is written into source tree. But unless XGBoost upgrades its version, there will be no actual modification. This retains compatibility with Makefiles for R. * Add XGBoost version the DMatrix binaries. * Simplify prefetch detection in CMakeLists.txt
This commit is contained in:
61
tests/cpp/common/test_version.cc
Normal file
61
tests/cpp/common/test_version.cc
Normal file
@@ -0,0 +1,61 @@
|
||||
/*!
|
||||
* Copyright 2019 XGBoost contributors
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <dmlc/filesystem.h>
|
||||
#include <dmlc/io.h>
|
||||
|
||||
#include <xgboost/json.h>
|
||||
#include <xgboost/base.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../../../src/common/version.h"
|
||||
|
||||
namespace xgboost {
|
||||
TEST(Version, Basic) {
|
||||
Json j_ver { Object() };
|
||||
Version::Save(&j_ver);
|
||||
auto triplet { Version::Load(j_ver) };
|
||||
ASSERT_TRUE(Version::Same(triplet));
|
||||
|
||||
dmlc::TemporaryDirectory tempdir;
|
||||
const std::string fname = tempdir.path + "/version";
|
||||
|
||||
{
|
||||
std::unique_ptr<dmlc::Stream> fo(dmlc::Stream::Create(fname.c_str(), "w"));
|
||||
Version::Save(fo.get());
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<dmlc::Stream> fi(dmlc::Stream::Create(fname.c_str(), "r"));
|
||||
auto triplet { Version::Load(fi.get())};;
|
||||
ASSERT_TRUE(Version::Same(triplet));
|
||||
}
|
||||
|
||||
std::string str { Version::String(triplet) };
|
||||
|
||||
size_t ptr {0};
|
||||
XGBoostVersionT v {0};
|
||||
v = std::stoi(str, &ptr);
|
||||
ASSERT_EQ(str.at(ptr), '.');
|
||||
ASSERT_EQ(v, XGBOOST_VER_MAJOR) << "major: " << v;
|
||||
|
||||
str = str.substr(ptr+1);
|
||||
|
||||
ptr = 0;
|
||||
v = std::stoi(str, &ptr);
|
||||
ASSERT_EQ(str.at(ptr), '.');
|
||||
ASSERT_EQ(v, XGBOOST_VER_MINOR) << "minor: " << v;;
|
||||
|
||||
str = str.substr(ptr+1);
|
||||
|
||||
ptr = 0;
|
||||
v = std::stoi(str, &ptr);
|
||||
ASSERT_EQ(v, XGBOOST_VER_MINOR) << "patch: " << v;;
|
||||
|
||||
str = str.substr(ptr);
|
||||
ASSERT_EQ(str.size(), 0);
|
||||
}
|
||||
} // namespace xgboost
|
||||
Reference in New Issue
Block a user