Skip to content

Commit

Permalink
Merge pull request #237 from jerryct/warn
Browse files Browse the repository at this point in the history
Compile on build server with warnings as errors
  • Loading branch information
gjasny authored Dec 9, 2018
2 parents 6fe2f3d + e38d020 commit 09f56af
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ script:
- pushd .
- mkdir _build_internal_deps
- cd _build_internal_deps
- cmake .. -DUSE_THIRDPARTY_LIBRARIES=ON
- cmake .. -DUSE_THIRDPARTY_LIBRARIES=ON -DENABLE_WARNINGS_AS_ERRORS=ON
- make -j 4
- ctest -V
- mkdir -p deploy
Expand Down
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ if(ENABLE_TESTING)
enable_testing()
endif()

# suppress warnings

add_compile_options(
$<$<AND:$<STREQUAL:$<COMPILE_LANGUAGE>,CXX>,$<CXX_COMPILER_ID:AppleClang>>:-Wno-deprecated-declarations>
)
# build flags for CI system

if(ENABLE_WARNINGS_AS_ERRORS)
add_compile_options(
$<$<AND:$<STREQUAL:$<COMPILE_LANGUAGE>,CXX>,$<CXX_COMPILER_ID:AppleClang>>:-Werror>
$<$<AND:$<STREQUAL:$<COMPILE_LANGUAGE>,CXX>,$<CXX_COMPILER_ID:AppleClang>>:-Wall>
$<$<AND:$<STREQUAL:$<COMPILE_LANGUAGE>,CXX>,$<CXX_COMPILER_ID:AppleClang>>:-Wextra>
$<$<AND:$<STREQUAL:$<COMPILE_LANGUAGE>,CXX>,$<CXX_COMPILER_ID:AppleClang>>:-pedantic-errors>
$<$<AND:$<STREQUAL:$<COMPILE_LANGUAGE>,CXX>,$<CXX_COMPILER_ID:GNU>>:-Werror>
$<$<AND:$<STREQUAL:$<COMPILE_LANGUAGE>,CXX>,$<CXX_COMPILER_ID:GNU>>:-Wall>
$<$<AND:$<STREQUAL:$<COMPILE_LANGUAGE>,CXX>,$<CXX_COMPILER_ID:GNU>>:-pedantic-errors>
)
endif()

# prometheus-cpp

Expand Down
6 changes: 6 additions & 0 deletions cmake/civetweb-3rdparty-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ target_compile_definitions(civetweb
NO_FILES
)

target_compile_options(civetweb
PRIVATE
$<$<CXX_COMPILER_ID:AppleClang>:-w>
$<$<CXX_COMPILER_ID:GNU>:-w>
)

target_include_directories(civetweb
PRIVATE
${CIVETWEB_INCLUDE_DIRS}
Expand Down
2 changes: 1 addition & 1 deletion core/include/prometheus/detail/utils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma onece
#pragma once

#include <cstddef>
#include <map>
Expand Down
4 changes: 2 additions & 2 deletions core/src/detail/hash.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma
#pragma once

#include <cstddef>
#include <functional>
Expand All @@ -11,7 +11,7 @@ namespace detail {
/// It's the boundary condition of this serial functions.
///
/// \param seed Not effect.
inline void hash_combine(std::size_t *seed) {}
inline void hash_combine(std::size_t *) {}

/// \brief Combine the given hash value with another obeject.
///
Expand Down
18 changes: 9 additions & 9 deletions core/tests/family_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ TEST(FamilyTest, labels) {
{{const_label.name, const_label.value}}};
family.Add({{dynamic_label.name, dynamic_label.value}});
auto collected = family.Collect();
ASSERT_GE(collected.size(), 1);
ASSERT_GE(collected.at(0).metric.size(), 1);
ASSERT_GE(collected.size(), 1U);
ASSERT_GE(collected.at(0).metric.size(), 1U);
EXPECT_THAT(collected.at(0).metric.at(0).label,
::testing::ElementsAre(const_label, dynamic_label));
}
Expand All @@ -31,8 +31,8 @@ TEST(FamilyTest, counter_value) {
auto& counter = family.Add({});
counter.Increment();
auto collected = family.Collect();
ASSERT_GE(collected.size(), 1);
ASSERT_GE(collected[0].metric.size(), 1);
ASSERT_GE(collected.size(), 1U);
ASSERT_GE(collected[0].metric.size(), 1U);
EXPECT_EQ(1, collected[0].metric.at(0).counter.value);
}

Expand All @@ -42,8 +42,8 @@ TEST(FamilyTest, remove) {
family.Add({{"name", "counter2"}});
family.Remove(&counter1);
auto collected = family.Collect();
ASSERT_GE(collected.size(), 1);
EXPECT_EQ(collected[0].metric.size(), 1);
ASSERT_GE(collected.size(), 1U);
EXPECT_EQ(collected[0].metric.size(), 1U);
}

TEST(FamilyTest, Histogram) {
Expand All @@ -52,9 +52,9 @@ TEST(FamilyTest, Histogram) {
Histogram::BucketBoundaries{0, 1, 2});
histogram1.Observe(0);
auto collected = family.Collect();
ASSERT_EQ(collected.size(), 1);
ASSERT_GE(collected[0].metric.size(), 1);
EXPECT_EQ(1, collected[0].metric.at(0).histogram.sample_count);
ASSERT_EQ(collected.size(), 1U);
ASSERT_GE(collected[0].metric.size(), 1U);
EXPECT_EQ(1U, collected[0].metric.at(0).histogram.sample_count);
}

TEST(FamilyTest, add_twice) {
Expand Down
18 changes: 9 additions & 9 deletions core/tests/histogram_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TEST(HistogramTest, initialize_with_zero) {
Histogram histogram{{}};
auto metric = histogram.Collect();
auto h = metric.histogram;
EXPECT_EQ(h.sample_count, 0);
EXPECT_EQ(h.sample_count, 0U);
EXPECT_EQ(h.sample_sum, 0);
}

Expand All @@ -21,7 +21,7 @@ TEST(HistogramTest, sample_count) {
histogram.Observe(200);
auto metric = histogram.Collect();
auto h = metric.histogram;
EXPECT_EQ(h.sample_count, 2);
EXPECT_EQ(h.sample_count, 2U);
}

TEST(HistogramTest, sample_sum) {
Expand All @@ -38,7 +38,7 @@ TEST(HistogramTest, bucket_size) {
Histogram histogram{{1, 2}};
auto metric = histogram.Collect();
auto h = metric.histogram;
EXPECT_EQ(h.bucket.size(), 3);
EXPECT_EQ(h.bucket.size(), 3U);
}

TEST(HistogramTest, bucket_bounds) {
Expand All @@ -58,8 +58,8 @@ TEST(HistogramTest, bucket_counts_not_reset_by_collection) {
histogram.Observe(1.5);
auto metric = histogram.Collect();
auto h = metric.histogram;
ASSERT_EQ(h.bucket.size(), 3);
EXPECT_EQ(h.bucket.at(1).cumulative_count, 2);
ASSERT_EQ(h.bucket.size(), 3U);
EXPECT_EQ(h.bucket.at(1).cumulative_count, 2U);
}

TEST(HistogramTest, cumulative_bucket_count) {
Expand All @@ -73,10 +73,10 @@ TEST(HistogramTest, cumulative_bucket_count) {
histogram.Observe(3);
auto metric = histogram.Collect();
auto h = metric.histogram;
ASSERT_EQ(h.bucket.size(), 3);
EXPECT_EQ(h.bucket.at(0).cumulative_count, 3);
EXPECT_EQ(h.bucket.at(1).cumulative_count, 6);
EXPECT_EQ(h.bucket.at(2).cumulative_count, 7);
ASSERT_EQ(h.bucket.size(), 3U);
EXPECT_EQ(h.bucket.at(0).cumulative_count, 3U);
EXPECT_EQ(h.bucket.at(1).cumulative_count, 6U);
EXPECT_EQ(h.bucket.at(2).cumulative_count, 7U);
}

} // namespace
Expand Down
10 changes: 5 additions & 5 deletions core/tests/registry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ TEST(RegistryTest, collect_single_metric_family) {
counter_family.Add({{"name", "counter1"}});
counter_family.Add({{"name", "counter2"}});
auto collected = registry.Collect();
ASSERT_EQ(collected.size(), 1);
ASSERT_EQ(collected.size(), 1U);
EXPECT_EQ(collected[0].name, "test");
EXPECT_EQ(collected[0].help, "a test");
ASSERT_EQ(collected[0].metric.size(), 2);
ASSERT_EQ(collected[0].metric.at(0).label.size(), 1);
ASSERT_EQ(collected[0].metric.size(), 2U);
ASSERT_EQ(collected[0].metric.at(0).label.size(), 1U);
EXPECT_EQ(collected[0].metric.at(0).label.at(0).name, "name");
ASSERT_EQ(collected[0].metric.at(1).label.size(), 1);
ASSERT_EQ(collected[0].metric.at(1).label.size(), 1U);
EXPECT_EQ(collected[0].metric.at(1).label.at(0).name, "name");
}

Expand All @@ -34,7 +34,7 @@ TEST(RegistryTest, build_histogram_family) {
Histogram::BucketBoundaries{0, 1, 2});
histogram.Observe(1.1);
auto collected = registry.Collect();
ASSERT_EQ(collected.size(), 1);
ASSERT_EQ(collected.size(), 1U);
}

} // namespace
Expand Down
12 changes: 6 additions & 6 deletions core/tests/summary_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TEST(SummaryTest, initialize_with_zero) {
Summary summary{Summary::Quantiles{}};
auto metric = summary.Collect();
auto s = metric.summary;
EXPECT_EQ(s.sample_count, 0);
EXPECT_EQ(s.sample_count, 0U);
EXPECT_EQ(s.sample_sum, 0);
}

Expand All @@ -22,7 +22,7 @@ TEST(SummaryTest, sample_count) {
summary.Observe(200);
auto metric = summary.Collect();
auto s = metric.summary;
EXPECT_EQ(s.sample_count, 2);
EXPECT_EQ(s.sample_count, 2U);
}

TEST(SummaryTest, sample_sum) {
Expand All @@ -39,14 +39,14 @@ TEST(SummaryTest, quantile_size) {
Summary summary{Summary::Quantiles{{0.5, 0.05}, {0.90, 0.01}}};
auto metric = summary.Collect();
auto s = metric.summary;
EXPECT_EQ(s.quantile.size(), 2);
EXPECT_EQ(s.quantile.size(), 2U);
}

TEST(SummaryTest, quantile_bounds) {
Summary summary{Summary::Quantiles{{0.5, 0.05}, {0.90, 0.01}, {0.99, 0.001}}};
auto metric = summary.Collect();
auto s = metric.summary;
ASSERT_EQ(s.quantile.size(), 3);
ASSERT_EQ(s.quantile.size(), 3U);
EXPECT_DOUBLE_EQ(s.quantile.at(0).quantile, 0.5);
EXPECT_DOUBLE_EQ(s.quantile.at(1).quantile, 0.9);
EXPECT_DOUBLE_EQ(s.quantile.at(2).quantile, 0.99);
Expand All @@ -60,7 +60,7 @@ TEST(SummaryTest, quantile_values) {

auto metric = summary.Collect();
auto s = metric.summary;
ASSERT_EQ(s.quantile.size(), 3);
ASSERT_EQ(s.quantile.size(), 3U);

EXPECT_NEAR(s.quantile.at(0).value, 0.5 * SAMPLES, 0.05 * SAMPLES);
EXPECT_NEAR(s.quantile.at(1).value, 0.9 * SAMPLES, 0.01 * SAMPLES);
Expand All @@ -75,7 +75,7 @@ TEST(SummaryTest, max_age) {
static const auto test_value = [&summary](double ref) {
auto metric = summary.Collect();
auto s = metric.summary;
ASSERT_EQ(s.quantile.size(), 1);
ASSERT_EQ(s.quantile.size(), 1U);

if (std::isnan(ref))
EXPECT_TRUE(std::isnan(s.quantile.at(0).value));
Expand Down
3 changes: 1 addition & 2 deletions pull/src/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ static std::size_t WriteResponse(struct mg_connection* conn,
return body.size();
}

bool MetricsHandler::handleGet(CivetServer* server,
struct mg_connection* conn) {
bool MetricsHandler::handleGet(CivetServer*, struct mg_connection* conn) {
auto start_time_of_request = std::chrono::steady_clock::now();

auto metrics = CollectMetrics();
Expand Down
2 changes: 1 addition & 1 deletion pull/tests/integration/sample_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <prometheus/exposer.h>
#include <prometheus/registry.h>

int main(int argc, char** argv) {
int main() {
using namespace prometheus;

// create an http server running on port 8080
Expand Down
2 changes: 1 addition & 1 deletion push/tests/integration/sample_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static std::string GetHostName() {
return hostname;
}

int main(int argc, char** argv) {
int main() {
using namespace prometheus;

// create a push gateway
Expand Down

0 comments on commit 09f56af

Please sign in to comment.