Added GitHub Action to test for clang-format.

pull/13171/head
Joshua Haberman 3 years ago
parent 5c89d4d8d0
commit be7dfeba6b
  1. 30
      .github/workflows/bazel_tests.yml
  2. 34
      tests/test_cpp.cc
  3. 10
      tests/test_generated_code.cc
  4. 2
      tests/test_table.cc
  5. 2
      upb/json_encode.c
  6. 1
      upb/upb.c
  7. 4
      upb/upb_internal.h

@ -1,4 +1,4 @@
name: Bazel Tests
name: Check ClangFormat
on:
push:
@ -10,27 +10,11 @@ on:
workflow_dispatch:
jobs:
ubuntu:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # Don't cancel all jobs if one fails.
matrix:
include:
- { CC: clang, os: ubuntu-20.04, flags: "" }
- { CC: clang, os: ubuntu-20.04, flags: "-c opt" } # Some warnings only fire with -c opt
- { CC: gcc, os: ubuntu-20.04, flags: "-c opt" }
- { CC: clang, os: ubuntu-20.04, flags: "--//:fasttable_enabled=true -- -cmake:test_generated_files" }
- { CC: clang, os: ubuntu-20.04, flags: "--config=asan -- -benchmarks:benchmark -python/..." }
- { CC: clang, os: macos-11, flags: "" }
check_clang_format:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Setup Python venv
run: rm -rf /tmp/venv && python3 -m venv /tmp/venv
- name: Install dependencies
run: sudo apt install -y ${{ matrix.install }}
if: matrix.install != ''
- name: Run tests
run: cd ${{ github.workspace }} && PATH=/tmp/venv/bin:$PATH CC=${{ matrix.CC }} bazel test --test_output=errors ... ${{ matrix.flags }}
- name: Run ClangFormat
run: find . | grep -E '\.(c|h|cc)$' | grep -E -v '^./(third_party|cmake)' | xargs clang-format -i
- name: Check for differences
run: git diff --exit-code

@ -35,11 +35,11 @@
#include <set>
#include <sstream>
#include "google/protobuf/timestamp.upb.h"
#include "google/protobuf/timestamp.upbdefs.h"
#include "gtest/gtest.h"
#include "tests/test_cpp.upb.h"
#include "tests/test_cpp.upbdefs.h"
#include "google/protobuf/timestamp.upb.h"
#include "google/protobuf/timestamp.upbdefs.h"
#include "upb/def.h"
#include "upb/def.hpp"
#include "upb/json_decode.h"
@ -155,26 +155,30 @@ TEST(Cpp, TimestampEncoder) {
upb::SymbolTable symtab;
upb::Arena arena;
upb::MessageDefPtr md(google_protobuf_Timestamp_getmsgdef(symtab.ptr()));
google_protobuf_Timestamp* timestamp_upb = google_protobuf_Timestamp_new(arena.ptr());
google_protobuf_Timestamp* timestamp_upb_decoded = google_protobuf_Timestamp_new(arena.ptr());
google_protobuf_Timestamp* timestamp_upb =
google_protobuf_Timestamp_new(arena.ptr());
google_protobuf_Timestamp* timestamp_upb_decoded =
google_protobuf_Timestamp_new(arena.ptr());
long timestamps[] = {
253402300799, // 9999-12-31T23:59:59Z
1641006000, // 2022-01-01T03:00:00Z
0, // 1970-01-01T00:00:00Z
-31525200, // 1969-01-01T03:00:00Z
-2208988800, // 1900-01-01T00:00:00Z
-62135596800, // 0000-01-01T00:00:00Z
253402300799, // 9999-12-31T23:59:59Z
1641006000, // 2022-01-01T03:00:00Z
0, // 1970-01-01T00:00:00Z
-31525200, // 1969-01-01T03:00:00Z
-2208988800, // 1900-01-01T00:00:00Z
-62135596800, // 0000-01-01T00:00:00Z
};
for(long timestamp: timestamps) {
for (long timestamp : timestamps) {
google_protobuf_Timestamp_set_seconds(timestamp_upb, timestamp);
char json[128];
size_t size = upb_JsonEncode(timestamp_upb, md.ptr(), NULL, 0, json, sizeof(json), NULL);
bool result = upb_JsonDecode(json, size, timestamp_upb_decoded, md.ptr(), NULL, 0, arena.ptr(), NULL);
const long timestamp_decoded = google_protobuf_Timestamp_seconds(timestamp_upb_decoded);
size_t size = upb_JsonEncode(timestamp_upb, md.ptr(), NULL, 0, json,
sizeof(json), NULL);
bool result = upb_JsonDecode(json, size, timestamp_upb_decoded, md.ptr(),
NULL, 0, arena.ptr(), NULL);
const long timestamp_decoded =
google_protobuf_Timestamp_seconds(timestamp_upb_decoded);
ASSERT_TRUE(result);
EXPECT_EQ(timestamp, timestamp_decoded);

@ -296,12 +296,14 @@ static void check_int32_map_one_entry(
EXPECT_EQ(
1, protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_size(
msg));
EXPECT_TRUE(protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_get(
msg, test_int32, &val));
EXPECT_TRUE(
protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_get(
msg, test_int32, &val));
EXPECT_EQ(val, test_int32_2);
EXPECT_FALSE(protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_get(
msg, test_int32_3, &val));
EXPECT_FALSE(
protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_get(
msg, test_int32_3, &val));
/* Test that iteration reveals a single k/v pair in the map. */
iter = kUpb_Map_Begin;

@ -460,7 +460,7 @@ TEST_P(IntTableTest, TestIntTable) {
uint32_t largest_key = 0;
std::map<uint32_t, uint32_t> m;
std::unordered_map<uint32_t, uint32_t> hm;
for (const auto& key: keys_) {
for (const auto& key : keys_) {
largest_key = UPB_MAX((int32_t)largest_key, key);
table.Insert(key, key * 2);
m[key] = key * 2;

@ -162,7 +162,7 @@ static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg,
* Fliegel, H. F., and Van Flandern, T. C., "A Machine Algorithm for
* Processing Calendar Dates," Communications of the Association of
* Computing Machines, vol. 11 (1968), p. 657. */
seconds += 62135596800; // Ensure seconds is positive.
seconds += 62135596800; // Ensure seconds is positive.
L = (int)(seconds / 86400) - 719162 + 68569 + 2440588;
N = 4 * L / 146097;
L = L - (146097 * N + 3) / 4;

@ -341,7 +341,6 @@ static void upb_FixLocale(char* p) {
}
}
void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) {
assert(size >= kUpb_RoundTripBufferSize);
snprintf(buf, size, "%.*g", DBL_DIG, val);

@ -61,9 +61,7 @@ struct upb_Arena {
// the beginning.
//
// The given buffer size must be at least kUpb_RoundTripBufferSize.
enum {
kUpb_RoundTripBufferSize = 32
};
enum { kUpb_RoundTripBufferSize = 32 };
void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size);
void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size);

Loading…
Cancel
Save