Add a test for includes without paths (#28532)

* Add a test for includes without paths

* fix path

* fix

* Automated change: Fix sanity tests

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/28541/head
Craig Tiller 3 years ago committed by GitHub
parent 98999225be
commit e29bdfe4e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/core/ext/transport/chttp2/transport/hpack_encoder.cc
  2. 2
      src/core/ext/transport/chttp2/transport/hpack_parser_table.cc
  3. 2
      test/core/util/fake_udp_and_tcp_server.cc
  4. 2
      test/cpp/qps/qps_server_builder.cc
  5. 72
      tools/distrib/check_naked_includes.py
  6. 1
      tools/distrib/sanitize.sh
  7. 1
      tools/run_tests/sanity/sanity_tests.yaml

@ -25,8 +25,8 @@
#include <cstdint>
#include "hpack_constants.h"
#include "hpack_encoder_table.h"
#include "src/core/ext/transport/chttp2/transport/hpack_constants.h"
#include "src/core/ext/transport/chttp2/transport/hpack_encoder_table.h"
/* This is here for grpc_is_binary_header
* TODO(murgatroid99): Remove this

@ -24,11 +24,11 @@
#include <string.h>
#include "absl/strings/str_format.h"
#include "hpack_constants.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/ext/transport/chttp2/transport/hpack_constants.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/murmur_hash.h"
#include "src/core/lib/slice/slice_internal.h"

@ -16,7 +16,7 @@
#include <grpc/support/port_platform.h>
#include "fake_udp_and_tcp_server.h"
#include "test/core/util/fake_udp_and_tcp_server.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"

@ -16,7 +16,7 @@
*
*/
#include "qps_server_builder.h"
#include "test/cpp/qps/qps_server_builder.h"
#include "absl/memory/memory.h"

@ -0,0 +1,72 @@
#!/usr/bin/env python3
# Copyright 2022 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Check for includes of the form `#include "bar.h"` - i.e. not including the subdirectory. We require instead `#include "foo/bar.h"`.
import argparse
import os
import re
import sys
# find our home
ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..'))
os.chdir(ROOT)
# parse command line
argp = argparse.ArgumentParser(description='include guard checker')
argp.add_argument('-f', '--fix', default=False, action='store_true')
args = argp.parse_args()
# error count
errors = 0
CHECK_SUBDIRS = [
'src/core',
'src/cpp',
'test/core',
'test/cpp',
]
for subdir in CHECK_SUBDIRS:
for root, dirs, files in os.walk(subdir):
for f in files:
if f.endswith('.h') or f.endswith('.cc'):
fpath = os.path.join(root, f)
output = open(fpath, 'r').readlines()
changed = False
for (i, line) in enumerate(output):
m = re.match(r'^#include "([^"]*)"(.*)', line)
if not m:
continue
include = m.group(1)
if '/' in include:
continue
expect_path = os.path.join(root, include)
trailing = m.group(2)
if not os.path.exists(expect_path):
continue
changed = True
errors += 1
output[i] = '#include "{0}"{1}\n'.format(
expect_path, trailing)
print("Found naked include '{0}' in {1}".format(
include, fpath))
if changed and args.fix:
open(fpath, 'w').writelines(output)
if errors > 0:
print('{} errors found.'.format(errors))
sys.exit(1)

@ -19,6 +19,7 @@ cd $(dirname $0)/../..
tools/buildgen/generate_projects.sh
tools/distrib/check_include_guards.py --fix
tools/distrib/check_naked_includes.py --fix || true
tools/distrib/check_copyright.py --fix
tools/distrib/add-iwyu.py
tools/distrib/check_trailing_newlines.sh --fix

@ -23,6 +23,7 @@
cpu_cost: 3
- script: tools/distrib/check_copyright.py
- script: tools/distrib/check_include_guards.py
- script: tools/distrib/check_naked_includes.py
- script: tools/distrib/check_trailing_newlines.sh
- script: tools/distrib/check_upb_output.sh
- script: tools/distrib/check_pytype.sh

Loading…
Cancel
Save