• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2015 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# Don't run this script standalone. Instead, run from the repository root:
17# ./tools/run_tests/run_tests.py -l objc
18
19set -ev
20
21cd $(dirname $0)
22
23# Run the tests server.
24
25ROOT_DIR=../../..
26BAZEL=$ROOT_DIR/tools/bazel
27PROTOC=$ROOT_DIR/bazel-bin/external/com_google_protobuf/protoc
28PLUGIN=$ROOT_DIR/bazel-bin/src/compiler/grpc_objective_c_plugin
29
30[ -f $PROTOC ] && [ -f $PLUGIN ] || {
31    BAZEL build @com_google_protobuf//:protoc //src/compiler:grpc_objective_c_plugin
32}
33
34rm -rf PluginTest/*pb*
35
36$PROTOC \
37    --plugin=protoc-gen-grpc=$PLUGIN \
38    --objc_out=PluginTest \
39    --grpc_out=PluginTest \
40    -I PluginTest \
41    -I ../../../third_party/protobuf/src \
42    PluginTest/*.proto
43
44# Verify the output proto filename
45[ -e ./PluginTest/TestDashFilename.pbrpc.h ] || {
46    echo >&2 "protoc outputs wrong filename."
47    exit 1
48}
49
50# TODO(jtattermusch): rewrite the tests to make them more readable.
51# Also, the way they are written, they need one extra command to run in order to
52# clear $? after they run (see end of this script)
53# Verify names of the imported protos in generated code don't contain dashes.
54[ "`cat PluginTest/TestDashFilename.pbrpc.h |
55    egrep '#import ".*\.pb(objc|rpc)\.h"$' |
56    egrep '-'`" ] && {
57    echo >&2 "protoc generated import with wrong filename."
58    exit 1
59}
60[ "`cat PluginTest/TestDashFilename.pbrpc.m |
61    egrep '#import ".*\.pb(objc|rpc)\.h"$' |
62    egrep '-'`" ] && {
63    echo >&2 "protoc generated import with wrong filename."
64    exit 1
65}
66
67# Run one extra command to clear $? before exiting the script to prevent
68# failing even when tests pass.
69echo "Plugin tests passed."
70