1#!/bin/bash 2# Copyright 2022 The gRPC 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# Run this script via bazel test 17# It expects that protoc and grpc_objective_c_plugin have already been built. 18 19set -ev 20 21# protoc and grpc_objective_c_plugin binaries are supplied as "data" in bazel 22PROTOC=./external/com_google_protobuf/protoc 23PLUGIN=./src/compiler/grpc_objective_c_plugin 24 25PROTO_OUT=./proto_out 26rm -rf ${PROTO_OUT} 27mkdir -p ${PROTO_OUT} 28 29$PROTOC \ 30 --plugin=protoc-gen-grpc=$PLUGIN \ 31 --objc_out=${PROTO_OUT} \ 32 --grpc_out=${PROTO_OUT} \ 33 -I src/objective-c/tests/PluginTest \ 34 src/objective-c/tests/PluginTest/*.proto 35 36# Verify the output proto filename 37[ -e ${PROTO_OUT}/TestDashFilename.pbrpc.h ] || { 38 echo >&2 "protoc outputs wrong filename." 39 exit 1 40} 41 42# TODO(jtattermusch): rewrite the tests to make them more readable. 43# Also, the way they are written, they need one extra command to run in order to 44# clear $? after they run (see end of this script) 45# Verify names of the imported protos in generated code don't contain dashes. 46[ "`cat ${PROTO_OUT}/TestDashFilename.pbrpc.h | 47 egrep '#import ".*\.pb(objc|rpc)\.h"$' | 48 egrep '-'`" ] && { 49 echo >&2 "protoc generated import with wrong filename." 50 exit 1 51} 52[ "`cat ${PROTO_OUT}/TestDashFilename.pbrpc.m | 53 egrep '#import ".*\.pb(objc|rpc)\.h"$' | 54 egrep '-'`" ] && { 55 echo >&2 "protoc generated import with wrong filename." 56 exit 1 57} 58 59# Run one extra command to clear $? before exiting the script to prevent 60# failing even when tests pass. 61echo "Plugin tests passed." 62