1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/*
* Copyright 2009- ECMWF.
*
* This software is licensed under the terms of the Apache Licence version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation
* nor does it submit to any jurisdiction.
*/
#include <string>
#include <vector>
#include <boost/test/unit_test.hpp>
#include "ecflow/core/File.hpp"
#include "ecflow/core/Str.hpp"
#include "ecflow/core/Version.hpp"
#include "ecflow/test/scaffold/Naming.hpp"
using namespace ecf;
template <typename... T>
bool contains(std::string_view value, T&&... pattern) {
return ((value.find(pattern) != std::string::npos) && ...);
}
std::string find_cmake_version(const std::vector<std::string>& cmake_content) {
// Assume a lines like the following:
// project( ecflow LANGUAGES CXX VERSION X.Y.Z )
//
// Find token `VERSION` and return the next token
for (auto& line : cmake_content) {
if (contains(line, "project", "ecflow", "LANGUAGES", "CXX", "VERSION")) {
std::vector<std::string> tokens;
Str::split(line, tokens);
auto version_arg = std::find(tokens.begin(), tokens.end(), "VERSION");
auto version_val = version_arg + 1;
if (version_val != tokens.end()) {
return *version_val;
break;
}
}
}
return "";
}
BOOST_AUTO_TEST_SUITE(U_Core)
BOOST_AUTO_TEST_SUITE(T_Version)
BOOST_AUTO_TEST_CASE(test_version) {
std::string desc = Version::description();
BOOST_CHECK_MESSAGE(!desc.empty(), "Expected version");
ECF_NAME_THIS_TEST(<< ", found version: " << desc);
}
BOOST_AUTO_TEST_CASE(test_version_raw_components) {
ECF_NAME_THIS_TEST();
auto actual = Version::base();
auto expected = Version::major() + "." + Version::minor() + "." + Version::patch();
BOOST_CHECK_EQUAL(actual, expected);
}
BOOST_AUTO_TEST_CASE(test_version_full_components) {
ECF_NAME_THIS_TEST();
auto actual = Version::full();
auto expected = Version::major() + "." + Version::minor() + "." + Version::patch() + Version::suffix();
BOOST_CHECK_EQUAL(actual, expected);
}
BOOST_AUTO_TEST_CASE(test_version_against_cmake) {
ECF_NAME_THIS_TEST();
// Load CMakeList.txt
std::string version_cmake_file = File::root_source_dir() + "/CMakeLists.txt";
std::vector<std::string> lines;
BOOST_REQUIRE_MESSAGE(File::splitFileIntoLines(version_cmake_file, lines, true /* ignore empty lines */),
"Failed to open file " << version_cmake_file << " (" << strerror(errno) << ")");
BOOST_REQUIRE_MESSAGE(!lines.empty(), "File " << version_cmake_file << " does not contain version info ??");
// Find CMake project version
auto actual_version = find_cmake_version(lines);
BOOST_CHECK_MESSAGE(!actual_version.empty(), "Unable to find CMake version in file " << version_cmake_file);
auto expected_version = Version::base();
BOOST_CHECK_EQUAL(actual_version, expected_version);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
|