From 2317b4608821b03da0cc288d06b9c0bdb6b60239 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 22 May 2021 16:42:06 +0100 Subject: Pass linter checks Except IWYU, doesn't like the C++20 CTF. --- iwyu.json | 18 +++++++++++++++++- lib/Jamfile.jam | 1 + lib/bitset.h | 2 +- lib/eventHandlerBase.cpp | 2 ++ lib/input/mysqlConn.cpp | 4 +++- lib/input/replStream.cpp | 9 +++++++-- lib/input/replStream.h | 6 +++++- lib/mysql_types.cpp | 10 +++++----- lib/mysql_types.h | 5 ++--- lib/output/dumpToConsole.cpp | 6 +++--- lib/output/dumpToConsole.h | 2 +- lib/rawDataReader.cpp | 5 ----- lib/rawDataReader.h | 8 +------- lib/row.cpp | 6 ++++++ lib/row.h | 9 +++++++-- lib/streamSupport.cpp | 2 +- test/test-bitset.cpp | 6 ++++-- test/test-rawDataReader.cpp | 16 +++++++++++++--- test/test-streams.cpp | 19 ++++++++++++++++--- 19 files changed, 95 insertions(+), 41 deletions(-) diff --git a/iwyu.json b/iwyu.json index 5785628..4fd09e5 100644 --- a/iwyu.json +++ b/iwyu.json @@ -9,12 +9,28 @@ }, { "include": [ - "", + "@.(mysql|mariadb_(com|ctype|dyncol|stmt|version))\\.h.", "private", "", "public" ] }, + { + "include": [ + "@.mariadb_rpl\\.h.", + "private", + "\"mariadb_repl.h\"", + "public" + ] + }, + { + "include": [ + "", + "private", + "", + "public" + ] + }, { "include": [ "", diff --git a/lib/Jamfile.jam b/lib/Jamfile.jam index 02374c9..05699a8 100644 --- a/lib/Jamfile.jam +++ b/lib/Jamfile.jam @@ -2,6 +2,7 @@ lib mygrate : [ glob-tree *.cpp ] : static + . ..//libmariadb : : . diff --git a/lib/bitset.h b/lib/bitset.h index 40ee3ed..b604ccf 100644 --- a/lib/bitset.h +++ b/lib/bitset.h @@ -2,7 +2,7 @@ #define MYGRATE_BITSET_H #include -#include +#include #include namespace MyGrate { diff --git a/lib/eventHandlerBase.cpp b/lib/eventHandlerBase.cpp index 7f9b2d4..777c746 100644 --- a/lib/eventHandlerBase.cpp +++ b/lib/eventHandlerBase.cpp @@ -1,4 +1,6 @@ #include "eventHandlerBase.h" +#include +#include namespace MyGrate { void diff --git a/lib/input/mysqlConn.cpp b/lib/input/mysqlConn.cpp index 38feb35..6c00628 100644 --- a/lib/input/mysqlConn.cpp +++ b/lib/input/mysqlConn.cpp @@ -2,7 +2,9 @@ #include namespace MyGrate::Input { - MySQLConn::MySQLConn(const char * const host, const char * const user, const char * const pass, unsigned short port) + MySQLConn::MySQLConn( + const char * const host, const char * const user, const char * const pass, unsigned short port) : + st_mysql {} { mysql_init(this); if (!mysql_real_connect(this, host, user, pass, "", port, nullptr, 0)) { diff --git a/lib/input/replStream.cpp b/lib/input/replStream.cpp index 88c3caf..c894941 100644 --- a/lib/input/replStream.cpp +++ b/lib/input/replStream.cpp @@ -1,6 +1,11 @@ #include "replStream.h" -#include "../eventHandlers.h" -#include "../mariadb_repl.h" +#include "mariadb_repl.h" +#include +#include +#include +#include +#include +#include namespace MyGrate::Input { void diff --git a/lib/input/replStream.h b/lib/input/replStream.h index 983d9d3..4b1a7b6 100644 --- a/lib/input/replStream.h +++ b/lib/input/replStream.h @@ -1,8 +1,12 @@ #ifndef MYGRATE_INPUT_REPLSTREAM_H #define MYGRATE_INPUT_REPLSTREAM_H -#include "../eventSourceBase.h" #include "mysqlConn.h" +#include + +namespace MyGrate { + class EventHandlerBase; +} namespace MyGrate::Input { class ReplicationStream : public EventSourceBase, MySQLConn { diff --git a/lib/mysql_types.cpp b/lib/mysql_types.cpp index b61de08..a4641ba 100644 --- a/lib/mysql_types.cpp +++ b/lib/mysql_types.cpp @@ -1,8 +1,10 @@ #include "mysql_types.h" #include "helpers.h" #include "rawDataReader.h" -#include +#include +#include #include +#include namespace MyGrate::MySQL { typename Type::C @@ -96,13 +98,11 @@ namespace MyGrate::MySQL { const auto realtype {md.readValue()}; \ const auto lenlen {md.readValue()}; \ switch (realtype) { \ - case MYSQL_TYPE_ENUM: { \ + case MYSQL_TYPE_ENUM: \ + case MYSQL_TYPE_VAR_STRING: \ return data.viewValue(lenlen); \ - break; \ - } \ default: \ throw std::logic_error("Not implemented: sub-type: " + std::to_string(realtype)); \ - break; \ } \ throw std::logic_error("Didn't return a value: " + std::to_string(realtype)); \ } diff --git a/lib/mysql_types.h b/lib/mysql_types.h index ec578f7..af45b4f 100644 --- a/lib/mysql_types.h +++ b/lib/mysql_types.h @@ -2,16 +2,15 @@ #define MYGRATE_MYSQL_TYPES_H #include "bitset.h" -#include #include #include #include -#include // IWYU pragma: keep +#include #include #include #include -#include +struct timespec; namespace MyGrate { class RawDataReader; diff --git a/lib/output/dumpToConsole.cpp b/lib/output/dumpToConsole.cpp index 6ece800..4cc9cc9 100644 --- a/lib/output/dumpToConsole.cpp +++ b/lib/output/dumpToConsole.cpp @@ -1,7 +1,7 @@ #include "dumpToConsole.h" -#include "../compileTimeFormatter.h" -#include "../row.h" -#include "../streamSupport.h" +#include +#include +#include namespace MyGrate::Output { void diff --git a/lib/output/dumpToConsole.h b/lib/output/dumpToConsole.h index 98769a6..d03c795 100644 --- a/lib/output/dumpToConsole.h +++ b/lib/output/dumpToConsole.h @@ -1,7 +1,7 @@ #ifndef MYGRATE_OUTPUT_DUMPTOCONSOLE_H #define MYGRATE_OUTPUT_DUMPTOCONSOLE_H -#include "../eventHandlerBase.h" +#include namespace MyGrate::Output { class DumpToConsole : public MyGrate::EventHandlerBase { diff --git a/lib/rawDataReader.cpp b/lib/rawDataReader.cpp index 2dd87a9..90e227a 100644 --- a/lib/rawDataReader.cpp +++ b/lib/rawDataReader.cpp @@ -1,9 +1,4 @@ #include "rawDataReader.h" -#include "helpers.h" -#include "streamSupport.h" -#include -#include -#include namespace MyGrate { RawDataReader::RawDataReader(const void * const d, std::size_t l) : diff --git a/lib/rawDataReader.h b/lib/rawDataReader.h index 0ed2847..906eaef 100644 --- a/lib/rawDataReader.h +++ b/lib/rawDataReader.h @@ -2,17 +2,11 @@ #define MYGRATE_RAW_DATA_READER_H #include "helpers.h" -#include +#include "mariadb_repl.h" #include #include #include -#include -#include // IWYU pragma: keep -#include #include -#include - -#include namespace MyGrate { struct PackedInteger { diff --git a/lib/row.cpp b/lib/row.cpp index 45e2959..65ac591 100644 --- a/lib/row.cpp +++ b/lib/row.cpp @@ -1,4 +1,10 @@ #include "row.h" +#include "bitset.h" +#include "mariadb_repl.h" +#include "rawDataReader.h" +#include +#include +#include #include #include diff --git a/lib/row.h b/lib/row.h index 4191644..a40b1b2 100644 --- a/lib/row.h +++ b/lib/row.h @@ -2,8 +2,13 @@ #define MYGRATE_ROW_H #include "mysql_types.h" -#include "rawDataReader.h" -#include +#include +#include +namespace MyGrate { + class RawDataReader; +} +struct st_mariadb_rpl_rows_event; +struct st_mariadb_rpl_table_map_event; namespace MyGrate { class Row : public std::vector { diff --git a/lib/streamSupport.cpp b/lib/streamSupport.cpp index 541b191..1e5258c 100644 --- a/lib/streamSupport.cpp +++ b/lib/streamSupport.cpp @@ -11,7 +11,7 @@ namespace std { std::ostream & operator<<(std::ostream & s, const MARIADB_STRING & str) { - return s.write(str.str, str.length); + return s << std::string_view(str.str, str.length); } std::ostream & diff --git a/test/test-bitset.cpp b/test/test-bitset.cpp index 15e43d6..02b3893 100644 --- a/test/test-bitset.cpp +++ b/test/test-bitset.cpp @@ -1,10 +1,12 @@ #define BOOST_TEST_MODULE BitSet -#include #include #include "helpers.h" +#include #include #include +#include +#include using namespace MyGrate; @@ -14,7 +16,7 @@ BOOST_TEST_DONT_PRINT_LOG_VALUE(BitSet::Iterator); BOOST_AUTO_TEST_CASE(bitset) { - std::byte bytes[3] {0x00_b, 0xFF_b, 0xa1_b}; + constexpr std::array bytes {0x00_b, 0xFF_b, 0xa1_b}; BitSet bs {bytes}; BOOST_REQUIRE_EQUAL(bs.size(), 24); diff --git a/test/test-rawDataReader.cpp b/test/test-rawDataReader.cpp index 4ac0a8a..b211fe3 100644 --- a/test/test-rawDataReader.cpp +++ b/test/test-rawDataReader.cpp @@ -3,10 +3,20 @@ #include #include +#include "bitset.h" #include "helpers.h" +#include "mariadb_repl.h" +#include +#include +#include #include #include +#include #include +#include +#include +#include +#include using namespace MyGrate; @@ -147,10 +157,10 @@ BOOST_DATA_TEST_CASE(read_field_type, BOOST_AUTO_TEST_CASE(rdr_from_MARIADB_STRING) { - char buf[5] = "test"; - MARIADB_STRING str {buf, strlen(buf)}; + std::string buf {"test"}; + MARIADB_STRING str {buf.data(), buf.length()}; RawDataReader rdr {str}; - BOOST_CHECK_EQUAL(rdr.viewValue(4), "test"); + BOOST_CHECK_EQUAL(rdr.viewValue(buf.length()), buf); } using SimpleTypes = boost::mpl::list #include +#include "bitset.h" #include "helpers.h" +#include "mariadb_repl.h" +#include "mysql_types.h" +#include +#include +#include +#include +#include +#include +#include +#include +struct timespec; +struct tm; #include BOOST_FIXTURE_TEST_SUITE(stream, std::stringstream); @@ -56,7 +69,7 @@ BOOST_DATA_TEST_CASE(tss, *this << in; BOOST_CHECK_EQUAL(this->str(), exp); } -constexpr std::byte somebits[3] {0x00_b, 0xFF_b, 0xa1_b}; +constexpr std::array somebits {0x00_b, 0xFF_b, 0xa1_b}; BOOST_DATA_TEST_CASE(bss, boost::unit_test::data::make>({ {{MyGrate::BitSet {somebits}}, "[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1]"}, @@ -69,8 +82,8 @@ BOOST_DATA_TEST_CASE(bss, BOOST_AUTO_TEST_CASE(mariadb_string) { - char buf[5] = "test"; - MARIADB_STRING str {buf, strlen(buf)}; + std::string buf {"test"}; + MARIADB_STRING str {buf.data(), buf.length()}; *this << str; BOOST_CHECK_EQUAL(this->str(), buf); } -- cgit v1.2.3