Skip to content

Commit c9de4ee

Browse files
authored
Merge pull request #140 from Flamefire/coverage
Increase test coverage
2 parents ba092ab + 87c28ee commit c9de4ee

22 files changed

+648
-323
lines changed

.github/codecov.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ else
3939
: "${LCOV_BRANCH_COVERAGE:=1}" # Set default
4040

4141
lcov --gcov-tool="$GCOV" --rc lcov_branch_coverage=${LCOV_BRANCH_COVERAGE} --base-directory "$BOOST_ROOT/libs/$LIBRARY" --directory "$BOOST_ROOT" --capture --output-file all.info
42+
# dump a summary on the console
43+
lcov --gcov-tool="$GCOV" --rc lcov_branch_coverage=${LCOV_BRANCH_COVERAGE} --list all.info
4244

4345
# all.info contains all the coverage info for all projects - limit to ours
4446
# first we extract the interesting headers for our project then we use that list to extract the right things
4547
for f in $(for f2 in include/boost/*; do echo "$f2"; done | cut -f2- -d/); do echo "*/$f*"; done > /tmp/interesting
4648
echo headers that matter:
4749
cat /tmp/interesting
48-
xargs -L 999999 -a /tmp/interesting lcov --gcov-tool="$GCOV" --rc lcov_branch_coverage=${LCOV_BRANCH_COVERAGE} --extract all.info {} "*/libs/$LIBRARY/src/*" --output-file coverage.info
50+
xargs -L 999999 -a /tmp/interesting lcov --gcov-tool="$GCOV" --rc lcov_branch_coverage=${LCOV_BRANCH_COVERAGE} --extract all.info {} "*/libs/$LIBRARY/*" --output-file coverage.info
4951

5052
# dump a summary on the console - helps us identify problems in pathing
5153
lcov --gcov-tool="$GCOV" --rc lcov_branch_coverage=${LCOV_BRANCH_COVERAGE} --list coverage.info

.github/workflows/posix.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
UBSAN_OPTIONS: print_stacktrace=1
1414
B2_VARIANT: debug,release
1515
B2_LINK: shared,static
16+
LCOV_BRANCH_COVERAGE: 0
1617

1718
jobs:
1819
CI:
@@ -123,6 +124,11 @@ jobs:
123124
working-directory: ${{env.BOOST_ROOT}}
124125
run: ./b2 -j3 libs/$LIBRARY/test toolset=$B2_TOOLSET cxxstd=$B2_CXXSTD variant=$B2_VARIANT link=$B2_LINK $B2_ASAN $B2_UBSAN $B2_LINKFLAGS $B2_FLAGS
125126

127+
- name: Run tests with simulated no LFS support
128+
if: matrix.coverage
129+
working-directory: ${{env.BOOST_ROOT}}
130+
run: ./b2 -j3 libs/$LIBRARY/test toolset=$B2_TOOLSET cxxstd=$B2_CXXSTD variant=$B2_VARIANT link=$B2_LINK $B2_ASAN $B2_UBSAN $B2_LINKFLAGS $B2_FLAGS boost.nowide.lfs=no
131+
126132
- name: Collect coverage
127133
if: matrix.coverage
128134
run: ${{github.workspace}}/.github/codecov.sh collect

build/Jamfile.v2

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
# Copyright (c) 2002, 2006 Beman Dawes
44
# Copyright (c) 2012 Artyom Beilis (Tonkikh)
5-
# Copyright (c) 2020 Alexander Grund
5+
# Copyright (c) 2020-2021 Alexander Grund
66
#
77
# Distributed under the Boost Software License, Version 1.0.
88
# (See accompanying file LICENSE or www.boost.org/LICENSE_1_0.txt)
99
# See library home page at http://www.boost.org/libs/nowide
1010

1111
import ../../config/checks/config : requires ;
12+
import configure ;
13+
import feature ;
14+
15+
feature.feature boost.nowide.lfs : auto no : optional propagated ;
1216

1317
local requirements =
1418
<link>shared:<define>BOOST_NOWIDE_DYN_LINK=1
@@ -24,7 +28,7 @@ project boost/nowide
2428
cxx11_static_assert
2529
]
2630
[ check-target-builds ../config//cxx11_moveable_fstreams "std::fstream is moveable and swappable" : : <build>no ]
27-
[ check-target-builds ../config//lfs_support "Has Large File Support" : : <define>BOOST_NOWIDE_NO_LFS ]
31+
[ check-target-builds ../config//lfs_support "Has Large File Support" : : <define>BOOST_NOWIDE_NO_LFS ] <boost.nowide.lfs>no:<define>BOOST_NOWIDE_NO_LFS
2832
[ check-target-builds ../config//attribute_init_priority "Has attribute init_priority" : <define>BOOST_NOWIDE_HAS_INIT_PRIORITY ]
2933
: usage-requirements $(requirements)
3034
;

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ comment:
88
layout: "diff, files"
99
ignore:
1010
- "test/test.hpp"
11+
- "test/file_test_helpers.cpp"

doc/changelog.dox

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
\section changelog Changelog
1212

13+
\subsection changelog_next Next release
14+
15+
- Fix possible double-free when setting a custom buffer (`setbuf`) after filebuf already allocated an internal buffer
16+
- Handle some warnings (mostly on MSVC)
17+
1318
\subsection changelog_11_1_3 Nowide 11.1.3
1419

1520
- Fix missing config file in release

include/boost/nowide/filebuf.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ namespace nowide {
213213
setg(NULL, NULL, NULL);
214214
setp(NULL, NULL);
215215
if(owns_buffer_)
216+
{
216217
delete[] buffer_;
218+
owns_buffer_ = false;
219+
}
217220
buffer_ = s;
218221
buffer_size_ = (n >= 0) ? static_cast<size_t>(n) : 0;
219222
return this;

include/boost/nowide/utf8_codecvt.hpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <boost/nowide/replacement.hpp>
1313
#include <boost/nowide/utf/utf.hpp>
14+
#include <cassert>
1415
#include <cstdint>
1516
#include <locale>
1617

@@ -48,6 +49,11 @@ namespace nowide {
4849
template<typename CharType, int CharSize = sizeof(CharType)>
4950
class utf8_codecvt;
5051

52+
#ifdef BOOST_MSVC
53+
#pragma warning(push)
54+
#pragma warning(disable : 4996) // Disable deprecation warning for std::codecvt<char16_t, char, ...>
55+
#endif
56+
5157
/// Specialization for the UTF-8 <-> UTF-16 variant of the std::codecvt implementation
5258
template<typename CharType>
5359
class BOOST_SYMBOL_VISIBLE utf8_codecvt<CharType, 2> : public std::codecvt<CharType, char, std::mbstate_t>
@@ -58,6 +64,10 @@ namespace nowide {
5864
utf8_codecvt(size_t refs = 0) : std::codecvt<CharType, char, std::mbstate_t>(refs)
5965
{}
6066

67+
#ifdef BOOST_MSVC
68+
#pragma warning(pop)
69+
#endif
70+
6171
protected:
6272
using uchar = CharType;
6373

@@ -81,8 +91,10 @@ namespace nowide {
8191
return false;
8292
}
8393

94+
// LCOV_EXCL_START
8495
int do_length(std::mbstate_t& std_state, const char* from, const char* from_end, size_t max) const override
8596
{
97+
// LCOV_EXCL_STOP
8698
using utf16_traits = utf::utf_traits<uchar, 2>;
8799
std::uint16_t state = detail::read_state(std_state);
88100
const char* save_from = from;
@@ -225,11 +237,7 @@ namespace nowide {
225237
ch = BOOST_NOWIDE_REPLACEMENT_CHARACTER;
226238
}
227239
}
228-
if(!utf::is_valid_codepoint(ch))
229-
{
230-
r = std::codecvt_base::error;
231-
break;
232-
}
240+
assert(utf::is_valid_codepoint(ch)); // Any valid UTF16 sequence is a valid codepoint
233241
int len = utf::utf_traits<char>::width(ch);
234242
if(to_end - to < len)
235243
{
@@ -248,6 +256,11 @@ namespace nowide {
248256
}
249257
};
250258

259+
#ifdef BOOST_MSVC
260+
#pragma warning(push)
261+
#pragma warning(disable : 4996) // Disable deprecation warning for std::codecvt<char32_t, char, ...>
262+
#endif
263+
251264
/// Specialization for the UTF-8 <-> UTF-32 variant of the std::codecvt implementation
252265
template<typename CharType>
253266
class BOOST_SYMBOL_VISIBLE utf8_codecvt<CharType, 4> : public std::codecvt<CharType, char, std::mbstate_t>
@@ -256,6 +269,10 @@ namespace nowide {
256269
utf8_codecvt(size_t refs = 0) : std::codecvt<CharType, char, std::mbstate_t>(refs)
257270
{}
258271

272+
#ifdef BOOST_MSVC
273+
#pragma warning(pop)
274+
#endif
275+
259276
protected:
260277
using uchar = CharType;
261278

@@ -296,7 +313,7 @@ namespace nowide {
296313
}
297314
max--;
298315
}
299-
return from - start_from;
316+
return static_cast<int>(from - start_from);
300317
}
301318

302319
std::codecvt_base::result do_in(std::mbstate_t& /*state*/,

test/benchmark_fstream.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ class io_stdio
9494
}
9595
void write(const char* buf, int size)
9696
{
97-
TEST(std::fwrite(buf, 1, size, f_) == static_cast<size_t>(size));
97+
TEST_EQ(std::fwrite(buf, 1, size, f_), static_cast<size_t>(size));
9898
}
9999
void read(char* buf, int size)
100100
{
101-
TEST(std::fread(buf, 1, size, f_) == static_cast<size_t>(size));
101+
TEST_EQ(std::fread(buf, 1, size, f_), static_cast<size_t>(size));
102102
}
103103
void rewind()
104104
{
@@ -202,7 +202,7 @@ perf_data test_io(const char* file, bool binary)
202202
std::cout << " read block size " << std::setw(8) << block_size << " " << std::fixed << std::setprecision(3)
203203
<< speed << " MB/s" << std::endl;
204204
}
205-
TEST(std::remove(file) == 0);
205+
TEST_EQ(std::remove(file), 0);
206206
return results;
207207
}
208208

test/file_test_helpers.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ namespace boost {
1818
namespace nowide {
1919
namespace test {
2020

21-
void create_empty_file(const std::string& filepath)
22-
{
23-
auto* f = fopen(filepath.c_str(), "w");
24-
TEST(f);
25-
std::fclose(f);
26-
}
27-
2821
void create_file(const std::string& filepath, const std::string& contents, data_type type /*= data_type::text*/)
2922
{
3023
auto* f = fopen(filepath.c_str(), (type == data_type::binary) ? "wb" : "w");

test/test.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ inline void test_equal_impl(const T& lhs, const U& rhs, const char* file, const
8888
DISABLE_CONST_EXPR_DETECTED \
8989
} while(0) DISABLE_CONST_EXPR_DETECTED_POP
9090

91+
#define TEST_THROW(expr, error) \
92+
do \
93+
{ \
94+
test_mon(); \
95+
try \
96+
{ \
97+
expr; \
98+
test_failed(#error " not thrown", __FILE__, __LINE__, __FUNCTION__); \
99+
} catch(const error&) \
100+
{ /* OK */ \
101+
} \
102+
break; \
103+
DISABLE_CONST_EXPR_DETECTED \
104+
} while(0) DISABLE_CONST_EXPR_DETECTED_POP
105+
91106
#ifndef BOOST_NOWIDE_TEST_NO_MAIN
92107
// Tests should implement this
93108
void test_main(int argc, char** argv, char** env);
@@ -100,6 +115,9 @@ int main(int argc, char** argv, char** env)
100115
} catch(const std::exception& e)
101116
{
102117
std::cerr << "Failed " << e.what() << std::endl;
118+
#ifdef _MSC_VER
119+
std::cerr << "MSVC version " << _MSC_VER << std::endl;
120+
#endif
103121
return 1;
104122
}
105123
return 0;

0 commit comments

Comments
 (0)