Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 25bd9f5

Browse files
authored
Add a Travis check for code formatting. (#7)
- The helper script can also be used to autoformat the code. - Format the code. - Make bazel under Travis less chatty.
1 parent 01a800d commit 25bd9f5

File tree

12 files changed

+44
-13
lines changed

12 files changed

+44
-13
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ before_install:
99
- ./bazel-0.8.1-installer-linux-x86_64.sh --user
1010

1111
script:
12-
- bazel build -k //...
13-
- bazel test -k //...
12+
- bazel build --noshow_progress -k //...
13+
- bazel test --noshow_progress -k //...
14+
- ./format.sh

format.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2017, OpenCensus Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# Formats code under opencensus/, exits with 0 if there were no changes.
17+
set -e
18+
# For easier debugging: print the version because it affects the formatting.
19+
CMD=clang-format
20+
$CMD -version
21+
$CMD -i -style=Google $(find opencensus -name '*.cc' -or -name '*.h')
22+
CHANGED="$(git ls-files --modified)"
23+
if [[ ! -z "$CHANGED" ]]; then
24+
echo "The following files have changes:"
25+
echo "$CHANGED"
26+
exit 1
27+
else
28+
echo "No changes."
29+
fi

opencensus/common/internal/stats_object_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
#include <random>
2424
#include <utility>
2525

26-
#include "gmock/gmock.h"
27-
#include "gtest/gtest.h"
2826
#include "absl/strings/str_join.h"
2927
#include "absl/types/span.h"
28+
#include "gmock/gmock.h"
29+
#include "gtest/gtest.h"
3030

3131
namespace opencensus {
3232
namespace common {

opencensus/trace/examples/span_example.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#include <memory>
1717
#include <thread>
1818

19-
#include "gtest/gtest.h"
2019
#include "absl/memory/memory.h"
2120
#include "absl/strings/str_cat.h"
21+
#include "gtest/gtest.h"
2222
#include "opencensus/trace/exporter/status.h"
2323
#include "opencensus/trace/sampler.h"
2424
#include "opencensus/trace/span.h"

opencensus/trace/internal/attribute_value_ref_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
#include "opencensus/trace/attribute_value_ref.h"
1616

17-
#include "gtest/gtest.h"
1817
#include "absl/strings/str_cat.h"
18+
#include "gtest/gtest.h"
1919

2020
namespace opencensus {
2121
namespace trace {

opencensus/trace/internal/attribute_value_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
#include "opencensus/trace/exporter/attribute_value.h"
1616

17-
#include "gtest/gtest.h"
1817
#include "absl/strings/str_cat.h"
18+
#include "gtest/gtest.h"
1919
#include "opencensus/trace/attribute_value_ref.h"
2020

2121
namespace opencensus {

opencensus/trace/internal/running_span_store_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include <unordered_map>
2020
#include <vector>
2121

22-
#include "gtest/gtest.h"
2322
#include "absl/memory/memory.h"
23+
#include "gtest/gtest.h"
2424
#include "opencensus/trace/exporter/attribute_value.h"
2525
#include "opencensus/trace/exporter/span_data.h"
2626
#include "opencensus/trace/exporter/status.h"

opencensus/trace/internal/span_exporter_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
#include "opencensus/trace/exporter/span_exporter.h"
1616

17-
#include "gtest/gtest.h"
1817
#include "absl/memory/memory.h"
1918
#include "absl/synchronization/mutex.h"
19+
#include "gtest/gtest.h"
2020
#include "opencensus/trace/exporter/span_data.h"
2121
#include "opencensus/trace/sampler.h"
2222
#include "opencensus/trace/span.h"

opencensus/trace/internal/span_options_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
#include <memory>
1616

17-
#include "gtest/gtest.h"
1817
#include "absl/strings/string_view.h"
1918
#include "absl/synchronization/mutex.h"
19+
#include "gtest/gtest.h"
2020
#include "opencensus/trace/exporter/message_event.h"
2121
#include "opencensus/trace/exporter/status.h"
2222
#include "opencensus/trace/internal/span_impl.h"

opencensus/trace/internal/trace_config.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "opencensus/trace/internal/trace_config_impl.h"
1615
#include "opencensus/trace/trace_config.h"
16+
17+
#include "opencensus/trace/internal/trace_config_impl.h"
1718
#include "opencensus/trace/trace_params.h"
1819

1920
namespace opencensus {

0 commit comments

Comments
 (0)