Repository navigation
Expand file tree
/
Copy pathwhere_file.hpp
More file actions
118 lines (91 loc) · 3.42 KB
/
Copy pathwhere_file.hpp
File metadata and controls
118 lines (91 loc) · 3.42 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright 2025 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_DECIMAL_DECTEST_TEST_WHERE_FILE_HPP
#define BOOST_DECIMAL_DECTEST_TEST_WHERE_FILE_HPP
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
namespace boost {
namespace decimal {
namespace dectest {
// This will show untested paths based on where the CI coverage run finds the file
// LCOV_EXCL_START
auto where_file(const std::string& test_vectors_filename) -> std::string
{
// Try to open the file in each of the known relative paths
// in order to find out where it is located.
// Boost-root
std::string test_vectors_filename_relative = "libs/decimal/test/decimal-dectest/" + test_vectors_filename;
std::ifstream in_01(test_vectors_filename_relative.c_str());
const bool file_01_is_open { in_01.is_open() };
if(file_01_is_open)
{
in_01.close();
}
else
{
// Local test directory or IDE
test_vectors_filename_relative = "../test/decimal-dectest/" + test_vectors_filename;
std::ifstream in_02(test_vectors_filename_relative.c_str());
const bool file_02_is_open { in_02.is_open() };
if(file_02_is_open)
{
in_02.close();
}
else
{
// test/cover
test_vectors_filename_relative = "../../test/decimal-dectest/" + test_vectors_filename;
std::ifstream in_03(test_vectors_filename_relative.c_str());
const bool file_03_is_open { in_03.is_open() };
if(file_03_is_open)
{
in_03.close();
}
else
{
// CMake builds
test_vectors_filename_relative = "../../../../../libs/decimal/test/decimal-dectest/" + test_vectors_filename;
std::ifstream in_04(test_vectors_filename_relative.c_str());
const bool file_04_is_open { in_04.is_open() };
if(file_04_is_open)
{
in_04.close();
}
else
{
// Try to open the file from the absolute path.
test_vectors_filename_relative = test_vectors_filename;
std::ifstream in_05(test_vectors_filename_relative.c_str());
const bool file_05_is_open { in_05.is_open() };
if(file_05_is_open)
{
in_05.close();
}
else
{
// Clion Cmake builds
test_vectors_filename_relative = "../../../libs/decimal/test/decimal-dectest/" + test_vectors_filename;
std::ifstream in_06(test_vectors_filename_relative.c_str());
const bool file_06_is_open { in_06.is_open() };
if (file_06_is_open)
{
in_06.close();
}
else
{
test_vectors_filename_relative = "";
}
}
}
}
}
}
return test_vectors_filename_relative;
}
} // namespace dectest
} // namespace decimal
} // namespace boost
#endif //BOOST_DECIMAL_DECTEST_TEST_WHERE_FILE_HPP