Skip to content

Commit 9aaf629

Browse files
authored
Merge pull request #2399 from joto/clang-tidy-test-headers
A grab-bag of fixes for clang-tidy issues in test headers
2 parents 66314dd + 0168cab commit 9aaf629

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

tests/common-cleanup.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ namespace testing::cleanup {
2626
class file_t
2727
{
2828
public:
29-
explicit file_t(std::string const &filename,
30-
bool remove_on_construct = true)
31-
: m_filename(filename)
29+
explicit file_t(std::string filename, bool remove_on_construct = true)
30+
: m_filename(std::move(filename))
3231
{
3332
if (remove_on_construct) {
3433
delete_file(false);
@@ -38,6 +37,10 @@ class file_t
3837
~file_t() noexcept { delete_file(true); }
3938

4039
private:
40+
// This function is run from a destructor so must be noexcept. If an
41+
// exception does occur the program is terminated and we are fine with
42+
// that, it is test code after all.
43+
// NOLINTNEXTLINE(bugprone-exception-escape)
4144
void delete_file(bool warn) const noexcept
4245
{
4346
if (m_filename.empty()) {

tests/common-options.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class opt_t
3333
m_opt.output_dbschema = "public";
3434
}
3535

36+
// Implicit conversion is intended here for ease of use in lots of tests.
37+
// NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
3638
operator options_t() const { return m_opt; }
3739

3840
opt_t &slim()

tests/common-pg.hpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class tempdb_t
122122
"Test database cannot be created: {}\n"
123123
"Did you mean to run 'pg_virtualenv ctest'?\n",
124124
e.what());
125-
std::exit(1);
125+
std::exit(1); // NOLINT(concurrency-mt-unsafe)
126126
}
127127
}
128128

@@ -134,22 +134,25 @@ class tempdb_t
134134

135135
~tempdb_t() noexcept
136136
{
137-
if (!m_db_name.empty()) {
138-
// Disable removal of the test database by setting the environment
139-
// variable OSM2PGSQL_KEEP_TEST_DB to anything. This can be useful
140-
// when debugging tests.
141-
char const *const keep_db = std::getenv("OSM2PGSQL_KEEP_TEST_DB");
142-
if (keep_db != nullptr) {
143-
return;
144-
}
145-
try {
146-
connection_params_t connection_params;
147-
connection_params.set("dbname", "postgres");
148-
conn_t const conn{connection_params};
149-
conn.exec(R"(DROP DATABASE IF EXISTS "{}")", m_db_name);
150-
} catch (...) {
151-
fprintf(stderr, "DROP DATABASE failed. Ignored.\n");
152-
}
137+
if (m_db_name.empty()) {
138+
return;
139+
}
140+
141+
// Disable removal of the test database by setting the environment
142+
// variable OSM2PGSQL_KEEP_TEST_DB to anything. This can be useful
143+
// when debugging tests.
144+
// NOLINTNEXTLINE(concurrency-mt-unsafe)
145+
char const *const keep_db = std::getenv("OSM2PGSQL_KEEP_TEST_DB");
146+
if (keep_db != nullptr) {
147+
return;
148+
}
149+
try {
150+
connection_params_t connection_params;
151+
connection_params.set("dbname", "postgres");
152+
conn_t const conn{connection_params};
153+
conn.exec(R"(DROP DATABASE IF EXISTS "{}")", m_db_name);
154+
} catch (...) {
155+
fmt::print(stderr, "DROP DATABASE failed. Ignored.\n");
153156
}
154157
}
155158

0 commit comments

Comments
 (0)